Пример #1
0
 /**
  * Produces a persistable GDS entity based on an aggregate root and an event.
  *
  * @param \Atrauzzi\PhpEventSourcing\AggregateRoot $aggregateRoot
  * @param object $event
  * @return \Atrauzzi\PhpEventSourcing\GoogleCloudDatastore\Event
  */
 private function createGdsEvent(AggregateRoot $aggregateRoot, $event)
 {
     $gdsEvent = $this->eventStore->createEntity(['created' => new DateTime(), 'type' => $this->getType($event), 'sequence' => $aggregateRoot->getLastSequence() + 1, 'aggregate_type' => $aggregateRoot->getType(), 'aggregate_id' => $aggregateRoot->getId(), 'discriminator_php' => get_class($event)]);
     // Extract all the POPO event's public properties and prefix them with `event_`.
     foreach (get_object_vars($event) as $property => $value) {
         $eventProperty = 'event_' . snake_case($property);
         $gdsEvent->{$eventProperty} = $value;
     }
     return $gdsEvent;
 }
 /**
  * @param \Atrauzzi\PhpEventSourcing\AggregateRoot $aggregateRoot
  * @param object $event
  */
 public function __construct(AggregateRoot $aggregateRoot, $event)
 {
     $this->aggregateRoot = $aggregateRoot;
     $this->event = $event;
     parent::__construct(sprintf('The data for `%s:%s` has changed, sequence at %s, expected %s.', $aggregateRoot->getType(), $aggregateRoot->getId(), $aggregateRoot->getLastSequence()));
 }
Пример #3
0
 /**
  * Events must originate from our root, so start from there.
  *
  * @param \Atrauzzi\PhpEventSourcing\Event $event
  */
 public function apply(Event $event)
 {
     $this->aggregateRoot->apply($event);
 }