/** * Constructor * * @param ComponentCollection $collection A ComponentCollection this component can use to lazy load its components * @param array $settings Array of configuration settings. */ public function __construct(ComponentCollection $collection, $settings = array()) { $this->_Collection = $collection; $this->settings = $settings; $this->_set($settings); if (!empty($this->components)) { $this->_componentMap = ComponentCollection::normalizeObjectArray($this->components); } }
/** * Initializes all the Components for a controller. * Attaches a reference of each component to the Controller. * * @param Controller $Controller Controller to initialize components for. * @return void */ public function init(Controller $Controller) { if (empty($Controller->components)) { return; } $this->_Controller = $Controller; $components = ComponentCollection::normalizeObjectArray($Controller->components); foreach ($components as $name => $properties) { $Controller->{$name} = $this->load($properties['class'], $properties['settings']); } }
/** * Loads a Component * * @param string $componentClass Name of model class to load * @param array $settings array of settings * @return void * @access public **/ public function loadComponent($componentClass, $settings = array()) { if (empty($this->_internals['controller'])) { $this->loadController(); } $components = ComponentCollection::normalizeObjectArray(array($componentClass => $settings)); foreach ($components as $name => $properties) { $this->_internals['controller']->{$name} = $this->_internals['controller']->Components->load($properties['class'], $properties['settings']); $this->{$name} = $this->_internals['controller']->{$name}; } if (method_exists($this->_internals['controller']->{$name}, 'initialize')) { $this->_internals['controller']->{$name}->initialize($this->_internals['controller']); } if (method_exists($this->_internals['controller']->{$name}, 'startup')) { $this->_internals['controller']->{$name}->startup($this->_internals['controller']); } }