-
-
Save codeliner/b9494ae825d56f3db74ce501f02a7f19 to your computer and use it in GitHub Desktop.
InspectIO prooph projection Elements API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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