1
|
|
|
<?php declare(strict_types = 1); |
2
|
|
|
|
3
|
|
|
namespace TomCizek\SymfonyProoph\ProjectionManager; |
4
|
|
|
|
5
|
|
|
use Prooph\EventStore\Projection\ProjectionManager; |
6
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
7
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
8
|
|
|
use TomCizek\SymfonyProoph\BadConfigurationException; |
9
|
|
|
use TomCizek\SymfonyProoph\Common\DefaultConfigurator; |
10
|
|
|
|
11
|
|
|
class ProjectionManagerConfigurator extends DefaultConfigurator |
12
|
|
|
{ |
13
|
|
|
public const KEY = 'projection_manager'; |
14
|
|
|
public const KEY_FACTORY = 'factory'; |
15
|
|
|
|
16
|
16 |
|
public function buildDefaultConfig(): array |
17
|
|
|
{ |
18
|
16 |
|
return []; |
19
|
|
|
} |
20
|
|
|
|
21
|
16 |
|
public function getConfigKey(): string |
22
|
|
|
{ |
23
|
16 |
|
return self::KEY; |
24
|
|
|
} |
25
|
|
|
|
26
|
15 |
|
public function configureWithConfig(array $config): void |
27
|
|
|
{ |
28
|
15 |
|
$reversedConfig = array_reverse($config); |
29
|
|
|
|
30
|
15 |
|
foreach ($reversedConfig as $projectionManagerConfigName => $specificConfig) { |
31
|
5 |
|
$this->setDefinitionOfProjectionManager( |
32
|
5 |
|
$specificConfig, |
33
|
5 |
|
$projectionManagerConfigName |
34
|
|
|
); |
35
|
|
|
} |
36
|
14 |
|
} |
37
|
|
|
|
38
|
5 |
|
private function setDefinitionOfProjectionManager( |
39
|
|
|
array $specificConfig, |
40
|
|
|
string $projectionManagerConfigName |
41
|
|
|
): void { |
42
|
|
|
|
43
|
5 |
|
$referenceToInteropContainer = new Reference($this->getInteropContainerServiceId()); |
44
|
|
|
|
45
|
5 |
|
$factory = $this->getFactoryName($specificConfig, $projectionManagerConfigName); |
46
|
|
|
|
47
|
4 |
|
$projectionManagerDefinition = new Definition(ProjectionManager::class); |
48
|
|
|
$projectionManagerDefinition |
49
|
4 |
|
->setFactory($factory . '::' . $projectionManagerConfigName) |
50
|
4 |
|
->addArgument($referenceToInteropContainer); |
51
|
|
|
|
52
|
4 |
|
$definitionName = 'prooph.projection_manager.' . $projectionManagerConfigName; |
53
|
|
|
|
54
|
4 |
|
$this->containerBuilder->setDefinition($definitionName, $projectionManagerDefinition); |
55
|
|
|
|
56
|
4 |
|
$this->containerBuilder->setDefinition('prooph.projection_manager', $projectionManagerDefinition); |
57
|
4 |
|
$this->containerBuilder->setAlias(ProjectionManager::class, $definitionName); |
58
|
4 |
|
} |
59
|
|
|
|
60
|
5 |
|
private function getFactoryName(array $specificConfig, string $eventStoreConfigName): string |
61
|
|
|
{ |
62
|
5 |
|
if (empty($specificConfig[self::KEY_FACTORY])) { |
63
|
1 |
|
throw new BadConfigurationException( |
64
|
1 |
|
sprintf( |
65
|
1 |
|
'Projection manager config for %s has not set factory. Please provide factory class for |
66
|
|
|
event store under prooph.event_store.%s.factory', |
67
|
1 |
|
$eventStoreConfigName, |
68
|
1 |
|
$eventStoreConfigName |
69
|
|
|
) |
70
|
|
|
); |
71
|
|
|
} |
72
|
|
|
|
73
|
4 |
|
return $specificConfig[self::KEY_FACTORY]; |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|