From 6c179ef3a7fc0dfc787dfc5318ed554cd5124791 Mon Sep 17 00:00:00 2001 From: Klimov Paul Date: Mon, 3 Jun 2013 20:47:37 +0300 Subject: [PATCH 1/7] File creation checks at "AssetController" have been updated to use Exceptions. --- .../yii/console/controllers/AssetController.php | 25 +++++++++++++--------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/framework/yii/console/controllers/AssetController.php b/framework/yii/console/controllers/AssetController.php index 8e3de29..0d09570 100644 --- a/framework/yii/console/controllers/AssetController.php +++ b/framework/yii/console/controllers/AssetController.php @@ -159,7 +159,7 @@ class AssetController extends Controller } } - $this->getAssetManager(); // check asset manager configuration + $this->getAssetManager(); // check asset manager configuration is correct } /** @@ -420,7 +420,7 @@ class AssetController extends Controller } $array = var_export($array, true); $version = date('Y-m-d H:i:s', time()); - $bytesWritten = file_put_contents($bundleFile, <<adjustCssUrl(file_get_contents($file), dirname($file), dirname($outputFile)) . "/*** END FILE: $file ***/\n"; } - file_put_contents($outputFile, $content); + if (!file_put_contents($outputFile, $content)) { + throw new Exception("Unable to write output CSS file '{$outputFile}'."); + } } /** @@ -590,6 +595,7 @@ EOD /** * Creates template of configuration file for [[actionCompress]]. * @param string $configFile output file name. + * @throws \yii\console\Exception on failure. */ public function actionTemplate($configFile) { @@ -622,9 +628,8 @@ EOD; return; } } - $bytesWritten = file_put_contents($configFile, $template); - if ($bytesWritten<=0) { - echo "Error: unable to write file '{$configFile}'!\n\n"; + if (!file_put_contents($configFile, $template)) { + throw new Exception("Unable to write template file '{$configFile}'."); } else { echo "Configuration file template created at '{$configFile}'.\n\n"; } From 5172dbd4c4748f2913b08768e651522499bc5ccb Mon Sep 17 00:00:00 2001 From: Klimov Paul Date: Mon, 3 Jun 2013 21:25:04 +0300 Subject: [PATCH 2/7] Additional comments have been added to the "AssetController::actionTemplate" output. --- framework/yii/console/controllers/AssetController.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/framework/yii/console/controllers/AssetController.php b/framework/yii/console/controllers/AssetController.php index 0d09570..d794b30 100644 --- a/framework/yii/console/controllers/AssetController.php +++ b/framework/yii/console/controllers/AssetController.php @@ -601,13 +601,17 @@ EOD; { $template = << require('path/to/bundles.php'), - // + // The list of extensions, which asset files should be included to compression: 'extensions' => require('path/to/namespaces.php'), - // + // Compression result asset bundle: 'targets' => array( 'all' => array( 'basePath' => __DIR__, @@ -616,7 +620,7 @@ return array( 'css' => 'all-{ts}.css', ), ), - + // Asset manager configuration: 'assetManager' => array( 'basePath' => __DIR__, 'baseUrl' => '/test', From 9b8b285eb1b3b639324994f72c6c64d47a5aa09e Mon Sep 17 00:00:00 2001 From: Klimov Paul Date: Mon, 3 Jun 2013 21:43:54 +0300 Subject: [PATCH 3/7] Doc comments at "AssetController" have been extended. --- framework/yii/console/controllers/AssetController.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/framework/yii/console/controllers/AssetController.php b/framework/yii/console/controllers/AssetController.php index d794b30..dab7e90 100644 --- a/framework/yii/console/controllers/AssetController.php +++ b/framework/yii/console/controllers/AssetController.php @@ -14,6 +14,20 @@ use yii\console\Controller; /** * This command allows you to combine and compress your JavaScript and CSS files. * + * Usage: + * 1. Create a configuration file using 'template' action: + * yii asset/template /path/to/myapp/config.php + * 2. Edit the created config file, adjusting it for your web application needs. + * 3. Run the 'compress' action, using created config: + * yii asset /path/to/myapp/config.php /path/to/myapp/config/assets_compressed.php + * 4. Adjust your web application config to use compressed assets. + * + * Note: in the console environment some path aliases like '@wwwroot' and '@www' may not exist, + * so corresponding paths inside the configuration should be specified directly. + * + * Note: by default this command relies on an external tools to perform actual files compression, + * check [[jsCompressor]] and [[cssCompressor]] for more details. + * * @property array|\yii\web\AssetManager $assetManager asset manager, which will be used for assets processing. * * @author Qiang Xue From 1f68becb61767fb83cc1310404572ff99d244b3e Mon Sep 17 00:00:00 2001 From: Klimov Paul Date: Mon, 3 Jun 2013 21:46:56 +0300 Subject: [PATCH 4/7] Doc comments at "AssetController" have been updated. --- framework/yii/console/controllers/AssetController.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/framework/yii/console/controllers/AssetController.php b/framework/yii/console/controllers/AssetController.php index dab7e90..61e54e9 100644 --- a/framework/yii/console/controllers/AssetController.php +++ b/framework/yii/console/controllers/AssetController.php @@ -57,7 +57,7 @@ class AssetController extends Controller * ~~~ * 'all' => array( * 'css' => 'all.css', - * 'js' => 'js.css', + * 'js' => 'all.js', * 'depends' => array( ... ), * ) * ~~~ @@ -322,7 +322,7 @@ class AssetController extends Controller /** * Builds 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'. * @param \yii\web\AssetBundle[] $bundles source asset bundles. * @param integer $timestamp current timestamp. * @throws Exception on failure. @@ -617,7 +617,7 @@ EOD; Date: Mon, 3 Jun 2013 21:53:07 +0300 Subject: [PATCH 5/7] Output of "AssetController::actionCompress" have been adjusted to hold the action id. --- framework/yii/console/controllers/AssetController.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/framework/yii/console/controllers/AssetController.php b/framework/yii/console/controllers/AssetController.php index 61e54e9..e525ef1 100644 --- a/framework/yii/console/controllers/AssetController.php +++ b/framework/yii/console/controllers/AssetController.php @@ -437,11 +437,11 @@ class AssetController extends Controller $bundleFileContent = <<id}" command. * DO NOT MODIFY THIS FILE DIRECTLY. - * @version $version + * @version {$version} */ -return $array; +return {$array}; EOD; if (!file_put_contents($bundleFile, $bundleFileContent)) { throw new Exception("Unable to write output bundle configuration at '{$bundleFile}'."); From ec8fecb8b079b3eec4a66df67e91cc3412fc77e5 Mon Sep 17 00:00:00 2001 From: Klimov Paul Date: Mon, 3 Jun 2013 21:56:03 +0300 Subject: [PATCH 6/7] Check output bundle file format has been added to "AssetControllerTest::testActionCompress()" unit test. --- tests/unit/framework/console/controllers/AssetControllerTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/unit/framework/console/controllers/AssetControllerTest.php b/tests/unit/framework/console/controllers/AssetControllerTest.php index db6d2a7..9d7dd28 100644 --- a/tests/unit/framework/console/controllers/AssetControllerTest.php +++ b/tests/unit/framework/console/controllers/AssetControllerTest.php @@ -239,6 +239,7 @@ class AssetControllerTest extends TestCase // Then : $this->assertTrue(file_exists($bundleFile), 'Unable to create output bundle file!'); + $this->assertTrue(is_array(require($bundleFile)), 'Output bundle file has incorrect format!'); $compressedCssFileName = $this->testAssetsBasePath . DIRECTORY_SEPARATOR . 'all.css'; $this->assertTrue(file_exists($compressedCssFileName), 'Unable to compress CSS files!'); From 152e5a0e15f1f6edf9106adf61dbaa1e0423d366 Mon Sep 17 00:00:00 2001 From: Klimov Paul Date: Mon, 3 Jun 2013 22:34:15 +0300 Subject: [PATCH 7/7] Doc comments and descriptive output at"AssetController" has been adjusted. --- framework/yii/console/controllers/AssetController.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/framework/yii/console/controllers/AssetController.php b/framework/yii/console/controllers/AssetController.php index e525ef1..4c759de 100644 --- a/framework/yii/console/controllers/AssetController.php +++ b/framework/yii/console/controllers/AssetController.php @@ -71,7 +71,7 @@ class AssetController extends Controller */ private $_assetManager = array(); /** - * @var string|callback Java Script file compressor. + * @var string|callback JavaScript file compressor. * If a string, it is treated as shell command template, which should contain * placeholders {from} - source file name - and {to} - output file name. * Otherwise, it is treated as PHP callback, which should perform the compression. @@ -173,7 +173,7 @@ class AssetController extends Controller } } - $this->getAssetManager(); // check asset manager configuration is correct + $this->getAssetManager(); // check if asset manager configuration is correct } /** @@ -450,7 +450,7 @@ EOD; } /** - * Compresses given Java Script files and combines them into the single one. + * Compresses given JavaScript files and combines them into the single one. * @param array $inputFiles list of source file names. * @param string $outputFile output file name. * @throws \yii\console\Exception on failure @@ -508,7 +508,7 @@ EOD; } /** - * Combines Java Script files into a single one. + * Combines JavaScript files into a single one. * @param array $inputFiles source file names. * @param string $outputFile output file name. * @throws \yii\console\Exception on failure. @@ -522,7 +522,7 @@ EOD; . "/*** END FILE: $file ***/\n"; } if (!file_put_contents($outputFile, $content)) { - throw new Exception("Unable to write output Java Script file '{$outputFile}'."); + throw new Exception("Unable to write output JavaScript file '{$outputFile}'."); } } @@ -621,11 +621,11 @@ EOD; * so corresponding paths should be specified directly. */ return array( - // The list of asset bundles, which files should be included to compression: + // The list of asset bundles to compress: 'bundles' => require('path/to/bundles.php'), - // The list of extensions, which asset files should be included to compression: + // The list of extensions to compress: 'extensions' => require('path/to/namespaces.php'), - // Compression result asset bundle: + // Asset bundle for compression output: 'targets' => array( 'all' => array( 'basePath' => __DIR__,