Browse Source

Better Module::init refactoring

tags/2.0.0-beta
Alexander Makarov 11 years ago
parent
commit
54e1abaa7b
  1. 19
      framework/yii/base/Application.php
  2. 12
      framework/yii/base/Module.php

19
framework/yii/base/Application.php

@ -140,6 +140,11 @@ abstract class Application extends Module
$this->registerCoreComponents(); $this->registerCoreComponents();
Component::__construct($config); Component::__construct($config);
$this->preloadComponents();
if ($this->controllerNamespace === null) {
$this->controllerNamespace = 'app\\controllers';
}
} }
/** /**
@ -172,20 +177,6 @@ abstract class Application extends Module
} }
/** /**
* Initializes the application.
* This method is called after the application is created and initialized with property values
* given in configuration.
*/
public function init()
{
$this->preloadComponents();
if ($this->controllerNamespace === null) {
$this->controllerNamespace = 'app\\controllers';
}
}
/**
* Loads components that are declared in [[preload]]. * Loads components that are declared in [[preload]].
* @throws InvalidConfigException if a component or module to be preloaded is unknown * @throws InvalidConfigException if a component or module to be preloaded is unknown
*/ */

12
framework/yii/base/Module.php

@ -130,6 +130,12 @@ abstract class Module extends Component
$this->id = $id; $this->id = $id;
$this->module = $parent; $this->module = $parent;
parent::__construct($config); parent::__construct($config);
if ($this->controllerNamespace === null) {
$class = get_class($this);
if (($pos = strrpos($class, '\\')) !== false) {
$this->controllerNamespace = substr($class, 0, $pos) . '\\controllers';
}
}
} }
/** /**
@ -173,12 +179,6 @@ abstract class Module extends Component
public function init() public function init()
{ {
$this->preloadComponents(); $this->preloadComponents();
if ($this->controllerNamespace === null) {
$class = get_class($this);
if (($pos = strrpos($class, '\\')) !== false) {
$this->controllerNamespace = substr($class, 0, $pos) . '\\controllers';
}
}
} }
/** /**

Loading…
Cancel
Save