Commit b03b38fb by Qiang Xue

Added $publish parameter to AssetManager::getBundle().

parent 1475b462
...@@ -552,7 +552,7 @@ class View extends Component ...@@ -552,7 +552,7 @@ class View extends Component
foreach($bundle->depends as $dep) { foreach($bundle->depends as $dep) {
$this->registerAssetFiles($dep); $this->registerAssetFiles($dep);
} }
$bundle->registerAssets($this); $bundle->registerAssetFiles($this);
unset($this->assetBundles[$name]); unset($this->assetBundles[$name]);
} }
......
...@@ -133,7 +133,7 @@ class AssetBundle extends Object ...@@ -133,7 +133,7 @@ class AssetBundle extends Object
* Registers the CSS and JS files with the given view. * Registers the CSS and JS files with the given view.
* @param \yii\base\View $view the view that the asset files are to be registered with. * @param \yii\base\View $view the view that the asset files are to be registered with.
*/ */
public function registerAssets($view) public function registerAssetFiles($view)
{ {
foreach ($this->js as $js) { foreach ($this->js as $js) {
if (strpos($js, '/') !== 0 && strpos($js, '://') === false) { if (strpos($js, '/') !== 0 && strpos($js, '://') === false) {
......
...@@ -95,10 +95,12 @@ class AssetManager extends Component ...@@ -95,10 +95,12 @@ class AssetManager extends Component
* it will treat `$name` as the class of the asset bundle and create a new instance of it. * it will treat `$name` as the class of the asset bundle and create a new instance of it.
* *
* @param string $name the class name of the asset bundle * @param string $name the class name of the asset bundle
* @param boolean $publish whether to publish the asset files in the asset bundle before it is returned.
* If you set this false, you must manually call `AssetBundle::publish()` to publish the asset files.
* @return AssetBundle the asset bundle instance * @return AssetBundle the asset bundle instance
* @throws InvalidConfigException if $name does not refer to a valid asset bundle * @throws InvalidConfigException if $name does not refer to a valid asset bundle
*/ */
public function getBundle($name) public function getBundle($name, $publish = true)
{ {
if (isset($this->bundles[$name])) { if (isset($this->bundles[$name])) {
if ($this->bundles[$name] instanceof AssetBundle) { if ($this->bundles[$name] instanceof AssetBundle) {
...@@ -111,8 +113,10 @@ class AssetManager extends Component ...@@ -111,8 +113,10 @@ class AssetManager extends Component
} else { } else {
$bundle = Yii::createObject($name); $bundle = Yii::createObject($name);
} }
if ($publish) {
/** @var AssetBundle $bundle */ /** @var AssetBundle $bundle */
$bundle->publish($this); $bundle->publish($this);
}
return $this->bundles[$name] = $bundle; return $this->bundles[$name] = $bundle;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment