Example #1
0
 /**
  * Configures given module with provided configuration array.
  * @param \yii\base\Module $module module to be configured.
  * @param array $config configuration array.
  */
 public function configure($module, $config = null)
 {
     if ($config === null) {
         $config = $this->fetchConfig();
     }
     foreach ($config as $key => $value) {
         switch ($key) {
             case 'components':
                 $components = array_merge($module->getComponents(true), $module->getComponents(false));
                 $components = ArrayHelper::merge($components, $value);
                 $module->setComponents($components);
                 break;
             case 'modules':
                 $nestedModules = $module->getModules(false);
                 foreach ($nestedModules as $id => $nestedModule) {
                     if (!isset($value[$id])) {
                         continue;
                     }
                     if (is_object($nestedModule)) {
                         $this->configure($nestedModule, $value[$id]);
                     } else {
                         $nestedModules[$id] = ArrayHelper::merge($nestedModule, $value[$id]);
                     }
                 }
                 $module->setModules($nestedModules);
                 break;
             case 'params':
                 $module->params = ArrayHelper::merge($module->params, $value);
                 break;
             default:
                 $module->{$key} = $value;
         }
     }
 }