Installation:
composer require corley/version-bundle
Register the bundle in app/AppKernel.php:
$bundles[] = new Corley\VersionBundle\CorleyVersionBundle();
First Use Case:
config/version.yml):
app/console corley:version:init 0.0.1
app/console corley:version:bump 0.0.1
app/console corley:version:show
Expose Version in Twig:
Add to config/config.yml:
imports:
- { resource: version.yml }
twig:
globals:
version: %version%
Version Bumping:
corley:version:bump with semantic versioning (e.g., 0.0.1 for patch, 0.1.0 for minor, 1.0.0 for major).app/console corley:version:bump 0.0.1
Version in Templates: Access the version globally in Twig:
<footer>
App Version: {{ version.number }}
Build: {{ version.build }} <!-- Optional build metadata -->
</footer>
Static Asset Versioning: Append version to cache-bust static files (CSS/JS):
{% javascripts
['/js/app.js', '/js/vendor.js']
{'filter': 'js_version_filter'}
%}
Define the filter in a Twig extension (see Gotchas).
CI/CD Integration:
- name: Bump version
run: php bin/console corley:version:bump $NEW_VERSION
version.yml per environment (e.g., config/version_dev.yml) using Symfony’s parameter system.return response()->json(['version' => $this->container->getParameter('version.number')]);
versions table and sync with version.yml via a post-install command.File Permissions:
Ensure config/version.yml is writable by the web server user. Run:
chmod 644 config/version.yml
Twig Global Overrides:
If version global isn’t working, clear the cache:
php bin/console cache:clear
Static Asset Filtering: The bundle doesn’t provide a built-in Twig filter for versioning assets. Create a custom filter:
// src/Twig/AppExtension.php
class AppExtension extends \Twig_Extension
{
public function getFilters()
{
return [
new \Twig_SimpleFilter('version', function ($path) {
return $path . '?v=' . $this->container->getParameter('version.number');
}),
];
}
}
Register the extension in services.yml:
services:
app.twig.extension:
class: App\Twig\AppExtension
arguments: ['@service_container']
tags: ['twig.extension']
Version Format Validation:
The bundle doesn’t validate version strings (e.g., 1.2 or abc). Stick to semantic versioning (e.g., 1.2.3).
version.yml:
Verify the file exists and contains expected data:
# config/version.yml
number: 1.0.0
build: 202305151200
--verbose for debug info:
app/console corley:version:bump 1.0.0 --verbose
VersionManager service.Version class to include a project field.How can I help you explore Laravel packages today?