Use scope isolated includes for plugins & config
This commit is contained in:
parent
5bb1c325ff
commit
75d5081bfb
2 changed files with 27 additions and 3 deletions
20
lib/Pico.php
20
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(
|
||||
|
|
|
@ -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…
Add table
Reference in a new issue