refactor(infrastructure): Reorganize routing and messaging architecture with middleware support

This commit is contained in:
m.jalmoudy
2025-12-02 16:56:10 +03:30
parent 5326f40b2b
commit a014c36f63
11 changed files with 138 additions and 39 deletions

View File

@@ -0,0 +1,24 @@
<?php
namespace DistributingCarriers\Infrastructure\Messaging;
class CommandBus
{
private $handlers = [];
public function register(string $commandClass, callable $handler): void
{
$this->handlers[$commandClass] = $handler;
}
public function dispatch(object $command): void
{
$commandClass = \get_class($command);
if (!isset($this->handlers[$commandClass])) {
throw new \Exception("No handler registered for command: $commandClass");
}
$handler = $this->handlers[$commandClass];
$handler($command);
}
}