Browse Source

Fixes #996.

tags/2.0.0-beta
Qiang Xue 11 years ago
parent
commit
602592411d
  1. 16
      framework/yii/console/controllers/AssetController.php
  2. 2
      framework/yii/web/AssetBundle.php
  3. 14
      framework/yii/web/AssetManager.php

16
framework/yii/console/controllers/AssetController.php

@ -136,7 +136,6 @@ class AssetController extends Controller
$this->loadConfiguration($configFile); $this->loadConfiguration($configFile);
$bundles = $this->loadBundles($this->bundles); $bundles = $this->loadBundles($this->bundles);
$targets = $this->loadTargets($this->targets, $bundles); $targets = $this->loadTargets($this->targets, $bundles);
$this->publishBundles($bundles, $this->assetManager);
$timestamp = time(); $timestamp = time();
foreach ($targets as $name => $target) { foreach ($targets as $name => $target) {
echo "Creating output bundle '{$name}':\n"; 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. * Builds output asset bundle.
* @param \yii\web\AssetBundle $target output asset bundle * @param \yii\web\AssetBundle $target output asset bundle
* @param string $type either 'js' or 'css'. * @param string $type either 'js' or 'css'.

2
framework/yii/web/AssetBundle.php

@ -138,8 +138,6 @@ class AssetBundle extends Object
*/ */
public function registerAssets($view) public function registerAssets($view)
{ {
$this->publish($view->getAssetManager());
foreach ($this->js as $js) { foreach ($this->js as $js) {
$view->registerJsFile($this->baseUrl . '/' . $js, $this->jsOptions); $view->registerJsFile($this->baseUrl . '/' . $js, $this->jsOptions);
} }

14
framework/yii/web/AssetManager.php

@ -101,15 +101,19 @@ class AssetManager extends Component
public function getBundle($name) public function getBundle($name)
{ {
if (isset($this->bundles[$name])) { if (isset($this->bundles[$name])) {
if (is_array($this->bundles[$name])) { if ($this->bundles[$name] instanceof AssetBundle) {
$this->bundles[$name] = Yii::createObject(array_merge(array('class' => $name), $this->bundles[$name])); return $this->bundles[$name];
} elseif (!$this->bundles[$name] instanceof AssetBundle) { } 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"); throw new InvalidConfigException("Invalid asset bundle: $name");
} }
} else { } 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; private $_converter;

Loading…
Cancel
Save