Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Prooph Event Sourcing with Symfony Flex
{
"type": "project",
"license": "proprietary",
"provide": { "ext-mongo": "1.6.12" },
"require": {
"php": "^7.1.3",
"ext-iconv": "*",
"alcaeus/mongo-php-adapter": "^1.1",
"doctrine/doctrine-bundle": "^1.6",
"doctrine/doctrine-cache-bundle": "^1.2",
"doctrine/mongodb": "^1.6",
"doctrine/mongodb-odm-bundle": "^3.4",
"guzzlehttp/guzzle": "^6.3",
"lexik/jwt-authentication-bundle": "^2.4",
"prooph/event-sourcing": "^5.2",
"prooph/event-store-bus-bridge": "^3.0",
"prooph/event-store-symfony-bundle": "0.5.0",
"prooph/pdo-event-store": "^1.7",
"prooph/service-bus-symfony-bundle": "^0.6",
"symfony/asset": "^4.0",
"symfony/console": "^4.0",
"symfony/dotenv": "4.0.6",
"symfony/flex": "^1.0",
"symfony/framework-bundle": "^4.0",
"symfony/lts": "^4@dev",
"symfony/orm-pack": "^1.0",
"symfony/profiler-pack": "^1.0",
"symfony/translation": "^4.0",
"symfony/yaml": "^4.0"
},
"require-dev": {
"phpunit/phpunit": "^6.0",
"symfony/maker-bundle": "^1.1"
},
"config": {
"preferred-install": {
"*": "dist"
},
"sort-packages": true,
"platform": {
"ext-mongo": "1.6.16"
}
},
"autoload": {
"psr-4": {
"App\\": "src/App/",
"Acme\\": "src/Acme/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"replace": {
"symfony/polyfill-iconv": "*",
"symfony/polyfill-php71": "*",
"symfony/polyfill-php70": "*",
"symfony/polyfill-php56": "*"
},
"scripts": {
"auto-scripts": {
"cache:clear": "symfony-cmd",
"assets:install --symlink --relative %PUBLIC_DIR%": "symfony-cmd"
},
"post-install-cmd": [
"@auto-scripts"
],
"post-update-cmd": [
"@auto-scripts"
]
},
"conflict": {
"symfony/symfony": "*"
},
}
services:
Prooph\EventStore\Pdo\MySqlEventStore:
arguments: ['@prooph_event_store.message_factory', '@doctrine.pdo.connection', '@prooph_event_store.single_stream_strategy']
doctrine.pdo.connection:
class: PDO
factory: ['@database_connection', getWrappedConnection]
prooph_event_store.single_stream_strategy:
class: Prooph\EventStore\Pdo\PersistenceStrategy\MySqlSingleStreamStrategy
prooph_event_sourcing.aggregate_translator:
class: Prooph\EventSourcing\EventStoreIntegration\AggregateTranslator
prooph_event_store:
stores:
resource_store:
event_store: Prooph\EventStore\Pdo\MySqlEventStore
repositories:
resource_collection:
repository_class: Acme\Infrastructure\Repository\EventStoreResourceCollection
aggregate_type: Acme\Domain\Model\Resource\Resource
aggregate_translator: prooph_event_sourcing.aggregate_translator
stream_name: 'resource_stream'
projection_managers:
resource_projection_manager:
event_store: Prooph\EventStore\Pdo\MySqlEventStore
connection: 'doctrine.pdo.connection'
projections:
resource_projection:
projection: Acme\Infrastructure\Projection\Resource\ResourceProjection
prooph_service_bus:
command_buses:
transactional_command_bus:
router:
type: 'prooph_service_bus.command_bus_router'
event_buses:
synch_event_bus:
plugins:
- 'prooph_service_bus.on_event_invoke_strategy'
router:
type: 'prooph_service_bus.event_bus_router'
routes:
'Acme\Domain\Model\Resource\Event\PhotoUploaded':
- 'Acme\Infrastructure\ProcessManager\ThumbnailsGenerator'
<?php
namespace Acme\Infrastructure\Projection\Resource;
use Prooph\Bundle\EventStore\Projection\ReadModelProjection;
use Prooph\EventStore\Projection\ReadModelProjector;
use Acme\Domain\Model\Resource\Event\PhotoUploaded;
use Acme\Domain\Model\Resource\Event\ResourceAcquired;
/**
* Class ResourceProjection
* @package Acme\Infrastructure\Projection\Resource
*/
final class ResourceProjection implements ReadModelProjection
{
public function project(ReadModelProjector $projector): ReadModelProjector
{dump(__CLASS__);exit;
$projector->fromStream('event_stream')
->when([
ResourceAcquired::class => function ($state, ResourceAcquired $event) {
/** @var ResourceReadModel $readModel */
$readModel = $this->readModel();
$readModel->stack('acquire', [
'resourceGroupId' => $event->resourceGroupId()->toString(),
'name' => $event->name(),
'brandId' => $event->brandId()->toString(),
'serialNumber' => $event->serialNumber(),
'internalNumber' => $event->internalNumber(),
'locationId' => $event->locationId()->toString(),
'range' => $event->range(),
'acquisitionDate' => $event->acquisitionDate()->getTimestamp()
]);
},
PhotoUploaded::class => function ($state, PhotoUploaded $event) {
/** @var ResourceReadModel $readModel */
$readModel = $this->readModel();
dump($event);exit;
},
]);
return $projector;
}
}
<?php
namespace Acme\Infrastructure\Projection\Resource;
use Doctrine\MongoDB\Connection;
use Prooph\EventStore\Projection\AbstractReadModel;
use Acme\Infrastructure\Projection\Collection;
/**
* Class ResourceReadModel
* @package Acme\Infrastructure\Projection\Resource
*/
final class ResourceReadModel extends AbstractReadModel
{
/**
* @var Connection
*/
private $connection;
public function __construct(Connection $connection)
{
$this->connection = $connection;
}
public function init(): void
{
}
public function isInitialized(): bool
{
return true;
}
public function reset(): void
{
}
public function delete(): void
{
}
protected function insert(array $data): void
{dump($data);exit;
$this->connection->insert(Collection::RESOURCE, $data);
}
protected function uploadPhoto(string $assigneeId): void
{
dump($data);exit;
}
}
services:
Acme\Application\Service\Resource\AcquireResourceHandler:
arguments: ['@resource_collection']
public: true
tags:
- { name: 'prooph_service_bus.transactional_command_bus.route_target', message_detection: true }
Acme\Application\Service\Resource\UploadPhotoHandler:
arguments: ['@resource_collection', '@resourcephoto_repository']
public: true
tags:
- { name: 'prooph_service_bus.transactional_command_bus.route_target', message_detection: true }
Acme\Infrastructure\Projection\Resource\ResourceProjection:
public: true
class: Acme\Infrastructure\Projection\Resource\ResourceProjection
tags:
- { name: 'prooph_event_store.projection', projection_name: 'resource_projection', projection_manager: 'resource_projection_manager', read_model: 'Acme\Infrastructure\Projection\Resource\ResourceReadModel' }
Acme\Infrastructure\Projection\Resource\ResourceReadModel:
public: true
class: Acme\Infrastructure\Projection\Resource\ResourceReadModel
arguments: ['@doctrine_mongodb']
prooph_event_store_bus_bridge.synch_event_publisher:
class: Prooph\EventStoreBusBridge\EventPublisher
arguments: ['@prooph_service_bus.synch_event_bus']
public: true
tags:
- { name: 'prooph_event_store.resource_store.plugin' }
<?php
namespace Acme\Infrastructure\ProcessManager;
use Acme\Domain\Model\Resource\Event\PhotoUploaded;
/**
* Class ThumbnailsGenerator
* @package Acme\Infrastructure\ProcessManager
*/
final class ThumbnailsGenerator
{
public function __invoke(PhotoUploaded $event): void
{
dump($event);exit;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment