Exemplo n.º 1
0
    }
    private function findUserById($id)
    {
        if (!isset($this->users[$id])) {
            // here would normally be a database call or something
            $this->users[$id] = new User();
            $this->map->add($this->users[$id]);
        }
        return $this->users[$id];
    }
}
class MyEventHandler
{
    public function onChangeEmail(DomainObjectChanged $event)
    {
        echo "E-Mail changed from " . $event->oldEmail . " to " . $event->email . "\n";
    }
}
// 1. Setup the Library with InMemory Handlers
$messageBus = new InMemoryEventMessageBus();
$identityMap = new SimpleIdentityMap();
$queue = new EventProviderQueue($identityMap);
$commandBus = new DirectCommandBus(array(new EventMessageHandlerFactory($messageBus, $queue)));
// 2. Register a command service and an event handler
$userService = new UserService($identityMap, $messageBus);
$someEventHandler = new MyEventHandler();
$commandBus->register('MyApp\\ChangeEmailCommand', $userService);
$messageBus->register($someEventHandler);
// 3. Invoke command!
$commandBus->handle(new ChangeEmailCommand(array('id' => 1234, 'email' => '*****@*****.**')));
$commandBus->handle(new ChangeEmailCommand(array('id' => 1234, 'email' => '*****@*****.**')));
Exemplo n.º 2
0
{
    public $row;
    public $player;
}
class FieldMarked extends DefaultDomainEvent
{
    public $field;
    public $player;
}
class MarkField extends DefaultCommand
{
    public $field;
    public $player;
}
// 1. Setup the Library with InMemory Handlers
$messageBus = new InMemoryEventMessageBus();
$identityMap = new SimpleIdentityMap();
$queue = new EventProviderQueue($identityMap);
$commandBus = new DirectCommandBus(array(new EventMessageHandlerFactory($messageBus, $queue)));
// 2. register
$boardService = new BoardService($identityMap);
$humanService = new HumanPlayerService($commandBus);
$aiService = new ComputerPlayerService($commandBus);
$uiService = new DisplayService();
$commandBus->register("TicTacToe\\MarkField", $boardService);
$messageBus->register($aiService);
$messageBus->register($uiService);
$messageBus->register($humanService);
while (!$humanService->gameOver()) {
    try {
        $humanService->ask();