Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public static function deserialize(array $data) : QueryMessage
 {
     $keys = ['id', 'type', 'timestamp', 'meta_data', 'payload_type', 'payload'];
     foreach ($keys as $key) {
         if (!isset($data[$key])) {
             $message = sprintf('Invalid serialization data: %s', VarPrinter::toString($data));
             throw new DomainException($message);
         }
     }
     if ($data['type'] !== MessageType::QUERY) {
         $message = sprintf('Invalid message type: %s', $data['type']);
         throw new DomainException($message);
     }
     /** @var MessageId $id */
     $id = MessageId::fromString($data['id']);
     /** @var DateTime $timestamp */
     $timestamp = DateTime::fromString($data['timestamp']);
     /** @var MetaData $metaData */
     $metaData = MetaData::create($data['meta_data']);
     /** @var Type $payloadType */
     $payloadType = Type::create($data['payload_type']);
     /** @var string $payloadClass */
     $payloadClass = $payloadType->toClassName();
     assert(Validate::implementsInterface($payloadClass, Query::class), sprintf('Unable to deserialize: %s', $payloadClass));
     /** @var Query $payload */
     $payload = $payloadClass::fromArray($data['payload']);
     return new static($id, $timestamp, $payload, $metaData);
 }
Ejemplo n.º 2
0
 /**
  * Constructs CommandMessage
  *
  * @param MessageId $messageId The message ID
  * @param DateTime  $timestamp The timestamp
  * @param Command   $payload   The payload
  * @param MetaData  $metaData  The meta data
  */
 public function __construct(MessageId $messageId, DateTime $timestamp, Command $payload, MetaData $metaData)
 {
     $this->messageId = $messageId;
     $this->timestamp = $timestamp;
     $this->payload = $payload;
     $this->payloadType = Type::create($payload);
     $this->metaData = $metaData;
 }
Ejemplo n.º 3
0
 public function setUp()
 {
     $this->thingId = ThingId::fromString('014ec11d-2f21-4d33-a624-5df1196a4f85');
     $this->thingType = Type::create(Thing::class);
     $this->metaData = new MetaData(['ip_address' => '127.0.0.1']);
     $this->committed = 3;
     $this->version = 6;
 }
Ejemplo n.º 4
0
 /**
  * Constructs EventMessage
  *
  * @param Identifier  $aggregateId   The aggregate ID
  * @param Type        $aggregateType The aggregate type
  * @param MessageId   $messageId     The message ID
  * @param DateTime    $timestamp     The timestamp
  * @param DomainEvent $payload       The payload
  * @param MetaData    $metaData      The meta data
  * @param int         $sequence      The sequence number
  */
 public function __construct(Identifier $aggregateId, Type $aggregateType, MessageId $messageId, DateTime $timestamp, DomainEvent $payload, MetaData $metaData, $sequence)
 {
     $this->aggregateId = $aggregateId;
     $this->aggregateType = $aggregateType;
     $this->messageId = $messageId;
     $this->timestamp = $timestamp;
     $this->payload = $payload;
     $this->payloadType = Type::create($payload);
     $this->metaData = $metaData;
     $this->sequence = (int) $sequence;
 }
Ejemplo n.º 5
0
 public function setUp()
 {
     $thingId = ThingId::fromString('014ec11d-2f21-4d33-a624-5df1196a4f85');
     $thingType = Type::create(Thing::class);
     $messageId = MessageId::fromString('014ec11e-4343-49cd-9b7a-cdd4ced5cedc');
     $timestamp = DateTime::fromString('2015-01-01T13:12:31.045234[America/Chicago]');
     $payload = new ThingHappenedEvent('foo', 'bar');
     $metaData = new MetaData(['ip_address' => '127.0.0.1']);
     $sequence = 0;
     $this->eventMessage = new DomainEventMessage($thingId, $thingType, $messageId, $timestamp, $payload, $metaData, $sequence);
     $this->storedEvent = new StoredEvent($this->eventMessage);
 }
