From cec6692123ce6e2af4381ed72f73de7971ce74e9 Mon Sep 17 00:00:00 2001 From: Mark Story Date: Sat, 27 Feb 2010 22:01:08 -0500 Subject: [PATCH] Re-arrange the arguments of triggerCallback. Modifying Dispatcher so its not calling methods on Component directly. Additional methods added to Controller. --- cake/dispatcher.php | 7 ++----- cake/libs/controller/component.php | 8 ++++---- cake/libs/controller/controller.php | 27 ++++++++++++++++++++++++++- 3 files changed, 32 insertions(+), 10 deletions(-) diff --git a/cake/dispatcher.php b/cake/dispatcher.php index c54d87954..49551694b 100644 --- a/cake/dispatcher.php +++ b/cake/dispatcher.php @@ -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; diff --git a/cake/libs/controller/component.php b/cake/libs/controller/component.php index e9fe47e23..f640d5432 100644 --- a/cake/libs/controller/component.php +++ b/cake/libs/controller/component.php @@ -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) { diff --git a/cake/libs/controller/controller.php b/cake/libs/controller/controller.php index 1f57ae218..8b8e7dcc9 100644 --- a/cake/libs/controller/controller.php +++ b/cake/libs/controller/controller.php @@ -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;