_registry = $registry; $controller = $registry->getController(); if ($controller) { $this->request =& $controller->request; } $this->config($config); if (!empty($this->components)) { $this->_componentMap = $registry->normalizeArray($this->components); } $this->initialize($config); } /** * Constructor hook method. * * Implement this method to avoid having to overwrite * the constructor and call parent. * * @param array $config The configuration settings provided to this component. * @return void */ public function initialize(array $config) { } /** * Magic method for lazy loading $components. * * @param string $name Name of component to get. * @return mixed A Component object or null. */ public function __get($name) { if (isset($this->_componentMap[$name]) && !isset($this->{$name})) { $config = ['enabled' => false] + (array)$this->_componentMap[$name]['config']; $this->{$name} = $this->_registry->load($this->_componentMap[$name]['class'], $config); } if (isset($this->{$name})) { return $this->{$name}; } } /** * Get the Controller callbacks this Component is interested in. * * Uses Conventions to map controller events to standard component * callback method names. By defining one of the callback methods a * component is assumed to be interested in the related event. * * Override this method if you need to add non-conventional event listeners. * Or if you want components to listen to non-standard events. * * @return array */ public function implementedEvents() { $eventMap = [ 'Controller.initialize' => 'beforeFilter', 'Controller.startup' => 'startup', 'Controller.beforeRender' => 'beforeRender', 'Controller.beforeRedirect' => 'beforeRedirect', 'Controller.shutdown' => 'shutdown', ]; $events = []; foreach ($eventMap as $event => $method) { if (method_exists($this, $method)) { $events[$event] = $method; } } return $events; } }