Browse Source

Usage of "yii\console\controllers\AssetController::actionCompress()" has been clarified.

tags/2.0.0-beta
Klimov Paul 12 years ago
parent
commit
d3beeb7ddc
  1. 17
      tests/unit/framework/console/controllers/AssetControllerTest.php
  2. 27
      yii/console/controllers/AssetController.php

17
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 = '<?php return '.var_export($this->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';

27
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();

Loading…
Cancel
Save