コード例 #1
0
ファイル: DateTimeFactory.php プロジェクト: pauci/datetime
 /**
  * @param string $format
  * @param string $time
  * @param DateTimeZone|null $timezone
  * @return DateTime
  * @throws \InvalidArgumentException
  */
 public function fromFormat($format, $time, DateTimeZone $timezone = null)
 {
     $dateTime = $timezone !== null ? \DateTime::createFromFormat($format, $time, $timezone) : \DateTime::createFromFormat($format, $time);
     if (!$dateTime) {
         throw new \InvalidArgumentException(sprintf('Failed to parse time string "%s" formatted as "%s"', $time, $format));
     }
     return $this->fromDateTime($dateTime);
 }
コード例 #2
0
 public function testReconstructUsingExistingData()
 {
     $metadata = Metadata::from(['foo' => 'bar']);
     $id = Uuid::uuid4();
     $timestamp = DateTime::microsecondsNow();
     $eventMessage = new GenericEventMessage(new SomePayload(), $metadata, $id, $timestamp);
     $this->assertSame($timestamp, $eventMessage->getTimestamp());
     $this->assertSame($id, $eventMessage->getId());
     $this->assertSame($metadata, $eventMessage->getMetadata());
 }
コード例 #3
0
ファイル: DateType.php プロジェクト: pauci/datetime-doctrine
 public function convertToPHPValue($value, AbstractPlatform $platform)
 {
     if ($value === null || $value instanceof DateTime) {
         return $value;
     }
     $val = DateTime::createFromFormat('!' . $platform->getDateFormatString(), $value);
     if (!$val) {
         throw ConversionException::conversionFailedFormat($value, $this->getName(), $platform->getDateFormatString());
     }
     return $val;
 }
コード例 #4
0
ファイル: GuzzleApiEventStore.php プロジェクト: pauci/cqrs
 /**
  * @param array $data
  * @return GenericDomainEventMessage|GenericEventMessage
  */
 public function fromArray(array $data)
 {
     $payload = $this->serializer->deserialize(json_encode($data['payload']), $data['payloadType']);
     /** @var Metadata $metadata */
     $metadata = $this->serializer->deserialize(json_encode($data['metadata']), Metadata::class);
     $id = Uuid::fromString($data['id']);
     $timestamp = DateTime::fromString("{$data['timestamp']}");
     if (array_key_exists('aggregateType', $data)) {
         return new GenericDomainEventMessage($data['aggregateType'], $data['aggregateId'], 0, $payload, $metadata, $id, $timestamp);
     }
     return new GenericEventMessage($data['payload'], $data['metadata'], $id, $timestamp);
 }
コード例 #5
0
ファイル: RedisEventRecord.php プロジェクト: pauci/cqrs
 /**
  * @param SerializerInterface $serializer
  * @return GenericDomainEventMessage|GenericEventMessage
  */
 public function toMessage(SerializerInterface $serializer)
 {
     $data = $this->toArray();
     $id = Uuid::fromString($data['id']);
     $timestamp = DateTime::fromString($data['timestamp']);
     $payload = $serializer->deserialize($data['payload'], $data['payload_type']);
     $metadata = $serializer->deserialize($data['metadata'], Metadata::class);
     if (array_key_exists('aggregate', $data)) {
         return new GenericDomainEventMessage($data['aggregate']['type'], $data['aggregate']['id'], $data['aggregate']['seq'], $payload, $metadata, $id, $timestamp);
     }
     return new GenericEventMessage($payload, $metadata, $id, $timestamp);
 }
