_registry = $registry; $this->config($config); if (!empty($this->components)) { $this->_componentMap = $registry->normalizeArray($this->components); } } /** * 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 = array('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' => 'initialize', '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; } }