KachkaevAssetsVersionBundle
The purpose of this Symfony2 bundle is to automate the process of updating assets version each time it needs to be changed − doing this manually is a real pain.
The bundle can read and write assets_version parameter in app/config/parameters.yml from Symfony console. One of the advantages of the bundle is that it does not break existing formatting in the yaml file, all user comments are also kept.
So, if you configuration looks the following way:
# app/config/config.yml
framework:
templating: { engines: ['twig'], assets_version: %assets_version% }
# ...
# app/config/parameters.yml
parameters:
assets_version: v42
# ...
then you can simply call php app/console assets_version:increment to change version from v42 to v43. It is important to clear prod cache afterwards as this is not done automatically. More features are described below.
Detailed information on using assets versioning can be found in Symfony2 documentation: http://symfony.com/doc/current/reference/configuration/framework.html#ref-framework-assets-version
Installation
Composer
Add the following dependency to your project’s composer.json file:
"require": {
// ...
"kachkaev/assets-version-bundle": "dev-master"
// ...
}
Now tell composer to download the bundle by running the command:
$ php composer.phar update kachkaev/assets-version-bundle
Composer will install the bundle to vendor/kachkaev directory.
Adding bundle to your application kernel
// app/AppKernel.php
public function registerBundles()
{
$bundles = array(
// ...
new Kachkaev\AssetsVersionBundle\KachkaevAssetsVersionBundle(),
// ...
);
}
Configuration
Here is the default configuration for the bundle:
kachkaev_assets_version:
filename: %kernel.root_dir%/config/parameters.yml # name of the file where application parameters are stored
parametername: assets_version # name of property that defines assets version in that file
manager: Kachkaev\AssetsVersionBundle\AssetsVersionManager # location of version manager
In most cases custom configuration is not needed, so simply add the following line to your app/config/config.yml:
kachkaev_assets_version: ~
Note: It is not recommended to store real value of assets version in config.yml because its incrementing will cause git conflicts. It is better to keep it in parameters.yml added to .gitignore and also have parameters.yml.dist with blank or initial value for assets version.
Usage
The bundle adds two commands to symfony console: assets_version:increment and assets_version:set that are incrementing and setting assets version, respectively. Usage examples:
# Increments assets version by 1 (e.g. was v42, became v43)
$ php app/console assets_version:increment
# Increments assets version by 10 (e.g. was 42, became 52; was 0042, became 0052 - leading zeros are kept)
$ php app/console assets_version:increment 10
# Sets version to "1970-01-01_0000"
$ php app/console assets_version:set 1970-01-01_0000
# Sets version to "abcDEF-something_else" (no numeric part, so assets_version:increment will stop working)
$ php app/console assets_version:set abcDEF-something_else
# Decrements assets version by 10 (e.g. was lorem.ipsum.0.15, became lorem.ipsum.0.5)
# Note two dashes before the argument that prevent symfony from parsing -1 as an option
$ php app/console assets_version:increment -- -10
# Decrementing version by a number bigger than current version results 0 (e.g. was v0010, became v0000)
$ php app/console assets_version:increment -- -1000
Value for assets version must consist only of letters, numbers and the following characters: .-_. Incrementing only works when existing value is integer or has integer ending.
Please don’t forget to clear cache by calling php app/console cache:clear --env=prod for changes to take effect in the production environment.
If you are using assetic bundle on your production server and want to change asset version at each dump automatically, you may find useful the following shell script:
# bin/update_assets
php app/console assets_version:increment --env=prod
php app/console cache:clear --env=prod
php app/console assetic:dump --env=prod
At the moment the bundle only works with yaml files, but more file types can be added if there is a demand.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
assets_version:
filename: ~
parametername: ~
manager: ~
-
Symfony 2.3 support in composer.json
By kachkaev, 22 hours ago
-
Symfony 2.3 support in composer.json
By kachkaev, 22 hours ago
-
Symfony 2.3 support in composer.json
By kachkaev, 22 hours ago
-
Symfony 2.3 support in composer.json
By kachkaev, 22 hours ago
-
Symfony 2.3 support in composer.json
By kachkaev, 22 hours ago
-
Symfony 2.3 support in composer.json
By kachkaev, 22 hours ago
-
Symfony 2.3 support in composer.json
By kachkaev, 22 hours ago
-
Symfony 2.3 support in composer.json
By kachkaev, 22 hours ago
-
Symfony 2.3 support in composer.json
By kachkaev, 22 hours ago
-
Symfony 2.3 support in composer.json
By kachkaev, 22 hours ago
-
Symfony 2.3 support in composer.json
By kachkaev, 22 hours ago
-
Update composer.json
By kachkaev, 4 months ago
-
Merge branch 'issue_2'
By kachkaev, 6 months ago
-
Closed issue #2, updated tests
By kachkaev, 6 months ago
-
Update LICENSE
By kachkaev, 6 months ago
-
Adding issue #2 case to tests
By kachkaev, 6 months ago
-
Updated bundle description in composer.json
By kachkaev, 6 months ago
-
Changed dev-master branch alias
By kachkaev, 6 months ago
-
Branch alias in composer.json
By kachkaev, 6 months ago
-
Minor improvements in console output.
By kachkaev, 6 months ago
-
Update README.md
By kachkaev, 6 months ago
-
Update README.md
By kachkaev, 6 months ago
-
Fixes in tests
By kachkaev, 6 months ago
-
Syntax fix in composer.json
By kachkaev, 6 months ago
-
Added finder to composer.json
By kachkaev, 6 months ago
-
Added unit tests for AssetsVersionManager
By kachkaev, 6 months ago
-
Bug fixes and improvements in AssetsVersionManager
By kachkaev, 6 months ago
-
Added .travis.yml
By kachkaev, 6 months ago
-
Merge branch 'master' of https://github.com/kachkaev/KachkaevAssetsVersionBundle
By kachkaev, 6 months ago
-
Added preserving of leading zeros in version number.
By kachkaev, 6 months ago

