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); } }