예제 #1
0
 public function __construct()
 {
     parent::__construct();
     $eventBus = new BusProxy(new EventBus());
     $eventBus->setGate(new Gate());
     $this->snapshot = SnapshotManager::instance('mongodb', 'snapshot_test');
     $this->snapshot->setSnapshotPeriodical(2);
     $this->storage = StorageManager::instance('mongodb', 'app_test');
     $this->storage->attachSnapshot($this->snapshot);
     $this->repository = new TicketRepository($this->storage, $eventBus);
     $this->clear();
 }
예제 #2
0
 /**
  * {@inheritdoc}
  */
 public function attach(BusInterface $bus)
 {
     $name = $bus->getName();
     if (BusInterface::SYSTEM_BUS === $name) {
         $this->assertValidSystemBus($bus);
         $this->buses[$name] = $bus;
         return;
     }
     $this->assertNotRegisteredBus($name);
     $bus = new BusProxy($bus);
     $bus->setGate($this);
     $this->buses[$name] = $bus;
 }
예제 #3
0
 /**
  * Publish domain events in stream.
  *
  * @param DomainEventStreamInterface $stream
  *
  * @return array
  * @throws \Exception
  */
 private function publish(DomainEventStreamInterface $stream)
 {
     $results = array();
     foreach ($stream->all() as $domain) {
         try {
             $results[] = $this->eventBus->dispatch($domain->getPayload());
             $this->storage->append($this->table, $domain, 'OK');
             $this->broadcast($domain->getPayload(), array('status' => 'OK', 'exception' => null));
         } catch (\Exception $e) {
             $metadata = array('code' => $e->getCode(), 'file' => $e->getFile(), 'line' => $e->getLine(), 'message' => $e->getMessage());
             $this->storage->append($this->table, $domain, 'ERROR', $metadata);
             $this->broadcast($domain->getPayload(), array('status' => 'ERROR', 'exception' => $metadata));
             throw $e;
         }
     }
     return $results;
 }