/**
  * @param Contract $contract
  * @param DomainEvents $domainEvents
  * @return object
  */
 public function reconstitute(Contract $contract, DomainEvents $domainEvents)
 {
     // @todo A Contract shouldn't know about class names
     $className = $contract->toClassName();
     // @todo check if class exists and implements ReconstitutesFromHistory
     return $className::reconstituteFrom($domainEvents);
 }
예제 #2
0
 /**
  * @test
  * @dataProvider providePersistence
  * @param Persistence $persistence
  */
 public function it_should_disallow_tracking_AggregateRoots_twice(Persistence $persistence)
 {
     $unitOfWork = $this->buildUnitOfWork($persistence);
     $unitOfWork->track(Contract::with(Order::class), $this->orderId, $this->order);
     $this->setExpectedException(AggregateRootIsAlreadyBeingTracked::class);
     $unitOfWork->track(Contract::with(Order::class), $this->orderId, $this->order);
 }
 /**
  * @param Contract $streamContract
  * @param Identifier $streamId
  * @return EventEnvelope[]
  */
 public function fetch(Contract $streamContract, Identifier $streamId)
 {
     $records = $this->connection->fetchAll(Query\Select::from(self::TABLE_NAME), ['streamContract' => $streamContract, 'streamId' => $streamId]);
     $eventEnvelopes = array_map(function (array $record) {
         return EventEnvelope::reconstitute(EventId::fromString($record['eventId']), Contract::with($record['eventContract']), $record['eventPayload']);
     }, $records);
     return $eventEnvelopes;
 }
 /**
  * @test
  * @depends it_should_commit_and_fetch_events
  * @dataProvider providePersistence
  * @param Persistence $persistence
  */
 public function it_should_throw_when_events_have_been_committed_elsewhere(Persistence $persistence)
 {
     $commitId = CommitId::generate();
     $streamContract = Contract::with('My.Contract');
     $streamId = OrderId::generate();
     $eventEnvelope = EventEnvelope::wrap(EventId::generate(), Contract::with("My.SomethingHasHappened"), "My payload2");
     $this->setExpectedException(OptimisticConcurrencyFailed::class);
     $persistence->commit($commitId, $streamContract, $streamId, $expectedStreamVersion = 1, [$eventEnvelope]);
 }
 /**
  * @return Contract
  */
 private function getContract()
 {
     return Contract::canonicalFrom(Order::class);
 }
 /**
  * @param \EventCentric\DomainEvents\DomainEvent $domainEvent
  * @return \EventCentric\Contracts\Contract the contract
  */
 public function contractForDomainEvent(DomainEvent $domainEvent)
 {
     return Contract::canonicalFrom($domainEvent);
 }
예제 #7
0
 /**
  * Make a contract from an fully qualified class name, of the form My.Namespace.Class
  * @param object|string $object
  * @return Contract
  */
 public static function canonicalFrom($object)
 {
     return Contract::with(ClassFunctions::canonical($object));
 }
예제 #8
0
 /**
  * @param Contract $aggregateContract
  * @param Identifier $aggregateId
  * @return bool
  */
 public function isIdentifiedBy(Contract $aggregateContract, Identifier $aggregateId)
 {
     return $this->aggregateContract->equals($aggregateContract) && $this->aggregateId->equals($aggregateId);
 }
예제 #9
0
 public function equals(EventEnvelope $other)
 {
     return $this->eventId->equals($other->eventId) && $this->eventContract->equals($other->eventContract) && $this->eventPayload == $other->eventPayload;
 }