execute() methodinterface Command {
public function execute(): void;
public function undo(): void;
}
class SendEmailCommand implements Command {
public function execute(): void { /* send */ }
public function undo(): void { /* cancel */ }
}
class CommandBus {
private array $history = [];
public function dispatch(Command $cmd): void {
$cmd->execute();
$this->history[] = $cmd;
}
}
CQRS (Command Bus), task queues, transaction script, undo/redo in editors.