bbit/async-dispatcher-bundle
kernel.terminate.EventDispatcher interface, making it pluggable into Laravel via:
symfony/event-dispatcher + symfony/http-kernel in Laravel.Events and Symfony’s EventDispatcher.EventDispatcher, HttpKernel), which are compatible with Laravel via Composer.Illuminate\Events\Dispatcher) differs from Symfony’s. Direct integration may require custom event listeners or a proxy dispatcher.EventDispatcher behind an interface to allow swapping implementations.kernel.terminate. Not thread-safe in multi-process environments (e.g., Laravel Horizon).kernel.terminate fails (e.g., crashes)?queue:work + delayed jobs.spatie/laravel-async-jobs.Messenger component (if migrating to Symfony).symfony/event-dispatcher, symfony/http-kernel.Symfony\Component\HttpKernel\HttpKernelInterface to hook into terminate.// app/Providers/EventServiceProvider.php
public function boot()
{
$dispatcher = new Symfony\Component\EventDispatcher\EventDispatcher();
$dispatcher->addListener('kernel.terminate', function () {
// Flush buffered events via AsyncDispatcherBundle
});
}
AsyncDispatcher facade that adapts Laravel’s Events to Symfony’s EventDispatcher.class AsyncDispatcher implements AsyncDispatcherInterface {
public function dispatch($event) {
// Buffer event for later dispatch
}
}
symfony/event-dispatcher (^6.0).symfony/http-kernel (for terminate hook).psr/log for error handling.class LaravelAsyncDispatcher {
private $symfonyDispatcher;
public function __construct() {
$this->symfonyDispatcher = new Symfony\Component\EventDispatcher\EventDispatcher();
// Register AsyncDispatcherBundle listeners
}
public function dispatchLaravelEvent($event) {
$this->symfonyDispatcher->dispatch(new SymfonyEvent($event));
}
}
symfony/event-dispatcher:^6.0 (PSR-15 compatible).symfony/http-kernel:^6.0.Symfony\Component\EventDispatcher\Event. Laravel events (Illuminate\Contracts\Events\Dispatcher) need adaptation.composer require symfony/event-dispatcher symfony/http-kernel bbit/async-dispatcher-bundle
# config/bundles.php
return [
BBIT\AsyncDispatcherBundle\BBITAsyncDispatcherBundle::class => ['all' => true],
];
$this->app->singleton('asyncDispatcher', function ($app) {
$dispatcher = new Symfony\Component\EventDispatcher\EventDispatcher();
$dispatcher->addSubscriber(new AsyncDispatcherSubscriber());
return $dispatcher;
});
event(new MyEvent()) with:
app('asyncDispatcher')->dispatch(new SymfonyEvent(new MyEvent()));
terminate).kernel.terminate in unit tests.$kernel = $this->createMock(HttpKernelInterface::class);
$kernel->expects($this->once())->method('terminate');
terminate fails before flushing.How can I help you explore Laravel packages today?