/**
  * Puts a component under the management of the module.
  * The component will be initialized by calling its {@link CApplicationComponent::init() init()}
  * method if it has not done so.
  * @param string $id component ID
  * @param IApplicationComponent $component the component to be added to the module.
  * If this parameter is null, it will unload the component from the module.
  */
 public function setComponent($id, $component)
 {
     if ($component === null) {
         unset($this->_components[$id]);
     } else {
         $this->_components[$id] = $component;
         if (!$component->getIsInitialized()) {
             $component->init();
         }
     }
 }
Esempio n. 2
0
 /**
  * Puts a component under the management of the module.
  * The component will be initialized by calling its {@link CApplicationComponent::init() init()}
  * method if it has not done so.
  * @param string $id component ID
  * @param array|IApplicationComponent $component application component
  * (either configuration array or instance). If this parameter is null,
  * component will be unloaded from the module.
  * @param boolean $merge whether to merge the new component configuration
  * with the existing one. Defaults to true, meaning the previously registered
  * component configuration with the same ID will be merged with the new configuration.
  * If set to false, the existing configuration will be replaced completely.
  * This parameter is available since 1.1.13.
  */
 public function setComponent($id, $component, $merge = true)
 {
     if ($component === null) {
         unset($this->_components[$id]);
         return;
     } elseif ($component instanceof IApplicationComponent) {
         $this->_components[$id] = $component;
         if (!$component->getIsInitialized()) {
             $component->init();
         }
         return;
     } elseif (isset($this->_components[$id])) {
         if (isset($component['class']) && get_class($this->_components[$id]) !== $component['class']) {
             unset($this->_components[$id]);
             $this->_componentConfig[$id] = $component;
             //we should ignore merge here
             return;
         }
         foreach ($component as $key => $value) {
             if ($key !== 'class') {
                 $this->_components[$id]->{$key} = $value;
             }
         }
     } elseif (isset($this->_componentConfig[$id]['class'], $component['class']) && $this->_componentConfig[$id]['class'] !== $component['class']) {
         $this->_componentConfig[$id] = $component;
         //we should ignore merge here
         return;
     }
     if (isset($this->_componentConfig[$id]) && $merge) {
         $this->_componentConfig[$id] = CMap::mergeArray($this->_componentConfig[$id], $component);
     } else {
         $this->_componentConfig[$id] = $component;
     }
 }