Skip to content
This repository has been archived by the owner on Mar 1, 2024. It is now read-only.

Commit

Permalink
Changed to new version
Browse files Browse the repository at this point in the history
  • Loading branch information
italolelis committed Jun 27, 2016
1 parent 93c0e70 commit 7a3fa20
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 38 deletions.
4 changes: 0 additions & 4 deletions src/CommandBus/TacticianCommandBus.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/Domain/EventStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/EventBus/SimpleEventBus.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -32,7 +32,7 @@ class SimpleEventBus implements EventBusInterface
*/
public function __construct()
{
$this->eventListeners = new ArrayList();
$this->eventListeners = new Vector();
$this->queue = new Queue();
}

Expand Down
9 changes: 5 additions & 4 deletions src/EventDispatcher/InMemoryDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -21,7 +22,7 @@ class InMemoryDispatcher implements EventDispatcherInterface, EventListenerInter
*/
public function __construct()
{
$this->listeners = new Dictionary();
$this->listeners = new Map();
}

/**
Expand All @@ -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);
Expand Down
12 changes: 6 additions & 6 deletions src/EventSourcing/AggregateRepositoryFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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()
],
Expand Down Expand Up @@ -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);

Expand All @@ -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);

Expand All @@ -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);
}
Expand Down
19 changes: 10 additions & 9 deletions src/EventStore/Adapter/InMemoryAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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);
}
Expand Down
9 changes: 5 additions & 4 deletions src/EventStore/Snapshot/Adapter/InMemorySnapshotAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/Serializer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion tests/EventStore/EventStoreTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace HelloFresh\Tests\Engine\EventSourcing;
namespace HelloFresh\Tests\Engine\EventStore;

use HelloFresh\Engine\Domain\AggregateId;
use HelloFresh\Engine\Domain\DomainMessage;
Expand Down
2 changes: 1 addition & 1 deletion tests/EventStore/InMemoryEventStoreTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace HelloFresh\Tests\Engine\EventSourcing;
namespace HelloFresh\Tests\Engine\EventStore;

use HelloFresh\Engine\EventStore\Adapter\InMemoryAdapter;
use HelloFresh\Engine\EventStore\EventStore;
Expand Down
4 changes: 2 additions & 2 deletions tests/EventStore/RedisEventStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use HelloFresh\Engine\EventStore\Adapter\RedisAdapter;
use HelloFresh\Engine\EventStore\EventStore;
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 JMS\Serializer\Handler\HandlerRegistry;
use JMS\Serializer\SerializerBuilder;
Expand Down Expand Up @@ -43,7 +43,7 @@ private function setUpSerializer()
$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()
Expand Down
4 changes: 2 additions & 2 deletions tests/EventStoreIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 7a3fa20

Please sign in to comment.