Skip to content

Commit

Permalink
Refactoring existing callbacks into triggerCallback().
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Feb 28, 2010
1 parent 748ec4e commit e75f6fe
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions cake/libs/controller/component.php
Expand Up @@ -109,12 +109,7 @@ function initialize(&$controller) {
* @link http://book.cakephp.org/view/65/MVC-Class-Access-Within-Components
*/
function startup(&$controller) {
foreach ($this->_primary as $name) {
$component =& $this->_loaded[$name];
if ($component->enabled === true && method_exists($component, 'startup')) {
$component->startup($controller);
}
}
$this->triggerCallback($controller, 'startup');
}

/**
Expand All @@ -126,12 +121,7 @@ function startup(&$controller) {
* @access public
*/
function beforeRender(&$controller) {
foreach ($this->_primary as $name) {
$component =& $this->_loaded[$name];
if ($component->enabled === true && method_exists($component,'beforeRender')) {
$component->beforeRender($controller);
}
}
$this->triggerCallback($controller, 'beforeRender');
}

/**
Expand Down Expand Up @@ -166,10 +156,24 @@ function beforeRedirect(&$controller, $url, $status = null, $exit = true) {
* @access public
*/
function shutdown(&$controller) {
$this->triggerCallback($controller, 'shutdown');
}

/**
* Trigger a callback on all primary components. Will fire $callback on all components
* that have such a method. You can implement and fire custom callbacks in addition to the
* standard ones.
*
* @param Controller $controller Controller instance
* @param string $callback Callback to trigger.
* @return void
* @access public
*/
function triggerCallback(&$controller, $callback) {
foreach ($this->_primary as $name) {
$component =& $this->_loaded[$name];
if (method_exists($component,'shutdown') && $component->enabled === true) {
$component->shutdown($controller);
if (method_exists($component, $callback) && $component->enabled === true) {
$component->{$callback}($controller);
}
}
}
Expand Down

0 comments on commit e75f6fe

Please sign in to comment.