Skip to content

Instantly share code, notes, and snippets.

@codeliner
Created April 5, 2020 16:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codeliner/b9494ae825d56f3db74ce501f02a7f19 to your computer and use it in GitHub Desktop.
Save codeliner/b9494ae825d56f3db74ce501f02a7f19 to your computer and use it in GitHub Desktop.
InspectIO prooph projection Elements API
<?php
declare(strict_types = 1);
chdir(dirname(__DIR__));
require 'vendor/autoload.php';
/** @var \Psr\Container\ContainerInterface $container */
$container = require 'config/container.php';
/** @var \Prooph\EventStore\Projection\ProjectionManager $projectionManager */
$projectionManager = $container->get(\Prooph\EventStore\Projection\ProjectionManager::class);
$projection = $projectionManager->createReadModelProjection(
'board_api_projection',
$container->get(\Inspectio\Board\Domain\Infrastructure\ReadModel\BoardGraphApiReadModel::class),
[
\Prooph\EventStore\Projection\ReadModelProjector::OPTION_PERSIST_BLOCK_SIZE => 1
]
);
$projection->fromStreams(\Inspectio\Board\Domain\Api\EventStream::SNAPSHOTS, 'event_stream')
->when([
\Inspectio\Board\Domain\Api\Event::BOARD_SNAPSHOT_TAKEN => function ($state, \Prooph\Common\Messaging\Message $event) {
/** @var \Inspectio\Board\Domain\Infrastructure\ReadModel\BoardGraphApiReadModel $readModel */
$readModel = $this->readModel();
$readModel->stack('applySnapshot', $event);
},
\Inspectio\Board\Domain\Api\Event::BOARD_PATCH_APPLIED => function ($state, \Prooph\Common\Messaging\Message $event) {
/** @var \Inspectio\Board\Domain\Infrastructure\ReadModel\BoardGraphApiReadModel $readModel */
$readModel = $this->readModel();
$readModel->stack('applyPatch', $event);
},
])
->run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment