From d3beeb7ddcf799b1ac827f1b7998f7e308365f51 Mon Sep 17 00:00:00 2001 From: Klimov Paul Date: Thu, 16 May 2013 20:38:02 +0300 Subject: [PATCH] Usage of "yii\console\controllers\AssetController::actionCompress()" has been clarified. --- .../console/controllers/AssetControllerTest.php | 17 ++------------ yii/console/controllers/AssetController.php | 27 ++++++++++++++-------- 2 files changed, 20 insertions(+), 24 deletions(-) diff --git a/tests/unit/framework/console/controllers/AssetControllerTest.php b/tests/unit/framework/console/controllers/AssetControllerTest.php index b87eb87..9dc7c11 100644 --- a/tests/unit/framework/console/controllers/AssetControllerTest.php +++ b/tests/unit/framework/console/controllers/AssetControllerTest.php @@ -130,20 +130,6 @@ class AssetControllerTest extends TestCase } /** - * Creates test bundles configuration file. - * @param string $fileName output filename. - * @param array[] $bundles asset bundles config. - * @throws Exception on failure. - */ - protected function createBundleFile($fileName, array $bundles) - { - $content = 'createBundleConfig($bundles), true).';'; - if (file_put_contents($fileName, $content) <= 0) { - throw new \Exception("Unable to create file '{$fileName}'!"); - } - } - - /** * Creates test compress config file. * @param string $fileName output file name. * @param array[] $bundles asset bundles config. @@ -224,7 +210,6 @@ class AssetControllerTest extends TestCase ), );; $bundleFile = $this->testFilePath . DIRECTORY_SEPARATOR . 'bundle.php'; - $this->createBundleFile($bundleFile, $bundles); $configFile = $this->testFilePath . DIRECTORY_SEPARATOR . 'config.php'; $this->createCompressConfigFile($configFile, $bundles); @@ -233,6 +218,8 @@ class AssetControllerTest extends TestCase $this->runAssetControllerAction('compress', array($configFile, $bundleFile)); // Then : + $this->assertTrue(file_exists($bundleFile), 'Unable to create output bundle file!'); + $compressedCssFileName = $this->testAssetsBasePath . DIRECTORY_SEPARATOR . 'all.css'; $this->assertTrue(file_exists($compressedCssFileName), 'Unable to compress CSS files!'); $compressedJsFileName = $this->testAssetsBasePath . DIRECTORY_SEPARATOR . 'all.js'; diff --git a/yii/console/controllers/AssetController.php b/yii/console/controllers/AssetController.php index cf833b4..a707cb7 100644 --- a/yii/console/controllers/AssetController.php +++ b/yii/console/controllers/AssetController.php @@ -77,8 +77,10 @@ class AssetController extends Controller /** * Combines and compresses the asset files according to the given configuration. + * During the process new asset bundle configuration file will be created. + * You should replace your original asset bundle configuration with this file in order to use compressed files. * @param string $configFile configuration file name. - * @param string $bundleFile + * @param string $bundleFile output asset bundles configuration file name. */ public function actionCompress($configFile, $bundleFile) { @@ -124,10 +126,10 @@ class AssetController extends Controller } /** - * Creates full list of asset bundles. + * Creates full list of source asset bundles. * @param array[] $bundles list of asset bundle configurations. * @param array $extensions list of the extension paths. - * @return \yii\web\AssetBundle[] list of asset bundles. + * @return \yii\web\AssetBundle[] list of source asset bundles. */ protected function loadBundles($bundles, $extensions) { @@ -152,9 +154,10 @@ class AssetController extends Controller } /** - * @param array $targets - * @param \yii\web\AssetBundle[] $bundles list of asset bundles. - * @return \yii\web\AssetBundle[] + * Creates full list of output asset bundles. + * @param array $targets output asset bundles configuration. + * @param \yii\web\AssetBundle[] $bundles list of source asset bundles. + * @return \yii\web\AssetBundle[] list of output asset bundles. * @throws \yii\console\Exception on failure. */ protected function loadTargets($targets, $bundles) @@ -260,9 +263,10 @@ class AssetController extends Controller } /** - * @param \yii\web\AssetBundle[] $targets - * @param \yii\web\AssetBundle[] $bundles - * @return \yii\web\AssetBundle[] + * Adjust dependencies between asset bundles in the way source bundles begin to depend on output ones. + * @param \yii\web\AssetBundle[] $targets output asset bundles. + * @param \yii\web\AssetBundle[] $bundles source asset bundles. + * @return \yii\web\AssetBundle[] output asset bundles. */ protected function adjustDependency($targets, $bundles) { @@ -321,6 +325,11 @@ class AssetController extends Controller } } + /** + * Saves new asset bundles configuration. + * @param \yii\web\AssetBundle[] $targets list of asset bundles to be saved. + * @param string $bundleFile output file name. + */ protected function saveTargets($targets, $bundleFile) { $array = array();