Installation
composer require bizkit/versioning-bundle
Add to config/bundles.php:
return [
// ...
Bizkit\VersioningBundle\BizkitVersioningBundle::class => ['all' => true],
];
Generate Version File Run the command to initialize versioning:
php bin/console bizkit:versioning:init
This creates config/versioning.yml (default location) with:
version: 1.0.0
release_date: '2024-01-01'
strategy: semantic
First Use Case Access the version in a controller:
use Bizkit\VersioningBundle\Versioning\VersionManager;
class AppController extends AbstractController {
public function showVersion(VersionManager $versionManager) {
return $this->json($versionManager->getVersion());
}
}
Version Management
VersionManager service to fetch/retrieve version data:
$version = $versionManager->getVersion(); // Returns "1.0.0"
$date = $versionManager->getReleaseDate(); // Returns DateTime
Version Incrementation
semantic, calver, or custom strategies):
# Semantic versioning (patch increment)
php bin/console bizkit:versioning:increment semantic
# Custom strategy (e.g., "custom-strategy")
php bin/console bizkit:versioning:increment custom-strategy
Custom Strategies
Bizkit\VersioningBundle\Versioning\Strategy\VersionStrategyInterface:
namespace App\Versioning;
use Bizkit\VersioningBundle\Versioning\Strategy\VersionStrategyInterface;
class CustomStrategy implements VersionStrategyInterface {
public function increment(string $currentVersion): string {
// Custom logic (e.g., "dev-2024.05.01")
return 'dev-' . date('Y.m.d');
}
}
config/packages/bizkit_versioning.yaml:
bizkit_versioning:
strategies:
custom_strategy: App\Versioning\CustomStrategy
Version-Aware Routing/Logic
VersionManager into services/controllers:
public function __construct(private VersionManager $versionManager) {}
if ($this->versionManager->isVersionGreaterThan('2.0.0')) {
$this->enableNewFeature();
}
VCS Integration (Git)
config/packages/bizkit_versioning.yaml:
bizkit_versioning:
vcs:
type: git
repository: /path/to/repo
increment command will auto-commit changes and tag releases (if enabled).Configuration Overrides
config/versioning.yml, but this can be overridden in config/packages/bizkit_versioning.yaml:
bizkit_versioning:
file: '%kernel.project_dir%/custom/version.yml'
Strategy Mismatches
increment command throws:
[ErrorException] Strategy "nonexistent" not found.
config/packages/bizkit_versioning.yaml for typos or missing strategy definitions.VCS Permissions
chmod -R 755 /path/to/repo).Version File Locking
versioning.yml, ensure the file isn’t locked by a running process.Symfony Cache Invalidation
php bin/console cache:clear
--no-debug flag in production to avoid cache rebuilds.Dry Run Mode
php bin/console bizkit:versioning:increment semantic --dry-run
Logging
bizkit_versioning:
debug: true
Custom VCS Handlers
Bizkit\VersioningBundle\Vcs\VcsHandlerInterface for non-Git systems (e.g., SVN):
class SvnHandler implements VcsHandlerInterface {
public function commit(string $message): bool { /* ... */ }
public function tag(string $version): bool { /* ... */ }
}
bizkit_versioning:
vcs:
type: svn
handler: App\Vcs\SvnHandler
Version Validation
1.0.0-alpha for semantic):
if (!$versionManager->isValidSemanticVersion($currentVersion)) {
throw new \RuntimeException("Invalid version format");
}
Environment-Specific Versions
bizkit_versioning:
version: '%env(VERSION_OVERRIDE)%'
.env:
VERSION_OVERRIDE=1.0.0-staging
Event Listeners
VersioningEvents:
use Bizkit\VersioningBundle\Event\VersioningEvents;
use Symfony\Component\EventDispatcher\Attribute\AsEventListener;
#[AsEventListener(event: VersioningEvents::VERSION_UPDATED)]
public function onVersionUpdated(VersioningEvent $event) {
// Log or trigger side effects (e.g., deploy hooks)
}
Custom Version Storage
Bizkit\VersioningBundle\Storage\VersionStorageInterface:
class DatabaseStorage implements VersionStorageInterface {
public function load(): array { /* ... */ }
public function save(array $data): void { /* ... */ }
}
bizkit_versioning:
storage: App\Storage\DatabaseStorage
API Endpoints
#[Route('/api/version', name: 'app_version', methods: ['GET'])]
public function getVersion(VersionManager $versionManager): JsonResponse {
return $this->json([
'version' => $versionManager->getVersion(),
'release_date' => $versionManager->getReleaseDate()->format('Y-m-d'),
]);
}
How can I help you explore Laravel packages today?