From 7a3fa20e012481bd99784517da179bb3408e56ce Mon Sep 17 00:00:00 2001 From: Italo Lelis de Vietro Date: Tue, 28 Jun 2016 00:44:09 +0200 Subject: [PATCH] Changed to new version --- src/CommandBus/TacticianCommandBus.php | 4 ---- src/Domain/EventStream.php | 4 ++-- src/EventBus/SimpleEventBus.php | 4 ++-- src/EventDispatcher/InMemoryDispatcher.php | 9 +++++---- .../AggregateRepositoryFactory.php | 12 ++++++------ src/EventStore/Adapter/InMemoryAdapter.php | 19 ++++++++++--------- .../Adapter/InMemorySnapshotAdapter.php | 9 +++++---- src/Serializer/README.md | 2 +- tests/EventStore/EventStoreTest.php | 2 +- tests/EventStore/InMemoryEventStoreTest.php | 2 +- tests/EventStore/RedisEventStore.php | 4 ++-- tests/EventStoreIntegrationTest.php | 4 ++-- 12 files changed, 37 insertions(+), 38 deletions(-) diff --git a/src/CommandBus/TacticianCommandBus.php b/src/CommandBus/TacticianCommandBus.php index d0ee58b..ee1e468 100644 --- a/src/CommandBus/TacticianCommandBus.php +++ b/src/CommandBus/TacticianCommandBus.php @@ -2,10 +2,6 @@ namespace HelloFresh\Engine\CommandBus; -use Assert\Assertion; -use Collections\Dictionary; -use Collections\MapInterface; -use Collections\Queue; use League\Tactician\CommandBus; class TacticianCommandBus implements CommandBusInterface diff --git a/src/Domain/EventStream.php b/src/Domain/EventStream.php index cad602a..46b61a0 100644 --- a/src/Domain/EventStream.php +++ b/src/Domain/EventStream.php @@ -2,9 +2,9 @@ namespace HelloFresh\Engine\Domain; -use Collections\Immutable\ImmArrayList; +use Collections\Immutable\ImmVector; -class EventStream extends ImmArrayList +class EventStream extends ImmVector { /** * @var StreamName diff --git a/src/EventBus/SimpleEventBus.php b/src/EventBus/SimpleEventBus.php index 861ff7e..6567666 100644 --- a/src/EventBus/SimpleEventBus.php +++ b/src/EventBus/SimpleEventBus.php @@ -2,7 +2,7 @@ namespace HelloFresh\Engine\EventBus; -use Collections\ArrayList; +use Collections\Vector; use Collections\Queue; use Collections\VectorInterface; use HelloFresh\Engine\Domain\DomainEventInterface; @@ -32,7 +32,7 @@ class SimpleEventBus implements EventBusInterface */ public function __construct() { - $this->eventListeners = new ArrayList(); + $this->eventListeners = new Vector(); $this->queue = new Queue(); } diff --git a/src/EventDispatcher/InMemoryDispatcher.php b/src/EventDispatcher/InMemoryDispatcher.php index 9e70b87..b008f48 100644 --- a/src/EventDispatcher/InMemoryDispatcher.php +++ b/src/EventDispatcher/InMemoryDispatcher.php @@ -2,9 +2,10 @@ namespace HelloFresh\Engine\EventDispatcher; -use Collections\ArrayList; -use Collections\Dictionary; +use Collections\Map; use Collections\MapInterface; +use Collections\Pair; +use Collections\Vector; /** * In Memory Event dispatcher implementation. @@ -21,7 +22,7 @@ class InMemoryDispatcher implements EventDispatcherInterface, EventListenerInter */ public function __construct() { - $this->listeners = new Dictionary(); + $this->listeners = new Map(); } /** @@ -44,7 +45,7 @@ public function dispatch($eventName, ...$arguments) public function addListener($eventName, callable $callable) { if (!$this->listeners->containsKey($eventName)) { - $this->listeners->add($eventName, new ArrayList()); + $this->listeners->add(new Pair($eventName, new Vector())); } $this->listeners->get($eventName)->add($callable); diff --git a/src/EventSourcing/AggregateRepositoryFactory.php b/src/EventSourcing/AggregateRepositoryFactory.php index 456ff4d..f3451ea 100644 --- a/src/EventSourcing/AggregateRepositoryFactory.php +++ b/src/EventSourcing/AggregateRepositoryFactory.php @@ -2,7 +2,7 @@ namespace HelloFresh\Engine\EventSourcing; -use Collections\Dictionary; +use Collections\Map; use Collections\MapInterface; use HelloFresh\Engine\EventBus\SimpleEventBus; use HelloFresh\Engine\EventStore\Adapter\InMemoryAdapter; @@ -26,10 +26,10 @@ class AggregateRepositoryFactory implements AggregateRepositoryFactoryInterface public function __construct($config = null) { if (!$config instanceof MapInterface) { - $config = new Dictionary($config); + $config = new Map($config); } - $this->config = new Dictionary([ + $this->config = new Map([ 'event_bus' => [ 'service' => new SimpleEventBus() ], @@ -74,7 +74,7 @@ public function build() private function configureEventStore(MapInterface $config) { $adapterName = $config->get('adapter'); - $arguments = $config->tryGet('arguments', []); + $arguments = $config->get('arguments') ? $config->get('arguments') : []; $adapter = new $adapterName(...$arguments); @@ -84,7 +84,7 @@ private function configureEventStore(MapInterface $config) private function configureSnapshotStore(MapInterface $config) { $adapterName = $config->get('adapter'); - $arguments = $config->tryGet('arguments', []); + $arguments = $config->get('arguments') ? $config->get('arguments') : []; $adapter = new $adapterName(...$arguments); @@ -94,7 +94,7 @@ private function configureSnapshotStore(MapInterface $config) private function configureSnapshotStrategy(MapInterface $config) { $adapterName = $config->get('name'); - $arguments = $config->tryGet('arguments', []); + $arguments = $config->get('arguments') ? $config->get('arguments') : []; return new $adapterName(...$arguments); } diff --git a/src/EventStore/Adapter/InMemoryAdapter.php b/src/EventStore/Adapter/InMemoryAdapter.php index a548100..ee00178 100644 --- a/src/EventStore/Adapter/InMemoryAdapter.php +++ b/src/EventStore/Adapter/InMemoryAdapter.php @@ -2,9 +2,10 @@ namespace HelloFresh\Engine\EventStore\Adapter; -use Collections\ArrayList; -use Collections\Dictionary; +use Collections\Map; use Collections\MapInterface; +use Collections\Pair; +use Collections\Vector; use Collections\VectorInterface; use HelloFresh\Engine\Domain\AggregateIdInterface; use HelloFresh\Engine\Domain\DomainMessage; @@ -20,22 +21,22 @@ class InMemoryAdapter implements EventStoreAdapterInterface public function __construct() { - $this->events = new Dictionary(); + $this->events = new Map(); } public function save(StreamName $streamName, DomainMessage $event) { $id = (string)$event->getId(); $name = (string)$streamName; - $events = $this->events->tryGet($name); + $events = $this->events->get($name); - if (!$events) { - $events = new Dictionary(); - $this->events->add($name, $events); + if (null === $events) { + $events = new Map(); + $this->events->add(new Pair($name, $events)); } if (!$events->containsKey($id)) { - $events->add($id, new ArrayList()); + $events->add(new Pair($id, new Vector())); } $events->get($id)->add($event); @@ -47,7 +48,7 @@ public function getEventsFor(StreamName $streamName, $id) $name = (string)$streamName; /** @var MapInterface $events */ try { - $events = $this->events->get($name); + $events = $this->events->at($name); } catch (\OutOfBoundsException $e) { throw new EventStreamNotFoundException("Stream $name not found", $e->getCode(), $e); } diff --git a/src/EventStore/Snapshot/Adapter/InMemorySnapshotAdapter.php b/src/EventStore/Snapshot/Adapter/InMemorySnapshotAdapter.php index 9ac198d..be038bc 100644 --- a/src/EventStore/Snapshot/Adapter/InMemorySnapshotAdapter.php +++ b/src/EventStore/Snapshot/Adapter/InMemorySnapshotAdapter.php @@ -2,8 +2,9 @@ namespace HelloFresh\Engine\EventStore\Snapshot\Adapter; -use Collections\Dictionary; +use Collections\Map; use Collections\MapInterface; +use Collections\Pair; use HelloFresh\Engine\Domain\AggregateIdInterface; use HelloFresh\Engine\EventStore\Snapshot\Snapshot; @@ -16,17 +17,17 @@ class InMemorySnapshotAdapter implements SnapshotStoreAdapterInterface public function __construct() { - $this->snapshots = new Dictionary(); + $this->snapshots = new Map(); } public function byId(AggregateIdInterface $id) { - return $this->snapshots->tryGet((string)$id); + return $this->snapshots->get((string)$id); } public function save(Snapshot $snapshot) { - $this->snapshots->add((string)$snapshot->getAggregateId(), $snapshot); + $this->snapshots->add(new Pair((string)$snapshot->getAggregateId(), $snapshot)); } public function has(AggregateIdInterface $id, $version) diff --git a/src/Serializer/README.md b/src/Serializer/README.md index 2f50253..b541480 100644 --- a/src/Serializer/README.md +++ b/src/Serializer/README.md @@ -21,7 +21,7 @@ use HelloFresh\Engine\Serializer\Adapter\JmsSerializerAdapter; $jmsSerializer = SerializerBuilder::create() ->setMetadataDirs(['' => __DIR__ . '/metadata']) ->configureHandlers(function (HandlerRegistry $registry) { - $registry->registerSubscribingHandler(new ArrayListHandler()); + $registry->registerSubscribingHandler(new VectorHandler()); $registry->registerSubscribingHandler(new UuidSerializerHandler()); }) ->addDefaultHandlers() diff --git a/tests/EventStore/EventStoreTest.php b/tests/EventStore/EventStoreTest.php index 6325ad0..8a9f87a 100644 --- a/tests/EventStore/EventStoreTest.php +++ b/tests/EventStore/EventStoreTest.php @@ -1,6 +1,6 @@ setMetadataDirs(['' => realpath(__DIR__ . '/../Mock/Config')]) ->configureHandlers(function (HandlerRegistry $registry) { - $registry->registerSubscribingHandler(new ArrayListHandler()); + $registry->registerSubscribingHandler(new VectorHandler()); $registry->registerSubscribingHandler(new UuidSerializerHandler()); }) ->addDefaultHandlers() diff --git a/tests/EventStoreIntegrationTest.php b/tests/EventStoreIntegrationTest.php index 9d9b6d7..fdf3269 100644 --- a/tests/EventStoreIntegrationTest.php +++ b/tests/EventStoreIntegrationTest.php @@ -23,7 +23,7 @@ use HelloFresh\Engine\EventStore\Snapshot\Snapshotter; use HelloFresh\Engine\EventStore\Snapshot\Strategy\CountSnapshotStrategy; use HelloFresh\Engine\Serializer\Adapter\JmsSerializerAdapter; -use HelloFresh\Engine\Serializer\Type\ArrayListHandler; +use HelloFresh\Engine\Serializer\Type\VectorHandler; use HelloFresh\Engine\Serializer\Type\UuidSerializerHandler; use HelloFresh\Tests\Engine\Mock\AggregateRoot; use HelloFresh\Tests\Engine\Mock\AssignNameCommand; @@ -116,7 +116,7 @@ private function configureSerializer() $jmsSerializer = SerializerBuilder::create() ->setMetadataDirs(['' => realpath(__DIR__ . '/Mock/Config')]) ->configureHandlers(function (HandlerRegistry $registry) { - $registry->registerSubscribingHandler(new ArrayListHandler()); + $registry->registerSubscribingHandler(new VectorHandler()); $registry->registerSubscribingHandler(new UuidSerializerHandler()); }) ->addDefaultHandlers()