black/cqrs-php
Minimal CQRS command bus for PHP/DDD without event sourcing. Define Command and CommandHandler, register handlers to commands, then dispatch via a single Bus. Includes optional Symfony bundle integration with service tags for handler registration.
ServiceProvider or bind()).Artisan::command()) or third-party packages (e.g., spatie/laravel-command-bus) suffice?boot() for event listeners, handle() for middleware).Artisan::command() for simpler use cases.Bus in AppServiceProvider).bus->handle() in try-catch).Bus as a singleton).// app/Providers/AppServiceProvider.php
public function register() {
$this->app->singleton(Black\DDD\CQRSinPHP\Infrastructure\CQRS\Bus::class);
$bus = $this->app->make(Black\DDD\CQRSinPHP\Infrastructure\CQRS\Bus::class);
$bus->register(MyCommand::class, new MyHandler());
}
Bus in tests to isolate command logic.database transactions).| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Bus crashes during handling | Command lost | Use Laravel Queues with retries. |
| Handler throws unhandled error | Silent failure | Global exception handler + monitoring. |
| Database transaction fails | Inconsistent state | Use Laravel transactions or Sagas. |
| PHP version incompatibility | Package breaks | Fork and update dependencies. |
| No read model updates | Stale queries | Implement event listeners for state changes. |
How can I help you explore Laravel packages today?