Ejemplo n.º 6
0
 public function test_that_event_is_dispatched_to_attached_service()
 {
     $dispatcher = $this->container->get('event.dispatcher');
     $dispatcher->attachService('test.subscriber', TestSubscriber::class);
     $dispatcher = new FrozenDispatcher($dispatcher);
     $thingId = ThingId::fromString('014ec11d-2f21-4d33-a624-5df1196a4f85');
     $thingType = Type::create(Thing::class);
     $messageId = MessageId::fromString('014ec11e-4343-49cd-9b7a-cdd4ced5cedc');
     $timestamp = DateTime::fromString('2015-01-01T13:12:31.045234[America/Chicago]');
     $payload = new ThingHappenedEvent('foo', 'bar');
     $metaData = new MetaData();
     $sequence = 0;
     $eventMessage = new DomainEventMessage($thingId, $thingType, $messageId, $timestamp, $payload, $metaData, $sequence);
     $dispatcher->dispatch($eventMessage);
     $this->assertTrue($this->container->get('test.subscriber')->thingHappened());
 }
Ejemplo n.º 7
0
 public function test_that_all_events_key_subscribes_to_any_event()
 {
     $subscriber = new EventLogSubscriber();
     $this->dispatcher->attach($subscriber);
     $thingId = ThingId::fromString('014ec11d-2f21-4d33-a624-5df1196a4f85');
     $thingType = Type::create(Thing::class);
     $messageId = MessageId::fromString('014ec11e-4343-49cd-9b7a-cdd4ced5cedc');
     $timestamp = DateTime::fromString('2015-01-01T13:12:31.045234[America/Chicago]');
     $payload = new ThingHappenedEvent('foo', 'bar');
     $metaData = new MetaData();
     $sequence = 0;
     $eventMessage = new DomainEventMessage($thingId, $thingType, $messageId, $timestamp, $payload, $metaData, $sequence);
     $this->dispatcher->dispatch($eventMessage);
     $logs = $subscriber->getLogs();
     $expected = '{"message_id":"014ec11e-4343-49cd-9b7a-cdd4ced5cedc",' . '"timestamp":"2015-01-01T13:12:31.045234[America/Chicago]",' . '"event_type":"Novuso.Test.Common.Doubles.Domain.Messaging.Event.ThingHappenedEvent",' . '"event_data":{"foo":"foo","bar":"bar"},"meta_data":[],' . '"aggregate_type":"Novuso.Test.Common.Doubles.Domain.Model.Thing",' . '"aggregate_id":"014ec11d-2f21-4d33-a624-5df1196a4f85","sequence":0}';
     $this->assertSame($expected, $logs[0]);
 }
Ejemplo n.º 8
0
 /**
  * Retrieves the event collection
  *
  * @return EventCollection
  */
 protected function eventCollection()
 {
     if ($this->eventCollection === null) {
         $this->eventCollection = new EventCollection($this->id(), Type::create($this));
     }
     return $this->eventCollection;
 }
Ejemplo n.º 9
0
 public function test_that_hash_value_returns_expected_string()
 {
     $type = Type::create($this);
     $expected = str_replace('\\', '.', get_class($this));
     $this->assertSame($expected, $type->hashValue());
 }
 /**
  * Checks if a responder is defined for an action
  *
  * @param string $actionClass The full action class name
  *
  * @return bool
  */
 public function hasResponder($actionClass)
 {
     $type = Type::create($actionClass)->toString();
     if (!isset($this->responders[$type])) {
         return false;
     }
     $serviceId = $this->responders[$type];
     return $this->container->has($serviceId);
 }
Ejemplo n.º 11
0
 /**
  * Creates a view for the current request
  *
  * @param mixed $data       The domain data
  * @param array $parameters Additional parameters
  *
  * @return View
  */
 protected function view($data = null, array $parameters = [])
 {
     $action = Type::create($this);
     return new View($this->request, $action, $data, $parameters);
 }
Ejemplo n.º 12
0
 /**
  * @expectedException Novuso\Common\Domain\EventStore\Exception\StreamNotFoundException
  */
 public function test_that_load_stream_throws_exception_when_id_does_not_have_a_stream()
 {
     $task = Task::create('First task description');
     $stream = $task->getRecordedEvents();
     $this->store->appendStream($stream);
     $task->clearRecordedEvents();
     $other = Task::create('Another task');
     $this->store->loadStream($other->id(), Type::create($other));
 }
 /**
  * Checks if a responder is defined for an action
  *
  * @param string $actionClass The full action class name
  *
  * @return bool
  */
 public function hasResponder($actionClass)
 {
     $type = Type::create($actionClass)->toString();
     return isset($this->responders[$type]);
 }
