Re-arrange the arguments of triggerCallback. Modifying Dispatcher so its not calling methods on Component directly. Additional methods added to Controller.

This commit is contained in:
Mark Story 2010-02-27 22:01:08 -05:00
parent e75f6fe2b4
commit cec6692123
3 changed files with 32 additions and 10 deletions

View file

@ -182,9 +182,7 @@ class Dispatcher extends Object {
*/
function _invoke(&$controller, $params) {
$controller->constructClasses();
$controller->Component->initialize($controller);
$controller->beforeFilter();
$controller->Component->startup($controller);
$controller->startupProcess();
$methods = array_flip($controller->methods);
@ -208,8 +206,7 @@ class Dispatcher extends Object {
} elseif (empty($controller->output)) {
$controller->output = $output;
}
$controller->Component->shutdown($controller);
$controller->afterFilter();
$controller->shutdownProcess();
if (isset($params['return'])) {
return $controller->output;

View file

@ -109,7 +109,7 @@ class Component extends Object {
* @link http://book.cakephp.org/view/65/MVC-Class-Access-Within-Components
*/
function startup(&$controller) {
$this->triggerCallback($controller, 'startup');
$this->triggerCallback('startup', $controller);
}
/**
@ -121,7 +121,7 @@ class Component extends Object {
* @access public
*/
function beforeRender(&$controller) {
$this->triggerCallback($controller, 'beforeRender');
$this->triggerCallback('beforeRender', $controller);
}
/**
@ -156,7 +156,7 @@ class Component extends Object {
* @access public
*/
function shutdown(&$controller) {
$this->triggerCallback($controller, 'shutdown');
$this->triggerCallback('shutdown', $controller);
}
/**
@ -169,7 +169,7 @@ class Component extends Object {
* @return void
* @access public
*/
function triggerCallback(&$controller, $callback) {
function triggerCallback($callback, &$controller) {
foreach ($this->_primary as $name) {
$component =& $this->_loaded[$name];
if (method_exists($component, $callback) && $component->enabled === true) {

View file

@ -514,6 +514,31 @@ class Controller extends Object {
return true;
}
/**
* Perform the startup process for this controller.
* Fire the Component and Controller callbacks in the correct order.
*
* @return void
* @access public
*/
function startupProcess() {
$this->Component->initialize($this);
$this->beforeFilter();
$this->Component->triggerCallback('startup', $this);
}
/**
* Perform the various shutdown processes for this controller.
* Fire the Component and Controller callbacks in the correct order.
*
* @return void
* @access public
*/
function shutdownProcess() {
$this->Component->triggerCallback('shutdown', $controller);
$this->afterFilter();
}
/**
* Queries & sets valid HTTP response codes & messages.
*
@ -835,7 +860,7 @@ class Controller extends Object {
App::import('View', $this->view);
}
$this->Component->beforeRender($this);
$this->Component->triggerCallback('beforeRender', $this);
$this->params['models'] = $this->modelNames;