Explorar el Código

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:
Daniel Rudolf hace 9 años
padre
commit
9a702415fb
Se han modificado 3 ficheros con 11 adiciones y 11 borrados
  1. 0 5
      config/config.php.template
  2. 4 1
      lib/Pico.php
  3. 7 5
      plugins/00-PicoDeprecated.php

+ 0 - 5
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;

+ 4 - 1
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;

+ 7 - 5
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;
             }
         }
     }