Use scope isolated includes for plugins & config

pico-3.0-alpha
Daniel Rudolf 9 years ago
parent 5bb1c325ff
commit 75d5081bfb
  1. 20
      lib/Pico.php
  2. 10
      plugins/00-PicoDeprecated.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(

@ -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'])) {

Loading…
Cancel
Save