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();
 }
Example #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;
 }
 /**
  * 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;
 }