-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- I was not able to pass projection options when defining projections so it couldn't be used when running projection with console command - projection options can be defined either in central way or as tagged service - supplementing the documentation with projection management
- Loading branch information
1 parent
70b6e6d
commit f70233e
Showing
20 changed files
with
454 additions
and
11 deletions.
There are no files selected for viewing
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
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
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
69 changes: 69 additions & 0 deletions
69
src/DependencyInjection/Compiler/ProjectionOptionsPass.php
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Prooph\Bundle\EventStore\DependencyInjection\Compiler; | ||
|
||
use Prooph\Bundle\EventStore\DependencyInjection\ProophEventStoreExtension; | ||
use Prooph\Bundle\EventStore\Exception\RuntimeException; | ||
use Prooph\Bundle\EventStore\Projection\ProjectionOptions; | ||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Definition; | ||
use Symfony\Component\DependencyInjection\Reference; | ||
|
||
final class ProjectionOptionsPass implements CompilerPassInterface | ||
{ | ||
public function process(ContainerBuilder $container): void | ||
{ | ||
if (! $container->hasDefinition('prooph_event_store.projection_options_locator')) { | ||
return; | ||
} | ||
|
||
$projectionOptionsIds = \array_keys($container->findTaggedServiceIds(ProophEventStoreExtension::TAG_PROJECTION_OPTIONS)); | ||
$projectionOptionsLocator = []; | ||
|
||
foreach ($projectionOptionsIds as $id) { | ||
$definition = $container->getDefinition($id); | ||
|
||
self::assertDefinitionIsAValidClass($id, $definition); | ||
|
||
$tags = $definition->getTag(ProophEventStoreExtension::TAG_PROJECTION_OPTIONS); | ||
foreach ($tags as $tag) { | ||
if (! isset($tag['projection_name'])) { | ||
throw new RuntimeException(\sprintf( | ||
'"projection_name" attribute is missing from tag "%s" on service "%s"', | ||
ProophEventStoreExtension::TAG_PROJECTION_OPTIONS, | ||
$id | ||
)); | ||
} | ||
|
||
$projectionOptionsLocator[$tag['projection_name']] = new Reference($id); | ||
} | ||
} | ||
|
||
$locator = $container->getDefinition('prooph_event_store.projection_options_locator'); | ||
$locator->replaceArgument(0, \array_merge($locator->getArgument(0), $projectionOptionsLocator)); | ||
} | ||
|
||
/** | ||
* @param string $serviceId The id of the service that is verified | ||
* @param Definition $definition The Definition of the service that is verified | ||
* | ||
* @throws RuntimeException if the service does not implement ProjectionOptions. | ||
*/ | ||
private static function assertDefinitionIsAValidClass(string $serviceId, Definition $definition): void | ||
{ | ||
/** @var object $definitionClass */ | ||
$definitionClass = $definition->getClass(); | ||
$reflection = new \ReflectionClass($definitionClass); | ||
|
||
if (! $reflection->implementsInterface(ProjectionOptions::class)) { | ||
throw new RuntimeException(\sprintf( | ||
'Tagged service "%s" must implement "%s"', | ||
$serviceId, | ||
ProjectionOptions::class | ||
)); | ||
} | ||
} | ||
} |
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Prooph\Bundle\EventStore\Projection\Options; | ||
|
||
use Prooph\Bundle\EventStore\Projection\ProjectionOptions as ProjectionOptionsInterface; | ||
|
||
final class ProjectionOptions implements ProjectionOptionsInterface | ||
{ | ||
/** | ||
* @var array | ||
*/ | ||
private $options; | ||
|
||
public function __construct(array $options) | ||
{ | ||
$this->options = $options; | ||
} | ||
|
||
public function options(): array | ||
{ | ||
return $this->options; | ||
} | ||
} |
Oops, something went wrong.