From 9a702415fb4e1b5a2092c95bb003d56bd88fa7ff Mon Sep 17 00:00:00 2001 From: Daniel Rudolf Date: Sat, 31 Oct 2015 00:32:08 +0100 Subject: [PATCH] Remove `return $config` in `config/config.php` I always thought that doing this is pretty unusual... But now it simply breaks BC - please refer to @Lomanic's [comment](https://github.com/picocms/Pico/pull/260#issuecomment-152610857). Using a return statement has no advantages, but increases the probability that something goes wrong (e.g. a clueless user removes the return statement). It was introduced with 23b90e2, but we never released it ([v0.9.1](https://github.com/picocms/Pico/blob/4cb2b24fae6bda83c7a3327cfb806370a90a60ac/lib/pico.php#L188-L189)). Removing the return statement shouldn't cause any problems even for users which installed Pico in the meantime. As a result we don't break BC and moreover remove a prior BC break :smiley: --- config/config.php.template | 5 ----- lib/Pico.php | 5 ++++- plugins/00-PicoDeprecated.php | 12 +++++++----- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/config/config.php.template b/config/config.php.template index 69cd7b1..568bd00 100644 --- a/config/config.php.template +++ b/config/config.php.template @@ -16,8 +16,6 @@ * @version 0.9 */ -$config = array(); - /* * BASIC */ @@ -58,6 +56,3 @@ $config = array(); * CUSTOM */ // $config['custom_setting'] = 'Hello'; // Can be accessed by {{ config.custom_setting }} in a theme - -// DO NOT REMOVE THIS LINE -return $config; diff --git a/lib/Pico.php b/lib/Pico.php index a75d6ad..13194c4 100644 --- a/lib/Pico.php +++ b/lib/Pico.php @@ -427,6 +427,7 @@ class Pico */ protected function loadConfig() { + $config = null; $defaultConfig = array( 'site_title' => 'Pico', 'base_url' => '', @@ -442,7 +443,9 @@ class Pico ); $configFile = $this->getConfigDir() . 'config.php'; - $config = file_exists($configFile) ? require($configFile) : null; + if (file_exists($configFile)) { + require $configFile; + } $this->config = is_array($this->config) ? $this->config : array(); $this->config += is_array($config) ? $config + $defaultConfig : $defaultConfig; diff --git a/plugins/00-PicoDeprecated.php b/plugins/00-PicoDeprecated.php index 2c818f8..d719d20 100644 --- a/plugins/00-PicoDeprecated.php +++ b/plugins/00-PicoDeprecated.php @@ -144,16 +144,18 @@ class PicoDeprecated extends AbstractPicoPlugin * * @see PicoDeprecated::onConfigLoaded() * @see Pico::loadConfig() - * @param mixed[] &$config array of config variables + * @param mixed[] &$realConfig array of config variables * @return void */ - protected function loadRootDirConfig(&$config) + protected function loadRootDirConfig(&$realConfig) { if (file_exists($this->getRootDir() . 'config.php')) { // config.php in Pico::$rootDir is deprecated; use Pico::$configDir instead - $newConfig = require($this->getRootDir() . 'config.php'); - if (is_array($newConfig)) { - $config = $newConfig + $config; + $config = null; + require($this->getRootDir() . 'config.php'); + + if (is_array($config)) { + $realConfig = $config + $realConfig; } } }