Installation
composer require cegeka/symfony-toolkit
Add the bundle to your config/bundles.php (Symfony) or composer.json (Laravel via Symfony bridge):
Cegeka\SymfonyToolkit\SymfonyToolkitBundle::class => ['all' => true],
First Use Case: Console Commands
The package provides a Command base class for consistent CLI tooling. Create a custom command:
php bin/console make:command MyCommand
Extend Cegeka\SymfonyToolkit\Command\Command in your command class for built-in helpers (e.g., logging, output formatting).
Key Entry Points
src/Command/ (for CLI tools).config/packages/cegeka_symfony_toolkit.yaml (if using Symfony).src/Service/ (for reusable logic).Command-Line Tooling
$this->output (Symfony’s OutputInterface) for colored, formatted output.
$this->output->writeln('<info>Success!</info>');
Argument and Option classes for validation:
protected function configure(): void
{
$this->addArgument('path', InputArgument::REQUIRED, 'File path');
$this->addOption('force', null, InputOption::VALUE_NONE, 'Force overwrite');
}
Service Layer
public function __construct(private FileSystem $fileSystem) {}
// src/Service/FileService.php
public function ensureDirectoryExists(string $path): void
{
if (!file_exists($path)) {
mkdir($path, 0777, true);
}
}
Configuration Management
Cegeka\SymfonyToolkit\Config\ConfigManager to load environment-specific settings:
# config/packages/cegeka_symfony_toolkit.yaml
cegeka_symfony_toolkit:
environments:
local:
debug: true
Access via:
$config = $this->getContainer()->get('cegeka_symfony_toolkit.config_manager');
$debugMode = $config->get('debug'); // Returns `true` in local env.
Event-Driven Extensions
$this->getEventDispatcher()->dispatch(
new MyCustomEvent($data),
MyCustomEvent::NAME
);
services.yaml:
services:
App\EventListener\MyListener:
tags:
- { name: 'kernel.event_listener', event: 'my_custom_event', method: 'onEvent' }
Symfony vs. Laravel Integration
symfony/console or laravel/symfony-bundle for Laravel compatibility.config/app.php:
'aliases' => [
'cegeka.config_manager' => App\Services\ConfigManager::class,
],
Configuration Overrides
!imports in Symfony’s config/packages/cegeka_symfony_toolkit.yaml to prevent accidental overrides:
imports:
- { resource: cegeka_symfony_toolkit.yaml, !ignore_errors }
Command Autowiring
console.command in services.yaml:
services:
App\Command\MyCommand:
tags: ['console.command']
Output Formatting
$this->output->section() for grouped output:
$this->output->section('Processing Files');
$this->output->writeln('File 1: OK');
Environment Detection
$env = $this->getContainer()->get('kernel')->getEnvironment();
$this->output->writeln(sprintf('Environment: <comment>%s</comment>', $env));
Service Debugging
$services = $this->getContainer()->getServiceIds();
file_put_contents('services.txt', print_r($services, true));
Custom Command Helpers
Cegeka\SymfonyToolkit\Command\Command to add shared methods:
// src/Command/BaseCommand.php
abstract class BaseCommand extends Command
{
protected function logProgress(string $message): void
{
$this->output->writeln(sprintf('<fg=yellow>%s</>', $message));
}
}
Dynamic Configuration
.env):
$configManager = $this->getContainer()->get('cegeka_symfony_toolkit.config_manager');
$configManager->addLoader(function () {
return ['custom_key' => getenv('CUSTOM_VALUE')];
});
Event Subscribers
// src/EventSubscriber/MySubscriber.php
class MySubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents(): array
{
return [
KernelEvents::TERMINATE => 'onTerminate',
];
}
public function onTerminate(KernelEvent $event): void
{
// Cleanup logic
}
}
How can I help you explore Laravel packages today?