From c32def86184f2a5128bf8224c485f7b75004aaf7 Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Thu, 18 Apr 2013 18:59:27 -0400 Subject: [PATCH] turn asset manager into a getter. --- framework/base/ViewContent.php | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/framework/base/ViewContent.php b/framework/base/ViewContent.php index dedd3bb..e5a1a06 100644 --- a/framework/base/ViewContent.php +++ b/framework/base/ViewContent.php @@ -24,11 +24,6 @@ class ViewContent extends Component const TOKEN_BODY_BEGIN = ''; const TOKEN_BODY_END = ''; - /** - * @var \yii\web\AssetManager - */ - public $assetManager; - public $assetBundles; public $title; public $metaTags; @@ -42,14 +37,6 @@ class ViewContent extends Component public $jsInBody; public $jsFilesInBody; - public function init() - { - parent::init(); - if ($this->assetManager === null) { - $this->assetManager = Yii::$app->getAssets(); - } - } - public function reset() { $this->title = null; @@ -64,6 +51,21 @@ class ViewContent extends Component $this->jsInBody = null; $this->jsFilesInBody = null; } + + private $_assetManager; + + /** + * @return \yii\web\AssetManager + */ + public function getAssetManager() + { + return $this->_assetManager ?: Yii::$app->getAssets(); + } + + public function setAssetManager($value) + { + $this->_assetManager = $value; + } public function begin() { @@ -95,10 +97,11 @@ class ViewContent extends Component public function registerAssetBundle($name) { if (!isset($this->assetBundles[$name])) { - $bundle = $this->assetManager->getBundle($name); + $am = $this->getAssetManager(); + $bundle = $am->getBundle($name); if ($bundle !== null) { $this->assetBundles[$name] = false; - $bundle->registerAssets($this, $this->assetManager); + $bundle->registerAssets($this, $am); $this->assetBundles[$name] = true; } else { throw new InvalidConfigException("Unknown asset bundle: $name");