コード例 #6
0
 public function testGetAll()
 {
     $timestamp = DateTime::fromString('2016-01-26T16:25:32.225809+00:00');
     $messages = [];
     for ($i = 0; $i < 15; $i++) {
         $eventId = Uuid::fromString('4e95d633-7ffb-448e-8925-2d02996057a' . dechex($i));
         $messages[] = new GenericEventMessage(null, null, $eventId, $timestamp);
     }
     $eventStore = $this->createMock('CQRS\\EventStore\\EventStoreInterface');
     $eventStore->expects($this->once())->method('iterate')->willReturn($messages);
     $this->getApplicationServiceLocator()->setService('cqrs.event_store.cqrs_default', $eventStore);
     $this->dispatch('/cqrs/notifications');
     $this->assertResponseStatusCode(200);
     $this->assertModuleName('CQRSModule');
     $this->assertControllerName('CQRSModule\\Controller\\NotificationController');
     $this->assertControllerClass('NotificationController');
     $this->assertMatchedRouteName('cqrs/notifications');
     $result = json_decode($this->getResponse()->getContent(), true);
     $events = array_map(function ($i) {
         return ['id' => '4e95d633-7ffb-448e-8925-2d02996057a' . $i, 'payloadType' => 'CQRS\\Domain\\Message\\GenericMessage', 'payload' => null, 'metadata' => [], 'timestamp' => '2016-01-26T16:25:32.225809+00:00'];
     }, range(0, 9));
     $this->assertEquals(['_links' => ['self' => '/cqrs/notifications', 'next' => '/cqrs/notifications?previousEventId=4e95d633-7ffb-448e-8925-2d02996057a9'], 'count' => 10, '_embedded' => ['event' => $events]], $result);
 }
コード例 #7
0
ファイル: GenericEventMessage.php プロジェクト: pauci/cqrs
 /**
  * @param mixed $payload
  * @param Metadata|array|null $metadata
  * @param UuidInterface|null $id
  * @param DateTimeInterface|null $timestamp
  */
 public function __construct($payload, $metadata = null, UuidInterface $id = null, DateTimeInterface $timestamp = null)
 {
     parent::__construct($payload, $metadata, $id);
     $this->timestamp = $timestamp ?: DateTime::microsecondsNow();
 }
コード例 #8
0
ファイル: RedisEventStoreTest.php プロジェクト: pauci/cqrs
 public function getData()
 {
     $aggregateId = 123;
     return [[new GenericEventMessage(new SomeEvent(), null, Uuid::fromString('777bb61d-b9fa-4023-937e-1b6e4fc9f7b4'), DateTime::fromString('2015-02-11T15:23:42.195819+0100')), '{"id":"777bb61d-b9fa-4023-937e-1b6e4fc9f7b4","timestamp":"2015-02-11T15:23:42.195819+01:00","payload_type":"CQRSTest\\\\EventStore\\\\SomeEvent","payload":"{}","metadata":"{}"}'], [new GenericDomainEventMessage('SomeAggregate', $aggregateId, 4, new SomeEvent(), null, Uuid::fromString('eabd641e-4181-4b5f-b191-ecdd40d82b1b'), DateTime::fromString('2015-02-11T13:40:29.658819+0100')), '{"id":"eabd641e-4181-4b5f-b191-ecdd40d82b1b","timestamp":"2015-02-11T13:40:29.658819+01:00","payload_type":"CQRSTest\\\\EventStore\\\\SomeEvent","payload":"{}","metadata":"{}","aggregate":{"type":"SomeAggregate","id":123,"seq":4}}']];
 }
コード例 #9
0
ファイル: TableEventStore.php プロジェクト: pauci/cqrs
 /**
  * @param array $data
  * @return GenericDomainEventMessage|GenericEventMessage
  */
 public function fromArray(array $data)
 {
     $payload = $this->serializer->deserialize($data['payload'], $data['payload_type']);
     /** @var Metadata $metadata */
     $metadata = $this->serializer->deserialize($data['metadata'], Metadata::class);
     $id = Uuid::fromString($data['event_id']);
     $timestamp = DateTime::fromString("{$data['event_date']}.{$data['event_date_u']}");
     if (array_key_exists('aggregate_type', $data)) {
         return new GenericDomainEventMessage($data['aggregate_type'], $data['aggregate_id'], $data['sequence_number'], $payload, $metadata, $id, $timestamp);
     }
     return new GenericEventMessage($payload, $metadata, $id, $timestamp);
 }
コード例 #10
0
ファイル: DateTimeTest.php プロジェクト: pauci/datetime
 public function testSerialize()
 {
     $dateTime = DateTime::now();
     $serialized = serialize($dateTime);
     $unserializedDateTime = unserialize($serialized);
     self::assertEquals($dateTime, $unserializedDateTime);
     self::assertEquals($dateTime->getTimezone(), $unserializedDateTime->getTimezone());
 }