Skip to content

Commit

Permalink
Merge pull request #108 from patchlevel/projectionist
Browse files Browse the repository at this point in the history
Projectionist
  • Loading branch information
DavidBadura authored Oct 11, 2022
2 parents aa85f06 + 17fa8e7 commit 4124513
Show file tree
Hide file tree
Showing 6 changed files with 148 additions and 34 deletions.
7 changes: 5 additions & 2 deletions baseline.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="4.27.0@faf106e717c37b8c81721845dba9de3d8deed8ff">
<files psalm-version="4.28.0@52e96bea381e6cb07a672aefec791a5817694a26">
<file src="src/DependencyInjection/PatchlevelEventSourcingExtension.php">
<DeprecatedClass occurrences="2">
<DeprecatedClass occurrences="5">
<code>DoctrineSchemaManager::class</code>
<code>DoctrineSchemaManager::class</code>
<code>MetadataAwareProjectionHandler::class</code>
<code>MetadataAwareProjectionHandler::class</code>
<code>ProjectionListener::class</code>
</DeprecatedClass>
</file>
</files>
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
],
"require": {
"php": "~8.1.0",
"patchlevel/event-sourcing": "^2.1.x-dev",
"patchlevel/event-sourcing": "2.1.0-beta1",
"symfony/config": "^4.4.34|^5.4.0|^6.0.0",
"symfony/console": "^4.4.34|^5.4.0|^6.0.0",
"symfony/dependency-injection": "^4.4.34|^5.4.0|^6.0.0",
Expand Down
19 changes: 9 additions & 10 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ public function getConfigTreeBuilder(): TreeBuilder
->end()
->end()

->arrayNode('projectionist')
->addDefaultsIfNotSet()
->children()
->booleanNode('enabled')->defaultValue(false)->end()
->end()
->end()

->end();
// @codingStandardsIgnoreEnd

Expand Down
125 changes: 104 additions & 21 deletions src/DependencyInjection/PatchlevelEventSourcingExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
use Patchlevel\EventSourcing\Console\Command\DebugCommand;
use Patchlevel\EventSourcing\Console\Command\ProjectionCreateCommand;
use Patchlevel\EventSourcing\Console\Command\ProjectionDropCommand;
use Patchlevel\EventSourcing\Console\Command\ProjectionistBootCommand;
use Patchlevel\EventSourcing\Console\Command\ProjectionistRemoveCommand;
use Patchlevel\EventSourcing\Console\Command\ProjectionistRunCommand;
use Patchlevel\EventSourcing\Console\Command\ProjectionistStatusCommand;
use Patchlevel\EventSourcing\Console\Command\ProjectionistTeardownCommand;
use Patchlevel\EventSourcing\Console\Command\ProjectionRebuildCommand;
use Patchlevel\EventSourcing\Console\Command\SchemaCreateCommand;
use Patchlevel\EventSourcing\Console\Command\SchemaDropCommand;
Expand All @@ -44,10 +49,19 @@
use Patchlevel\EventSourcing\Metadata\Event\AttributeEventRegistryFactory;
use Patchlevel\EventSourcing\Metadata\Event\EventMetadataFactory;
use Patchlevel\EventSourcing\Metadata\Event\EventRegistry;
use Patchlevel\EventSourcing\Projection\DefaultProjectionist;
use Patchlevel\EventSourcing\Projection\DefaultProjectorRepository;
use Patchlevel\EventSourcing\Projection\MetadataAwareProjectionHandler;
use Patchlevel\EventSourcing\Projection\MetadataProjectorResolver;
use Patchlevel\EventSourcing\Projection\Projection;
use Patchlevel\EventSourcing\Projection\ProjectionHandler;
use Patchlevel\EventSourcing\Projection\Projectionist;
use Patchlevel\EventSourcing\Projection\ProjectionListener;
use Patchlevel\EventSourcing\Projection\Projector;
use Patchlevel\EventSourcing\Projection\ProjectorRepository;
use Patchlevel\EventSourcing\Projection\ProjectorResolver;
use Patchlevel\EventSourcing\Projection\ProjectorStore\DoctrineStore;
use Patchlevel\EventSourcing\Projection\ProjectorStore\ProjectorStore;
use Patchlevel\EventSourcing\Repository\DefaultRepositoryManager;
use Patchlevel\EventSourcing\Repository\RepositoryManager;
use Patchlevel\EventSourcing\Schema\ChainSchemaConfigurator;
Expand Down Expand Up @@ -100,7 +114,7 @@ public function load(array $configs, ContainerBuilder $container): void
$configuration = new Configuration();

/**
* @var array{event_bus: ?array{type: string, service: string}, watch_server: array{enabled: bool, host: string}, connection: ?array{service: ?string, url: ?string}, store: array{schema_manager: string, type: string, options: array<string, mixed>}, aggregates: list<string>, events: list<string>, snapshot_stores: array<string, array{type: string, service: string}>, migration: array{path: string, namespace: string}, clock: array{freeze: ?string}} $config
* @var array{event_bus: ?array{type: string, service: string}, projectionist: array{enabled: bool}, watch_server: array{enabled: bool, host: string}, connection: ?array{service: ?string, url: ?string}, store: array{schema_manager: string, type: string, options: array<string, mixed>}, aggregates: list<string>, events: list<string>, snapshot_stores: array<string, array{type: string, service: string}>, migration: array{path: string, namespace: string}, clock: array{freeze: ?string}} $config
*/
$config = $this->processConfiguration($configuration, $configs);

Expand All @@ -112,7 +126,6 @@ public function load(array $configs, ContainerBuilder $container): void
$this->configureSerializer($config, $container);
$this->configureMessageDecorator($container);
$this->configureEventBus($config, $container);
$this->configureProjection($container);
$this->configureConnection($config, $container);
$this->configureStorage($config, $container);
$this->configureSnapshots($config, $container);
Expand All @@ -122,6 +135,12 @@ public function load(array $configs, ContainerBuilder $container): void
$this->configureClock($config, $container);
$this->configureSchema($config, $container);

if ($config['projectionist']['enabled']) {
$this->configureProjectionist($container);
} else {
$this->configureProjection($container);
}

if (class_exists(DependencyFactory::class)) {
$this->configureMigration($config, $container);
}
Expand Down Expand Up @@ -207,6 +226,89 @@ private function configureProjection(ContainerBuilder $container): void
->setArguments([new TaggedIteratorArgument('event_sourcing.projection')]);

$container->setAlias(ProjectionHandler::class, MetadataAwareProjectionHandler::class);

$container->register(ProjectionCreateCommand::class)
->setArguments([
new Reference(ProjectionHandler::class),
])
->addTag('console.command');

$container->register(ProjectionDropCommand::class)
->setArguments([
new Reference(ProjectionHandler::class),
])
->addTag('console.command');

$container->register(ProjectionRebuildCommand::class)
->setArguments([
new Reference(Store::class),
new Reference(ProjectionHandler::class),
])
->addTag('console.command');
}

