From 07f30cb04c9882c261495fee80809051179c8b5a Mon Sep 17 00:00:00 2001 From: Alexander Makarov Date: Sat, 24 May 2014 18:11:59 +0400 Subject: [PATCH 1/2] Fixes #3542: Removed requirement to specify `extensions` in application config --- apps/advanced/common/config/main.php | 1 - apps/basic/config/console.php | 1 - apps/basic/config/web.php | 1 - framework/CHANGELOG.md | 1 + framework/base/Application.php | 13 ++++++++++++- 5 files changed, 13 insertions(+), 4 deletions(-) diff --git a/apps/advanced/common/config/main.php b/apps/advanced/common/config/main.php index 67d498292d..c9071d108a 100644 --- a/apps/advanced/common/config/main.php +++ b/apps/advanced/common/config/main.php @@ -1,7 +1,6 @@ dirname(dirname(__DIR__)) . '/vendor', - 'extensions' => require(__DIR__ . '/../../vendor/yiisoft/extensions.php'), 'components' => [ 'cache' => [ 'class' => 'yii\caching\FileCache', diff --git a/apps/basic/config/console.php b/apps/basic/config/console.php index 462f35bd6c..85297b3cb1 100644 --- a/apps/basic/config/console.php +++ b/apps/basic/config/console.php @@ -10,7 +10,6 @@ return [ 'basePath' => dirname(__DIR__), 'bootstrap' => ['log'], 'controllerNamespace' => 'app\commands', - 'extensions' => require(__DIR__ . '/../vendor/yiisoft/extensions.php'), 'components' => [ 'cache' => [ 'class' => 'yii\caching\FileCache', diff --git a/apps/basic/config/web.php b/apps/basic/config/web.php index fbb7934e82..f9013d8fbb 100644 --- a/apps/basic/config/web.php +++ b/apps/basic/config/web.php @@ -6,7 +6,6 @@ $config = [ 'id' => 'basic', 'basePath' => dirname(__DIR__), 'bootstrap' => ['log'], - 'extensions' => require(__DIR__ . '/../vendor/yiisoft/extensions.php'), 'components' => [ 'cache' => [ 'class' => 'yii\caching\FileCache', diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index c90e21b0b2..a4be6ed4c3 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -54,6 +54,7 @@ Yii Framework 2 Change Log - Enh #3472: Added configurable option to encode spaces in dropDownLists and listBoxes (kartik-v) - Enh #3518: `yii\helpers\Html::encode()` now replaces invalid code sequences with "?" (DaSourcerer) - Enh #3521: Added `yii\filters\HttpCache::sessionCacheLimiter` (qiangxue) +- Enh #3542: Removed requirement to specify `extensions` in application config (samdark) - Enh: Added support for using sub-queries when building a DB query with `IN` condition (qiangxue) - Enh: Supported adding a new response formatter without the need to reconfigure existing formatters (qiangxue) - Enh: Added `yii\web\UrlManager::addRules()` to simplify adding new URL rules (qiangxue) diff --git a/framework/base/Application.php b/framework/base/Application.php index 58acc5f20d..f0cc9c8a34 100644 --- a/framework/base/Application.php +++ b/framework/base/Application.php @@ -8,6 +8,7 @@ namespace yii\base; use Yii; +use yii\log\Logger; /** * Application is the base class for all application classes. @@ -151,8 +152,11 @@ abstract class Application extends Module * 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. + * + * If the property isn't specified in the application bootstrap file i.e. index.php, content is loaded automatically + * from @vendor/yiisoft/extensions.php. */ - public $extensions = []; + public $extensions; /** * @var array list of components that should be run during the application [[bootstrap()|bootstrapping process]]. * @@ -262,6 +266,13 @@ abstract class Application extends Module */ protected function bootstrap() { + if ($this->extensions === null) { + try { + $this->extensions = include Yii::getAlias('@vendor/yiisoft/extensions.php'); + } catch (ErrorException $e) { + $this->extensions = []; + } + } foreach ($this->extensions as $extension) { if (!empty($extension['alias'])) { foreach ($extension['alias'] as $name => $path) { From 1122da950c90b3c97537e5f596e09621a0b1df86 Mon Sep 17 00:00:00 2001 From: Alexander Makarov Date: Sun, 25 May 2014 03:49:15 +0400 Subject: [PATCH 2/2] Adjustments according to comments on #3575 --- framework/base/Application.php | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/framework/base/Application.php b/framework/base/Application.php index f0cc9c8a34..0e393d24ff 100644 --- a/framework/base/Application.php +++ b/framework/base/Application.php @@ -8,7 +8,6 @@ namespace yii\base; use Yii; -use yii\log\Logger; /** * Application is the base class for all application classes. @@ -153,8 +152,8 @@ abstract class Application extends Module * [[bootstrap()|bootstrapping process]]. If the class implements [[BootstrapInterface]], * its [[BootstrapInterface::bootstrap()|bootstrap()]] method will be also be called. * - * If the property isn't specified in the application bootstrap file i.e. index.php, content is loaded automatically - * from @vendor/yiisoft/extensions.php. + * If not set explicitily in the application config, this property will be populated with the contents of + * `@vendor/yiisoft/extensions.php`. */ public $extensions; /** @@ -267,11 +266,8 @@ abstract class Application extends Module protected function bootstrap() { if ($this->extensions === null) { - try { - $this->extensions = include Yii::getAlias('@vendor/yiisoft/extensions.php'); - } catch (ErrorException $e) { - $this->extensions = []; - } + $file = Yii::getAlias('@vendor/yiisoft/extensions.php'); + $this->extensions = is_file($file) ? include($file) : []; } foreach ($this->extensions as $extension) { if (!empty($extension['alias'])) {