Skip to content

Commit

Permalink
moving the configuration closer to the start fixes #163
Browse files Browse the repository at this point in the history
  • Loading branch information
dogmatic69 committed Sep 7, 2010
1 parent ca96710 commit dce83f9
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 55 deletions.
58 changes: 58 additions & 0 deletions app_controller.php
Expand Up @@ -273,6 +273,7 @@ public function beforeFilter(){
* application.
*/
public function __construct(){
$this->__setupConfig();
$event = EventCore::trigger(new StdClass(), 'requireComponentsToLoad');

if(isset($event['requireComponentsToLoad']['libs'])){
Expand All @@ -288,10 +289,67 @@ public function __construct(){
$this->components = array_merge($this->components, $components);
}
}

unset($event);

parent::__construct();
}

/**
* Set up system configuration.
*
* Load the default configuration and check if there are any configs
* to load from the current plugin. configurations can be completely rewriten
* or just added to.
*/
private function __setupConfig(){
$this->configs = ClassRegistry::init('Management.Config')->getConfig();

$eventData = EventCore::trigger(new StdClass(), $this->plugin.'.setupConfigStart', $this->configs);
if (isset($eventData['setupConfigStart'][$this->plugin])){
$this->configs = (array)$eventData['setupConfigStart'][$this->plugin];

if (!array($this->configs)) {
$this->cakeError('eventError', array('message' => 'Your config is wrong.', 'event' => $eventData));
}
}

$eventData = EventCore::trigger(new StdClass(), $this->plugin.'.setupConfigEnd');
if (isset($eventData['setupConfigEnd'][$this->plugin])){
$this->configs = $this->configs + (array)$eventData['setupConfigEnd'][$this->plugin];
}

if (!$this->__writeConfigs()) {
$this->cakeError('configError', array('message' => 'Config was not written'));
}

unset($this->configs, $eventData);
}

/**
* Write the configuration.
*
* Write all the config values that have been called found in InfinitasComponent::setupConfig()
*/
private function __writeConfigs(){
if (empty($this->configs)) {
return false;
}

foreach($this->configs as $config) {
if (!(isset($config['Config']['key']) || isset($config['Config']['value']))) {
$config['Config']['key'] = isset($config['Config']['key']) ? $config['Config']['key'] : 'NOT SET';
$config['Config']['value'] = isset($config['Config']['key']) ? $config['Config']['value'] : 'NOT SET';
$this->log(serialize($config['Config']), 'configuration_error');
continue;
}

Configure::write($config['Config']['key'], $config['Config']['value']);
}

return true;
}

/**
* Common methods for the app
*/
Expand Down
2 changes: 1 addition & 1 deletion app_model.php
Expand Up @@ -53,7 +53,7 @@ class AppModel extends LazyModel {

function __construct($id = false, $table = null, $ds = null) {
$this->__getPlugin();
parent::__construct($id, $table, $ds);
parent::__construct($id, $table, $ds);

if (isset($this->_schema) && is_array($this->_schema)) {
if($this->Behaviors->enabled('Event')) {
Expand Down
54 changes: 0 additions & 54 deletions extensions/libs/controllers/components/infinitas.php
Expand Up @@ -35,7 +35,6 @@ public function initialize(&$controller, $settings = array()) {
$this->Controller = &$controller;
$settings = array_merge(array(), (array)$settings);

$this->setupConfig();
$this->__registerPlugins();

$this->__checkBadLogins();
Expand Down Expand Up @@ -64,59 +63,6 @@ private function __registerPlugins(){
}
}

/**
* Set up system configuration.
*
* Load the default configuration and check if there are any configs
* to load from the current plugin. configurations can be completely rewriten
* or just added to.
*/
public function setupConfig(){
$this->configs = Cache::read('core_configs', 'core');

if ($this->configs === false) {
$this->configs = ClassRegistry::init('Management.Config')->getConfig();
}

$eventData = $this->Controller->Event->trigger($this->Controller->plugin.'.setupConfigStart', $this->configs);
if (isset($eventData['setupConfigStart'][$this->Controller->plugin])){
$this->configs = (array)$eventData['setupConfigStart'][$this->Controller->plugin];

if (!array($this->configs)) {
$this->cakeError('eventError', array('message' => 'Your config is wrong.', 'event' => $eventData));
}
}

$eventData = $this->Controller->Event->trigger($this->Controller->plugin.'.setupConfigEnd');
if (isset($eventData['setupConfigEnd'][$this->Controller->plugin])){
$this->configs = $this->configs + (array)$eventData['setupConfigEnd'][$this->Controller->plugin];
}

if (!$this->_writeConfigs()) {
$this->cakeError('configError', array('message' => 'Config was not written'));
}
}

/**
* Write the configuration.
*
* Write all the config values that have been called found in InfinitasComponent::setupConfig()
*/
function _writeConfigs(){
if (empty($this->configs)) {
return false;
}

foreach($this->configs as $config) {
if (!(isset($config['Config']['key']) || isset($config['Config']['value']))) {
continue;
}
Configure::write($config['Config']['key'], $config['Config']['value']);
}

return true;
}

/**
* Setup the theme for the site
*
Expand Down

0 comments on commit dce83f9

Please sign in to comment.