Allow multiple calls to Pico::setConfig()

This commit is contained in:
Daniel Rudolf 2015-10-06 20:38:34 +02:00
parent 04a1c603d0
commit b09433a37b

View File

@ -78,6 +78,13 @@ class Pico
*/ */
protected $themesDir; protected $themesDir;
/**
* Boolean indicating whether Picos processing started yet
*
* @var boolean
*/
protected $locked = false;
/** /**
* List of loaded plugins * List of loaded plugins
* *
@ -246,8 +253,8 @@ class Pico
*/ */
public function run() public function run()
{ {
// lock config // lock Pico
$this->config = is_array($this->config) ? $this->config : array(); $this->locked = true;
// load plugins // load plugins
$this->loadPlugins(); $this->loadPlugins();
@ -421,6 +428,8 @@ class Pico
$configFile = $this->getConfigDir() . 'config.php'; $configFile = $this->getConfigDir() . 'config.php';
$config = file_exists($configFile) ? require($configFile) : null; $config = file_exists($configFile) ? require($configFile) : null;
$this->config = is_array($this->config) ? $this->config : array();
$this->config += is_array($config) ? $config + $defaultConfig : $defaultConfig; $this->config += is_array($config) ? $config + $defaultConfig : $defaultConfig;
if (empty($this->config['base_url'])) { if (empty($this->config['base_url'])) {
@ -456,7 +465,7 @@ class Pico
*/ */
public function setConfig(array $config) public function setConfig(array $config)
{ {
if ($this->config !== null) { if ($this->locked) {
throw new RuntimeException('You cannot modify Picos config after processing has started'); throw new RuntimeException('You cannot modify Picos config after processing has started');
} }