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) { function _invoke(&$controller, $params) {
$controller->constructClasses(); $controller->constructClasses();
$controller->Component->initialize($controller); $controller->startupProcess();
$controller->beforeFilter();
$controller->Component->startup($controller);
$methods = array_flip($controller->methods); $methods = array_flip($controller->methods);
@ -208,8 +206,7 @@ class Dispatcher extends Object {
} elseif (empty($controller->output)) { } elseif (empty($controller->output)) {
$controller->output = $output; $controller->output = $output;
} }
$controller->Component->shutdown($controller); $controller->shutdownProcess();
$controller->afterFilter();
if (isset($params['return'])) { if (isset($params['return'])) {
return $controller->output; 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 * @link http://book.cakephp.org/view/65/MVC-Class-Access-Within-Components
*/ */
function startup(&$controller) { function startup(&$controller) {
$this->triggerCallback($controller, 'startup'); $this->triggerCallback('startup', $controller);
} }
/** /**
@ -121,7 +121,7 @@ class Component extends Object {
* @access public * @access public
*/ */
function beforeRender(&$controller) { function beforeRender(&$controller) {
$this->triggerCallback($controller, 'beforeRender'); $this->triggerCallback('beforeRender', $controller);
} }
/** /**
@ -156,7 +156,7 @@ class Component extends Object {
* @access public * @access public
*/ */
function shutdown(&$controller) { function shutdown(&$controller) {
$this->triggerCallback($controller, 'shutdown'); $this->triggerCallback('shutdown', $controller);
} }
/** /**
@ -169,7 +169,7 @@ class Component extends Object {
* @return void * @return void
* @access public * @access public
*/ */
function triggerCallback(&$controller, $callback) { function triggerCallback($callback, &$controller) {
foreach ($this->_primary as $name) { foreach ($this->_primary as $name) {
$component =& $this->_loaded[$name]; $component =& $this->_loaded[$name];
if (method_exists($component, $callback) && $component->enabled === true) { if (method_exists($component, $callback) && $component->enabled === true) {

View file

@ -514,6 +514,31 @@ class Controller extends Object {
return true; 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. * Queries & sets valid HTTP response codes & messages.
* *
@ -835,7 +860,7 @@ class Controller extends Object {
App::import('View', $this->view); App::import('View', $this->view);
} }
$this->Component->beforeRender($this); $this->Component->triggerCallback('beforeRender', $this);
$this->params['models'] = $this->modelNames; $this->params['models'] = $this->modelNames;