/** * {@inheritdoc} */ public function getSnapshot(UuidInterface $id) { if (!isset($this->snapshots[$id->toString()])) { return null; } return $this->snapshots[$id->toString()]; }
/** * {@inheritdoc} */ public function getCommittedEventStream(UuidInterface $id, $version = 0) { $eventStream = new EventStream($id); if (isset($this->committedEvents[$id->toString()])) { foreach ($this->committedEvents[$id->toString()] as $event) { $eventStream->push($event); } } return $eventStream; }
/** * @param UuidInterface $id * @param int $amount * @param Product $product */ public function __construct(UuidInterface $id, $amount, Product $product) { Assertion::uuid($id->toString()); Assertion::integer($amount); Assertion::notEmpty($product); $this->id = $id; $this->amount = $amount; $this->product = $product; }
/** * {@inheritdoc} */ public function getSnapshot(UuidInterface $id) { try { $cursor = $this->client->selectCollection($this->options->getDatabase(), $id->toString())->find()->sort(['$natural' => -1])->limit(1); } catch (\Exception $e) { throw new EventStoreException(__METHOD__ . ' : ' . $e->getMessage()); } $snapshot = $cursor->current(); if (!isset($snapshot)) { return null; } $eventProvider = $this->serializer->deserialize($snapshot['memento']['data'], $snapshot['memento']['type'], 'json'); return $eventProvider; }
/** * {@inheritdoc} */ public function getCommittedEventStream(UuidInterface $id, $version = 0) { if (0 < $version) { $query = ['version' => ['$gte' => $version]]; } else { $query = []; } try { $cursor = $this->connection->selectCollection($this->options->getDatabase(), $id->toString())->find($query); } catch (\Exception $e) { throw new EventStoreException(__METHOD__ . ' : ' . $e->getMessage()); } $eventStream = new EventStream($id); foreach ($cursor as $document) { /** @var Event $event */ $event = $this->serializer->deserialize($document['data']['payload'], $document['data']['type'], 'json'); $eventStream->push($event); } return $eventStream; }
/** * @param null|UuidInterface $previousEventId * @return Generator */ public function iterate(UuidInterface $previousEventId = null) { $id = $previousEventId ? $previousEventId->toString() : null; while (true) { $response = $this->getFromApi($id, $this->requestLimit); $events = $response ? $response['_embedded']['event'] : null; if (!$events) { break; } $lastId = false; foreach ($events as $event) { $lastId = $event['id']; (yield $this->fromArray($event)); } if ($response['count'] < $this->requestLimit || !$lastId) { break; } $id = $lastId; } }
/** * @param UuidInterface $id * @param int $type * @param string $street * @param string $streetNumber * @param string $postalCode * @param string $city * @param string $state * @param string $country * @param string $phone */ public function __construct(UuidInterface $id, $type, $street, $streetNumber, $postalCode, $city, $state, $country, $phone) { Assertion::uuid($id->toString()); Assertion::choice($type, [self::TYPE_BILLING, self::TYPE_SHIPPING]); Assertion::notEmpty($street); Assertion::notEmpty($streetNumber); Assertion::notEmpty($postalCode); Assertion::notEmpty($city); Assertion::notEmpty($state); Assertion::notEmpty($country); Assertion::notEmpty($phone); $this->id = $id; $this->type = $type; $this->street = $street; $this->streetNumber = $streetNumber; $this->postalCode = $postalCode; $this->city = $city; $this->state = $state; $this->country = $country; $this->phone = $phone; }
/** * Returns the UUID serialized for JSON. * * @param JsonSerializationVisitor $visitor The serialization visitor. * @param UuidInterface $uuid The UUID to serialize. * @param array $type The type information. * @param Context $context The serialization context. * * @return string The serialized UUID. */ public static function toJson(JsonSerializationVisitor $visitor, UuidInterface $uuid, array $type, Context $context) { return $uuid->toString(); }
/** * This is what gets saved to data stores. * * @return string */ public function __toString() { return $this->value->toString(); }
/** * {@inheritdoc} */ public function toString() { return $this->uuid->toString(); }
/** * {@inheritdoc} */ public function set(UuidInterface $id, EventStream $eventStream) { $this->eventStreams[$id->toString()] = $eventStream; }
/** * @param UuidInterface $id * @return null|Cart */ public function getCart(UuidInterface $id) { return isset($this->carts[$id->toString()]) ? $this->carts[$id->toString()] : null; }
/** * @return string */ public function getId() : string { return $this->id->toString(); }
public function __toString() { return $this->id->toString(); }
/** * @param UuidInterface $id * @return null|CartEntry */ public function getEntry(UuidInterface $id) { return isset($this->entries[$id->toString()]) ? $this->entries[$id->toString()] : null; }
/** * {@inheritdoc} */ public function isEqualTo(ValueObject $object) : bool { return $object instanceof TicketTypeId && $object->toString() === $this->id->toString(); }
/** * @param string $msgType * @return array */ private function createHeader($msgType) { return ['date' => (new \DateTime('NOW'))->format('c'), 'msg_id' => Uuid::uuid4()->toString(), 'username' => "kernel", 'session' => $this->sesssionId->toString(), 'msg_type' => $msgType]; }
/** @return resource */ private function getFileStream(UuidInterface $fileUuid) { $stream = $this->fileSystem->readStream($fileUuid->toString()); if (!$stream) { throw new \RuntimeException('Could not retrieve stream for file.'); } return $stream; }
/** * @return string */ public function toString() : string { return $this->value->toString(); }
/** * @param \JMS\Serializer\VisitorInterface $visitor * @param \Ramsey\Uuid\UuidInterface $uuid * @param mixed[] $type * @param \JMS\Serializer\Context $context * @return string */ public function serializeUuid(VisitorInterface $visitor, UuidInterface $uuid, array $type, Context $context) { return $visitor->visitString($uuid->toString(), $type, $context); }
/** * @return string */ public function toString() { return $this->ramseyUuid->toString(); }