diff --git a/apps/advanced/backend/config/main.php b/apps/advanced/backend/config/main.php index 7d82a3415d..a0b5fc9932 100644 --- a/apps/advanced/backend/config/main.php +++ b/apps/advanced/backend/config/main.php @@ -10,6 +10,7 @@ return [ 'id' => 'app-backend', 'basePath' => dirname(__DIR__), 'controllerNamespace' => 'backend\controllers', + 'bootstrap' => ['log'], 'modules' => [], 'components' => [ 'user' => [ diff --git a/apps/advanced/console/config/main.php b/apps/advanced/console/config/main.php index f91278d262..ec60922f97 100644 --- a/apps/advanced/console/config/main.php +++ b/apps/advanced/console/config/main.php @@ -9,6 +9,7 @@ $params = array_merge( return [ 'id' => 'app-console', 'basePath' => dirname(__DIR__), + 'bootstrap' => ['log'], 'controllerNamespace' => 'console\controllers', 'modules' => [], 'components' => [ diff --git a/apps/advanced/frontend/config/main.php b/apps/advanced/frontend/config/main.php index e891885551..1ed8305ec8 100644 --- a/apps/advanced/frontend/config/main.php +++ b/apps/advanced/frontend/config/main.php @@ -9,6 +9,7 @@ $params = array_merge( return [ 'id' => 'app-frontend', 'basePath' => dirname(__DIR__), + 'bootstrap' => ['log'], 'controllerNamespace' => 'frontend\controllers', 'components' => [ 'user' => [ diff --git a/apps/basic/config/console.php b/apps/basic/config/console.php index 88c43c5264..462f35bd6c 100644 --- a/apps/basic/config/console.php +++ b/apps/basic/config/console.php @@ -8,6 +8,7 @@ $db = require(__DIR__ . '/db.php'); return [ 'id' => 'basic-console', 'basePath' => dirname(__DIR__), + 'bootstrap' => ['log'], 'controllerNamespace' => 'app\commands', 'extensions' => require(__DIR__ . '/../vendor/yiisoft/extensions.php'), 'components' => [ diff --git a/apps/basic/config/web.php b/apps/basic/config/web.php index 845a521c4b..fb9c6791c9 100644 --- a/apps/basic/config/web.php +++ b/apps/basic/config/web.php @@ -6,6 +6,7 @@ $db = require(__DIR__ . '/db.php'); $config = [ 'id' => 'basic', 'basePath' => dirname(__DIR__), + 'bootstrap' => ['log'], 'extensions' => require(__DIR__ . '/../vendor/yiisoft/extensions.php'), 'components' => [ 'cache' => [ diff --git a/extensions/debug/Module.php b/extensions/debug/Module.php index 6a61ebe1f3..6271bdc4cc 100644 --- a/extensions/debug/Module.php +++ b/extensions/debug/Module.php @@ -71,9 +71,15 @@ class Module extends \yii\base\Module implements BootstrapInterface public function init() { parent::init(); - $this->dataPath = Yii::getAlias($this->dataPath); + $this->initPanels(); + } + /** + * Initializes panels. + */ + protected function initPanels() + { // merge custom panels and core panels so that they are ordered mainly by custom panels if (empty($this->panels)) { $this->panels = $this->corePanels(); diff --git a/framework/base/Application.php b/framework/base/Application.php index 82724814cd..e6778b0589 100644 --- a/framework/base/Application.php +++ b/framework/base/Application.php @@ -137,29 +137,32 @@ abstract class Application extends Module * [ * 'name' => 'extension name', * 'version' => 'version number', - * 'bootstrap' => 'BootstrapClassName', + * 'bootstrap' => 'BootstrapClassName', // optional, may also be a configuration array * 'alias' => [ * '@alias1' => 'to/path1', * '@alias2' => 'to/path2', * ], * ] * ~~~ + * + * The "bootstrap" class listed above will be instantiated during the application + * [[bootstrap()|bootstrapping process]]. If the class implements [[BootstrapInterface]], + * its [[BootstrapInterface::bootstrap()|bootstrap()]] method will be also be called. */ public $extensions = []; /** - * @var array list of bootstrap components that should be run right after - * the application is configured. + * @var array list of components that should be run during the application [[bootstrap()|bootstrapping process]]. * - * Each bootstrap component may be specified in one of the following formats: + * Each component may be specified in one of the following formats: * * - an application component ID as specified via [[components]]. * - a module ID as specified via [[modules]]. * - a class name. * - a configuration array. * - * Note that a bootstrap component must implement [[BootstrapInterface]], or an exception will be thrown. - * The [[BootstrapInterface::bootstrap()]] method of each bootstrap component will be called - * when the component is instantiated and run in in [[bootstrap()]]. + * During the bootstrapping process, each component will be instantiated. If the component class + * implements [[BootstrapInterface]], its [[BootstrapInterface::bootstrap()|bootstrap()]] method + * will be also be called. */ public $bootstrap = []; /** @@ -245,7 +248,6 @@ abstract class Application extends Module public function init() { $this->state = self::STATE_INIT; - $this->get('log'); $this->bootstrap(); } @@ -253,7 +255,6 @@ abstract class Application extends Module * Initializes extensions and executes bootstrap components. * This method is called by [[init()]] after the application has been fully configured. * If you override this method, make sure you also call the parent implementation. - * @throws InvalidConfigException if a bootstrap component does not implement BootstrapInterface */ protected function bootstrap() { @@ -266,10 +267,10 @@ abstract class Application extends Module if (isset($extension['bootstrap'])) { $component = Yii::createObject($extension['bootstrap']); if ($component instanceof BootstrapInterface) { + Yii::trace("Bootstrap with " . get_class($component) . '::bootstrap()', __METHOD__); $component->bootstrap($this); } else { - $class = is_array($extension['bootstrap']) ? $extension['bootstrap']['class'] : $extension['bootstrap']; - throw new InvalidConfigException("$class must implement \\yii\\base\\BootstrapInterface"); + Yii::trace("Bootstrap with " . get_class($component), __METHOD__); } } } @@ -280,6 +281,8 @@ abstract class Application extends Module $component = $this->get($class); } elseif ($this->hasModule($class)) { $component = $this->getModule($class); + } elseif (strpos($class, '\\') === false) { + throw new InvalidConfigException("Unknown bootstrap component ID: $class"); } } if (!isset($component)) { @@ -287,9 +290,10 @@ abstract class Application extends Module } if ($component instanceof BootstrapInterface) { + Yii::trace("Bootstrap with " . get_class($component) . '::bootstrap()', __METHOD__); $component->bootstrap($this); } else { - throw new InvalidConfigException((is_array($class) ? $class['class'] : $class) . " must implement \\yii\\base\\BootstrapInterface"); + Yii::trace("Bootstrap with " . get_class($component), __METHOD__); } } }