Use scope isolated includes for plugins & config
This commit is contained in:
parent
5bb1c325ff
commit
75d5081bfb
20
lib/Pico.php
20
lib/Pico.php
@ -398,10 +398,18 @@ class Pico
|
|||||||
*/
|
*/
|
||||||
protected function loadPlugins()
|
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();
|
$this->plugins = array();
|
||||||
$pluginFiles = $this->getFiles($this->getPluginsDir(), '.php');
|
$pluginFiles = $this->getFiles($this->getPluginsDir(), '.php');
|
||||||
foreach ($pluginFiles as $pluginFile) {
|
foreach ($pluginFiles as $pluginFile) {
|
||||||
require_once($pluginFile);
|
$includeClosure($pluginFile);
|
||||||
|
|
||||||
$className = preg_replace('/^[0-9]+-/', '', basename($pluginFile, '.php'));
|
$className = preg_replace('/^[0-9]+-/', '', basename($pluginFile, '.php'));
|
||||||
if (class_exists($className)) {
|
if (class_exists($className)) {
|
||||||
@ -508,7 +516,15 @@ class Pico
|
|||||||
{
|
{
|
||||||
$config = null;
|
$config = null;
|
||||||
if (file_exists($this->getConfigDir() . 'config.php')) {
|
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(
|
$defaultConfig = array(
|
||||||
|
@ -165,10 +165,18 @@ class PicoDeprecated extends AbstractPicoPlugin
|
|||||||
protected function loadRootDirConfig(array &$realConfig)
|
protected function loadRootDirConfig(array &$realConfig)
|
||||||
{
|
{
|
||||||
if (file_exists($this->getRootDir() . 'config.php')) {
|
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
|
// config.php in Pico::$rootDir is deprecated
|
||||||
// use config.php in Pico::$configDir instead
|
// use config.php in Pico::$configDir instead
|
||||||
$config = null;
|
$config = null;
|
||||||
require($this->getRootDir() . 'config.php');
|
$includeClosure($this->getRootDir() . 'config.php');
|
||||||
|
|
||||||
if (is_array($config)) {
|
if (is_array($config)) {
|
||||||
if (isset($config['base_url'])) {
|
if (isset($config['base_url'])) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user