From 858ceb50397e40c60c69e39f927d102cf4bb9912 Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Tue, 30 Sep 2014 21:36:29 -0400 Subject: [PATCH] Added `yii\base\Application::loadedModules` --- framework/CHANGELOG.md | 1 + framework/base/Application.php | 4 ++++ framework/base/Module.php | 10 +++------- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index 5fea5f0aa6..88d1c43231 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -7,6 +7,7 @@ Yii Framework 2 Change Log - Bug #5260: `yii\i18n\Formatter::decimalSeparator` and `yii\i18n\Formatter::thousandSeparator` where not configurable when intl is not installed (execut, cebe) - Bug: Date and time formatting now assumes UTC as the timezone for input dates unless a timezone is explicitly given (cebe) - Enh #4275: Added `removeChildren()` to `yii\rbac\ManagerInterface` and implementations (samdark) +- Enh: Added `yii\base\Application::loadedModules` (qiangxue) 2.0.0-rc September 27, 2014 diff --git a/framework/base/Application.php b/framework/base/Application.php index ef90e34938..cdcb5774c2 100644 --- a/framework/base/Application.php +++ b/framework/base/Application.php @@ -180,6 +180,10 @@ abstract class Application extends Module * This property is managed by the application. Do not modify this property. */ public $state; + /** + * @var array list of loaded modules indexed by their class names. + */ + public $loadedModules = []; /** diff --git a/framework/base/Module.php b/framework/base/Module.php index f071198624..d301421517 100644 --- a/framework/base/Module.php +++ b/framework/base/Module.php @@ -123,10 +123,6 @@ class Module extends ServiceLocator * @var array child modules of this module */ private $_modules = []; - /** - * @var array list of currently requested modules indexed by their class names - */ - private static $_instances = []; /** @@ -151,7 +147,7 @@ class Module extends ServiceLocator public static function getInstance() { $class = get_called_class(); - return isset(self::$_instances[$class]) ? self::$_instances[$class] : null; + return isset(Yii::$app->loadedModules[$class]) ? Yii::$app->loadedModules[$class] : null; } /** @@ -162,9 +158,9 @@ class Module extends ServiceLocator public static function setInstance($instance) { if ($instance === null) { - unset(self::$_instances[get_called_class()]); + unset(Yii::$app->loadedModules[get_called_class()]); } else { - self::$_instances[get_class($instance)] = $instance; + Yii::$app->loadedModules[get_class($instance)] = $instance; } }