Installation
composer require shivas/versioning-bundle
Add to config/bundles.php:
return [
// ...
Shivas\VersioningBundle\ShivasVersioningBundle::class => ['all' => true],
];
Configure
Edit config/packages/versioning.yaml (auto-generated):
shivas_versioning:
handler: git # or 'manual'/'initial'
version: '0.1.0' # fallback if handler fails
First Use Case Access the version in a controller:
use Shivas\VersioningBundle\Versioning\VersionManager;
class AppController extends AbstractController {
public function index(VersionManager $versionManager) {
$version = $versionManager->getVersion();
return $this->render('index.html.twig', ['version' => $version]);
}
}
Display in Twig:
<div>App Version: {{ version }}</div>
Git-Based Versioning (Recommended)
v1.2.3).versioning.yaml:
shivas_versioning:
handler: git
git tag -a vX.Y.Z -m "Release" before deployment.Manual Version Bumping
php bin/console app:version:bump [major|minor|patch]
php bin/console app:version:bump minor → 0.2.0.Fallback to Initial Version
0.1.0 (configurable).# In deploy.php
$deploy->run("php bin/console app:version:bump patch");
return $this->json(['data' => $data, 'version' => $versionManager->getVersion()]);
version in versioning.yaml per environment:
# config/packages/dev/versioning.yaml
shivas_versioning:
version: 'dev-{{ date('YmdHis') }}'
Git Tag Format
vX.Y.Z (e.g., v1.0.0). The bundle strips the v prefix.git tag -a v1.0.0 instead of 1.0.0.Caching Issues
php bin/console cache:clear
Handler Priority
handler: git fails (e.g., no tags), it falls back to the version config. Test with:
php bin/console debug:config shivas_versioning
php bin/console debug:config shivas_versioning
git tag -l 'v*' # List all version tags
Custom Handlers Create a new handler (e.g., for SVN or custom logic):
// src/Handler/CustomHandler.php
namespace App\Handler;
use Shivas\VersioningBundle\Versioning\HandlerInterface;
class CustomHandler implements HandlerInterface {
public function getVersion(): string {
return file_get_contents('/path/to/version.txt');
}
}
Register in versioning.yaml:
shivas_versioning:
handler: custom
Bind the service in services.yaml:
Shivas\VersioningBundle\Versioning\HandlerInterface: '@App\Handler\CustomHandler'
Override Version Parameter Dynamically set the version in a service:
// src/EventListener/VersionListener.php
namespace App\EventListener;
use Shivas\VersioningBundle\Versioning\VersionManager;
use Symfony\Component\HttpKernel\Event\RequestEvent;
class VersionListener {
public function onKernelRequest(RequestEvent $event, VersionManager $versionManager) {
if ($event->isMainRequest()) {
$versionManager->setVersion('1.2.3-custom'); // Override
}
}
}
Register the listener in services.yaml:
services:
App\EventListener\VersionListener:
tags:
- { name: kernel.event_listener, event: kernel.request, method: onKernelRequest }
How can I help you explore Laravel packages today?