Skip to content

Commit

Permalink
Merge pull request #101 from proophsoftware/feature/event_machine_int…
Browse files Browse the repository at this point in the history
…erfaces

Add interfaces to avoid typehinting Event Machine at runtime
  • Loading branch information
codeliner authored Jul 31, 2018
2 parents 61c3ba1 + 72cf114 commit bd233e0
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/EventMachine.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
use Prooph\EventMachine\JsonSchema\Type\EnumType;
use Prooph\EventMachine\JsonSchema\Type\ObjectType;
use Prooph\EventMachine\Messaging\GenericJsonSchemaMessageFactory;
use Prooph\EventMachine\Messaging\MessageDispatcher;
use Prooph\EventMachine\Persistence\AggregateStateStore;
use Prooph\EventMachine\Persistence\Stream;
use Prooph\EventMachine\Persistence\TransactionManager as BusTransactionManager;
use Prooph\EventMachine\Projecting\ProjectionDescription;
Expand All @@ -58,7 +60,7 @@
use React\Promise\Promise;
use ReflectionClass;

final class EventMachine
final class EventMachine implements MessageDispatcher, AggregateStateStore
{
const ENV_PROD = 'prod';
const ENV_DEV = 'dev';
Expand Down Expand Up @@ -498,9 +500,7 @@ public function bootstrap(string $env = self::ENV_PROD, $debugMode = false): sel
}

/**
* @param string|Message $messageOrName
* @param array $payload
* @return null|Promise Promise is returned in case of a Query otherwise return type is null
* {@inheritdoc}
*/
public function dispatch($messageOrName, array $payload = []): ?Promise
{
Expand Down
24 changes: 24 additions & 0 deletions src/Messaging/MessageDispatcher.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
/**
* This file is part of the proophsoftware/event-machine.
* (c) 2017-2018 prooph software GmbH <contact@prooph.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Prooph\EventMachine\Messaging;

use React\Promise\Promise;

interface MessageDispatcher
{
/**
* @param string|Message $messageOrName
* @param array $payload
* @return null|Promise Promise is returned in case of a Query otherwise return type is null
*/
public function dispatch($messageOrName, array $payload = []): ?Promise;
}
27 changes: 27 additions & 0 deletions src/Persistence/AggregateStateStore.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
/**
* This file is part of the proophsoftware/event-machine.
* (c) 2017-2018 prooph software GmbH <contact@prooph.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Prooph\EventMachine\Persistence;

use Prooph\EventMachine\Aggregate\Exception\AggregateNotFound;
use Prooph\EventMachine\Exception\InvalidArgumentException;

interface AggregateStateStore
{
/**
* @param string $aggregateType
* @param string $aggregateId
* @return mixed State of the aggregate
* @throws InvalidArgumentException If $aggregateType is unknown
* @throws AggregateNotFound If aggregate state cannot be found
*/
public function loadAggregateState(string $aggregateType, string $aggregateId);
}

0 comments on commit bd233e0

Please sign in to comment.