mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
Refactoring existing callbacks into triggerCallback().
This commit is contained in:
parent
748ec4ee78
commit
e75f6fe2b4
1 changed files with 18 additions and 14 deletions
|
@ -109,12 +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) {
|
||||||
foreach ($this->_primary as $name) {
|
$this->triggerCallback($controller, 'startup');
|
||||||
$component =& $this->_loaded[$name];
|
|
||||||
if ($component->enabled === true && method_exists($component, 'startup')) {
|
|
||||||
$component->startup($controller);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -126,12 +121,7 @@ class Component extends Object {
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
function beforeRender(&$controller) {
|
function beforeRender(&$controller) {
|
||||||
foreach ($this->_primary as $name) {
|
$this->triggerCallback($controller, 'beforeRender');
|
||||||
$component =& $this->_loaded[$name];
|
|
||||||
if ($component->enabled === true && method_exists($component,'beforeRender')) {
|
|
||||||
$component->beforeRender($controller);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -166,10 +156,24 @@ class Component extends Object {
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
function shutdown(&$controller) {
|
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) {
|
foreach ($this->_primary as $name) {
|
||||||
$component =& $this->_loaded[$name];
|
$component =& $this->_loaded[$name];
|
||||||
if (method_exists($component,'shutdown') && $component->enabled === true) {
|
if (method_exists($component, $callback) && $component->enabled === true) {
|
||||||
$component->shutdown($controller);
|
$component->{$callback}($controller);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue