Installation
composer require dpoposki/symfony-kernel
Register the bundle in config/bundles.php (Symfony) or AppKernel.php (legacy):
return [
// ...
Dpoposki\SymfonyKernel\DpoposkiSymfonyKernelBundle::class => ['all' => true],
];
First Use Case Leverage the kernel for custom request handling or bootstrapping logic. Example:
use Symfony\Component\HttpKernel\KernelInterface;
use Dpoposki\SymfonyKernel\Kernel\CustomKernel;
class AppKernel extends CustomKernel {
public function __construct($environment, $debug) {
parent::__construct($environment, $debug);
}
// Override to add custom bundles or logic
protected function build(KernelInterface $kernel) {
$kernel->getContainer()->loadFromExtension('framework', [
'secret' => '%env(APP_SECRET)%',
]);
}
}
Where to Look First
src/Kernel/CustomKernel.php: Core kernel logic.src/DependencyInjection/: Configuration and extensions.tests/: Example use cases and edge scenarios.Extending the Kernel
Override CustomKernel to inject custom logic:
class AppKernel extends CustomKernel {
public function registerBundles() {
$bundles = parent::registerBundles();
$bundles[] = new \Acme\CustomBundle\AcmeCustomBundle();
return $bundles;
}
}
Dynamic Configuration
Use the kernel’s build() method to modify container parameters dynamically:
protected function build(KernelInterface $kernel) {
$container = $kernel->getContainer();
$container->setParameter('custom.param', 'dynamic_value');
}
Event Listeners
Attach listeners to kernel events (e.g., kernel.request):
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
$kernel->getContainer()->get('event_dispatcher')->addListener(
'kernel.request',
function (GetResponseEvent $event) {
// Custom logic here
}
);
$kernel = $this->createMock(CustomKernel::class);
$kernel->method('getContainer')->willReturn($container);
Bundle Registration Order
registerBundles() carefully to avoid BundleNotFoundException.Circular Dependencies
build() or registerBundles() can create circular references if not managed.Environment Variables
%env() syntax. For Laravel, preload env vars:
putenv('APP_ENV=' . getenv('APP_ENV'));
var/log/dev.log (Symfony) or Laravel’s storage/logs/laravel.log.$container->get('debug.dump_service');
Custom Console Commands Extend the kernel to add CLI tools:
$kernel->getContainer()->set('console.command.my_command', function () {
return new MyCommand();
});
Middleware Integration Add Symfony middleware to Laravel’s pipeline:
$kernel->getContainer()->get('http_kernel')->pushMiddleware(new MyMiddleware());
Configuration Overrides
Merge custom config in build():
$container->loadFromExtension('framework', [
'router' => ['resource' => '%kernel.project_dir%/config/routes.yaml'],
]);
build():
if (empty($container->getParameter('app.secret'))) {
throw new \RuntimeException('APP_SECRET is required!');
}
How can I help you explore Laravel packages today?