Ejemplo n.º 14
0
 /**
  * Converts data to an event message
  *
  * @return EventMessage
  */
 public function toEventMessage()
 {
     $aggregateIdClass = Type::create($this->aggregateIdType)->toClassName();
     $aggregateId = $aggregateIdClass::fromString($this->aggregateId);
     $aggregateType = Type::create($this->aggregateType);
     $messageId = MessageId::fromString($this->messageId);
     $timestamp = DateTime::fromString($this->timestamp);
     $payload = unserialize($this->payload);
     $metaData = unserialize($this->metaData);
     $sequence = $this->sequence;
     $message = new DomainEventMessage($aggregateId, $aggregateType, $messageId, $timestamp, $payload, $metaData, $sequence);
     return $message;
 }
Ejemplo n.º 15
0
 /**
  * {@inheritdoc}
  */
 public function hasStream(Identifier $aggregateId, Type $aggregateType)
 {
     $id = $aggregateId->toString();
     $type = $aggregateType->toString();
     if (!isset($this->streamData[$type])) {
         return false;
     }
     if (!isset($this->streamData[$type][$id])) {
         return false;
     }
     return true;
 }
Ejemplo n.º 16
0
 protected function getNextEvent()
 {
     $thingId = ThingId::fromString('014ec11d-2f21-4d33-a624-5df1196a4f85');
     $thingType = Type::create(Thing::class);
     $messageId = MessageId::fromString('014ec11f-317e-475a-9d5f-b8ae6c20aab1');
     $timestamp = DateTime::fromString('2015-01-02T10:34:12.672291[America/Chicago]');
     $metaData = new MetaData();
     $payload = new ThingHappenedEvent('foo', 'bar');
     $sequence = 1;
     return new DomainEventMessage($thingId, $thingType, $messageId, $timestamp, $payload, $metaData, $sequence);
 }
Ejemplo n.º 17
0
 /**
  * Checks if a handler is defined for a query
  *
  * @param string $queryClass The full query class name
  *
  * @return bool
  */
 public function hasHandler($queryClass)
 {
     $type = Type::create($queryClass)->toString();
     return isset($this->handlers[$type]);
 }
Ejemplo n.º 18
0
 /**
  * Checks if a handler is defined for a command
  *
  * @param string $commandClass The full command class name
  *
  * @return bool
  */
 public function hasHandler($commandClass)
 {
     $type = Type::create($commandClass)->toString();
     if (!isset($this->handlers[$type])) {
         return false;
     }
     $serviceId = $this->handlers[$type];
     return $this->container->has($serviceId);
 }
Ejemplo n.º 19
0
 /**
  * Checks if a handler is defined for a command
  *
  * @param string $commandClass The full command class name
  *
  * @return bool
  */
 public function hasHandler(string $commandClass) : bool
 {
     $type = Type::create($commandClass)->toString();
     return isset($this->handlers[$type]);
 }
Ejemplo n.º 20
0
 public function setUp()
 {
     $thingId = ThingId::fromString('014ec11d-2f21-4d33-a624-5df1196a4f85');
     $thingType = Type::create(Thing::class);
     $this->eventCollection = new EventCollection($thingId, $thingType);
 }
Ejemplo n.º 21
0
 /**
  * Checks if a handler is defined for a query
  *
  * @param string $queryClass The full query class name
  *
  * @return bool
  */
 public function hasHandler(string $queryClass) : bool
 {
     $type = Type::create($queryClass)->toString();
     if (!isset($this->handlers[$type])) {
         return false;
     }
     $service = $this->handlers[$type];
     return $this->container->has($service);
 }
Ejemplo n.º 22
0
 /**
  * {@inheritdoc}
  */
 public function toArray() : array
 {
     return ['id' => $this->id->toString(), 'type' => $this->type->value(), 'timestamp' => $this->timestamp->toString(), 'meta_data' => $this->metaData->toArray(), 'payload_type' => $this->payloadType->toString(), 'payload' => $this->payload->toArray()];
 }