From 602592411df232b01bd483db88ca1d97e6cc4455 Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Fri, 18 Oct 2013 10:33:56 -0400 Subject: [PATCH] Fixes #996. --- framework/yii/console/controllers/AssetController.php | 16 ---------------- framework/yii/web/AssetBundle.php | 2 -- framework/yii/web/AssetManager.php | 14 +++++++++----- 3 files changed, 9 insertions(+), 23 deletions(-) diff --git a/framework/yii/console/controllers/AssetController.php b/framework/yii/console/controllers/AssetController.php index 1e95dd8..a3c5de5 100644 --- a/framework/yii/console/controllers/AssetController.php +++ b/framework/yii/console/controllers/AssetController.php @@ -136,7 +136,6 @@ class AssetController extends Controller $this->loadConfiguration($configFile); $bundles = $this->loadBundles($this->bundles); $targets = $this->loadTargets($this->targets, $bundles); - $this->publishBundles($bundles, $this->assetManager); $timestamp = time(); foreach ($targets as $name => $target) { echo "Creating output bundle '{$name}':\n"; @@ -276,21 +275,6 @@ class AssetController extends Controller } /** - * Publishes given asset bundles. - * @param \yii\web\AssetBundle[] $bundles asset bundles to be published. - */ - protected function publishBundles($bundles) - { - echo "\nPublishing bundles:\n"; - $assetManager = $this->getAssetManager(); - foreach ($bundles as $name => $bundle) { - $bundle->publish($assetManager); - echo " '".$name."' published.\n"; - } - echo "\n"; - } - - /** * Builds output asset bundle. * @param \yii\web\AssetBundle $target output asset bundle * @param string $type either 'js' or 'css'. diff --git a/framework/yii/web/AssetBundle.php b/framework/yii/web/AssetBundle.php index aa2d02b..d34cb49 100644 --- a/framework/yii/web/AssetBundle.php +++ b/framework/yii/web/AssetBundle.php @@ -138,8 +138,6 @@ class AssetBundle extends Object */ public function registerAssets($view) { - $this->publish($view->getAssetManager()); - foreach ($this->js as $js) { $view->registerJsFile($this->baseUrl . '/' . $js, $this->jsOptions); } diff --git a/framework/yii/web/AssetManager.php b/framework/yii/web/AssetManager.php index 35e555f..5b47214 100644 --- a/framework/yii/web/AssetManager.php +++ b/framework/yii/web/AssetManager.php @@ -101,15 +101,19 @@ class AssetManager extends Component public function getBundle($name) { if (isset($this->bundles[$name])) { - if (is_array($this->bundles[$name])) { - $this->bundles[$name] = Yii::createObject(array_merge(array('class' => $name), $this->bundles[$name])); - } elseif (!$this->bundles[$name] instanceof AssetBundle) { + if ($this->bundles[$name] instanceof AssetBundle) { + return $this->bundles[$name]; + } elseif (is_array($this->bundles[$name])) { + $bundle = Yii::createObject(array_merge(array('class' => $name), $this->bundles[$name])); + } else { throw new InvalidConfigException("Invalid asset bundle: $name"); } } else { - $this->bundles[$name] = Yii::createObject($name); + $bundle = Yii::createObject($name); } - return $this->bundles[$name]; + /** @var AssetBundle $bundle */ + $bundle->publish($this); + return $this->bundles[$name] = $bundle; } private $_converter;