private function configureProjectionist(ContainerBuilder $container): void
{
$container->registerForAutoconfiguration(Projector::class)
->addTag('event_sourcing.projector');

$container->register(DefaultProjectorRepository::class)
->setArguments([
new TaggedIteratorArgument('event_sourcing.projector'),
]);

$container->setAlias(ProjectorRepository::class, DefaultProjectorRepository::class);

$container->register(MetadataProjectorResolver::class);
$container->setAlias(ProjectorResolver::class, MetadataProjectorResolver::class);

$container->register(DoctrineStore::class)
->setArguments([
new Reference('event_sourcing.dbal_connection'),
])
->addTag('event_sourcing.schema_configurator');

$container->setAlias(ProjectorStore::class, DoctrineStore::class);

$container->register(DefaultProjectionist::class)
->setArguments([
new Reference(Store::class),
new Reference(ProjectorStore::class),
new Reference(ProjectorRepository::class),
new Reference(ProjectorResolver::class),
]);

$container->setAlias(Projectionist::class, DefaultProjectionist::class);

$container->register(ProjectionistBootCommand::class)
->setArguments([
new Reference(Projectionist::class),
])
->addTag('console.command');

$container->register(ProjectionistRunCommand::class)
->setArguments([
new Reference(Projectionist::class),
])
->addTag('console.command');

$container->register(ProjectionistTeardownCommand::class)
->setArguments([
new Reference(Projectionist::class),
])
->addTag('console.command');

$container->register(ProjectionistRemoveCommand::class)
->setArguments([
new Reference(Projectionist::class),
])
->addTag('console.command');

$container->register(ProjectionistStatusCommand::class)
->setArguments([
new Reference(Projectionist::class),
])
->addTag('console.command');
}

private function configureUpcaster(ContainerBuilder $container): void
Expand Down Expand Up @@ -391,25 +493,6 @@ private function configureCommands(ContainerBuilder $container): void
])
->addTag('console.command');

$container->register(ProjectionCreateCommand::class)
->setArguments([
new Reference(ProjectionHandler::class),
])
->addTag('console.command');

$container->register(ProjectionDropCommand::class)
->setArguments([
new Reference(ProjectionHandler::class),
])
->addTag('console.command');

$container->register(ProjectionRebuildCommand::class)
->setArguments([
new Reference(Store::class),
new Reference(ProjectionHandler::class),
])
->addTag('console.command');

$container->register(ShowCommand::class)
->setArguments([
new Reference(Store::class),
Expand Down
22 changes: 22 additions & 0 deletions tests/Unit/PatchlevelEventSourcingBundleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Patchlevel\EventSourcing\Console\Command\DebugCommand;
use Patchlevel\EventSourcing\Console\Command\ProjectionCreateCommand;
use Patchlevel\EventSourcing\Console\Command\ProjectionDropCommand;
use Patchlevel\EventSourcing\Console\Command\ProjectionistBootCommand;
use Patchlevel\EventSourcing\Console\Command\ProjectionRebuildCommand;
use Patchlevel\EventSourcing\Console\Command\SchemaCreateCommand;
use Patchlevel\EventSourcing\Console\Command\SchemaDropCommand;
Expand Down Expand Up @@ -592,6 +593,27 @@ public function testFrozenClock()
self::assertSame('2020-01-01 22:00:00', $clock->now()->format('Y-m-d H:i:s'));
}

public function testProjectionist()
{
$container = new ContainerBuilder();

$this->compileContainer(
$container,
[
'patchlevel_event_sourcing' => [
'connection' => [
'service' => 'doctrine.dbal.eventstore_connection',
],
'projectionist' => [
'enabled' => true,
],
],
]
);

self::assertInstanceOf(ProjectionistBootCommand::class, $container->get(ProjectionistBootCommand::class));
}

public function testFullBuild()
{
$container = new ContainerBuilder();
Expand Down

0 comments on commit 4124513

Please sign in to comment.