From ee2d93b1813244e46c238ca955a52d5eb59f8d30 Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Tue, 16 Apr 2013 07:59:31 -0400 Subject: [PATCH] scripts WIP --- framework/base/ViewContent.php | 2 +- framework/web/AssetBundle.php | 20 +++++++++++++++++++- framework/web/AssetManager.php | 16 +++++++++++++++- 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/framework/base/ViewContent.php b/framework/base/ViewContent.php index 8b4e835..a2951e7 100644 --- a/framework/base/ViewContent.php +++ b/framework/base/ViewContent.php @@ -98,7 +98,7 @@ class ViewContent extends Component $bundle = $this->assetManager->getBundle($name); if ($bundle !== null) { $this->assetBundles[$name] = false; - $bundle->registerWith($this); + $bundle->registerAssets($this); $this->assetBundles[$name] = true; } else { throw new InvalidConfigException("Unknown asset bundle: $name"); diff --git a/framework/web/AssetBundle.php b/framework/web/AssetBundle.php index 3e4541e..26fbb34 100644 --- a/framework/web/AssetBundle.php +++ b/framework/web/AssetBundle.php @@ -42,10 +42,18 @@ class AssetBundle extends Object public $css = array(); public $depends = array(); + public function mapTo($target) + { + $this->depends = array($target); + $this->js = $this->css = array(); + $this->basePath = null; + $this->baseUrl = null; + } + /** * @param \yii\base\ViewContent $content */ - public function registerWith($content) + public function registerAssets($content) { foreach ($this->depends as $name) { $content->registerAssetBundle($name); @@ -65,4 +73,14 @@ class AssetBundle extends Object } } } + + /** + * @param \yii\web\AssetManager $assetManager + */ + public function publish($assetManager) + { + if ($this->basePath !== null && $this->baseUrl === null) { + return; + } + } } \ No newline at end of file diff --git a/framework/web/AssetManager.php b/framework/web/AssetManager.php index 1f82e7c..4f44f0c 100644 --- a/framework/web/AssetManager.php +++ b/framework/web/AssetManager.php @@ -129,9 +129,23 @@ class AssetManager extends Component $this->bundles[$name] = Yii::createObject($config); } } + /** @var $bundle AssetBundle */ + $bundle = $this->bundles[$name]; + if (isset($this->bundleMap[$name]) && is_string($this->bundleMap[$name])) { + $target = $this->bundleMap[$name]; + if (!isset($this->bundles[$target])) { + if (isset($this->bundleMap[$target])) { + $this->bundles[$target] = $this->bundleMap[$target]; + } else { + throw new InvalidConfigException("Asset bundle '$name' is mapped to an unknown bundle: $target"); + } + } + $bundle->mapTo($target); + unset($this->bundleMap[$name]); + } if ($publish) { - + $bundle->publish($this); } return $this->bundles[$name];