Преглед изворни кода

Use scope isolated includes for plugins & config

Daniel Rudolf пре 9 година
родитељ
комит
75d5081bfb
2 измењених фајлова са 27 додато и 3 уклоњено
  1. 18 2
      lib/Pico.php
  2. 9 1
      plugins/00-PicoDeprecated.php

+ 18 - 2
lib/Pico.php

@@ -398,10 +398,18 @@ class Pico
      */
     protected function loadPlugins()
     {
+        // scope isolated require_once()
+        $includeClosure = function ($pluginFile) {
+            require_once($pluginFile);
+        };
+        if (PHP_VERSION_ID >= 50400) {
+            $includeClosure = $includeClosure->bindTo(null);
+        }
+
         $this->plugins = array();
         $pluginFiles = $this->getFiles($this->getPluginsDir(), '.php');
         foreach ($pluginFiles as $pluginFile) {
-            require_once($pluginFile);
+            $includeClosure($pluginFile);
 
             $className = preg_replace('/^[0-9]+-/', '', basename($pluginFile, '.php'));
             if (class_exists($className)) {
@@ -508,7 +516,15 @@ class Pico
     {
         $config = null;
         if (file_exists($this->getConfigDir() . 'config.php')) {
-            require($this->getConfigDir() . 'config.php');
+            // scope isolated require()
+            $includeClosure = function ($configFile) {
+                require($configFile);
+            };
+            if (PHP_VERSION_ID >= 50400) {
+                $includeClosure = $includeClosure->bindTo(null);
+            }
+
+            $includeClosure($this->getConfigDir() . 'config.php');
         }
 
         $defaultConfig = array(

+ 9 - 1
plugins/00-PicoDeprecated.php

@@ -165,10 +165,18 @@ class PicoDeprecated extends AbstractPicoPlugin
     protected function loadRootDirConfig(array &$realConfig)
     {
         if (file_exists($this->getRootDir() . 'config.php')) {
+            // scope isolated require()
+            $includeClosure = function ($configFile) {
+                require($configFile);
+            };
+            if (PHP_VERSION_ID >= 50400) {
+                $includeClosure = $includeClosure->bindTo(null);
+            }
+
             // config.php in Pico::$rootDir is deprecated
             // use config.php in Pico::$configDir instead
             $config = null;
-            require($this->getRootDir() . 'config.php');
+            $includeClosure($this->getRootDir() . 'config.php');
 
             if (is_array($config)) {
                 if (isset($config['base_url'])) {