Ejemplo n.º 1
0
 /**
  * Handle a single domain event
  *
  * @param DomainEvent $event
  * @return void
  */
 protected function when(DomainEvent $event)
 {
     $method = 'when' . ClassToString::short($event);
     if (is_callable([$this, $method])) {
         $this->{$method}($event);
     }
 }
Ejemplo n.º 2
0
 public function commit(UncommittedEvents $events)
 {
     $query = '
         INSERT INTO `aggregate_events` (`identity`, `event`, `data`)
         VALUES (:identity, :event, :data)';
     $pdo = $this->conn->getWrappedConnection();
     foreach ($events as $event) {
         try {
             $pdo->beginTransaction();
             $stmt = $pdo->prepare($query);
             $stmt->execute([':identity' => (string) $event->getAggregateIdentity(), ':event' => (string) ClassToString::fqcn($event), ':data' => (string) serialize($event)]);
             $pdo->commit();
         } catch (\PDOException $ex) {
             $pdo->rollBack();
             throw $ex;
         }
     }
 }
Ejemplo n.º 3
0
 public function replayEvents(Identity $identity, $offset = null, $max = null)
 {
     $events = $this->store->getAggregateHistoryFor($identity, $offset, $max);
     foreach ($events as $event) {
         $method = 'when' . ClassToString::short($event);
         if (!isset($this->listeners[$method])) {
             continue;
         }
         if (is_array($this->listeners[$method])) {
             foreach ($this->listeners[$method] as $listener) {
                 call_user_func($listener, $event);
             }
         } else {
             call_user_func($this->listeners[$method], $event);
         }
     }
     return $this;
 }