|
1
|
|
|
<?php declare(strict_types = 1); |
|
2
|
|
|
|
|
3
|
|
|
namespace TomCizek\SymfonyProoph\EventSourcing; |
|
4
|
|
|
|
|
5
|
|
|
use Prooph\EventSourcing\Container\Aggregate\AggregateRepositoryFactory; |
|
6
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
|
7
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
|
8
|
|
|
use TomCizek\SymfonyProoph\Common\DefaultConfigurator; |
|
9
|
|
|
|
|
10
|
|
|
class EventSourcingConfigurator extends DefaultConfigurator |
|
11
|
|
|
{ |
|
12
|
|
|
public const KEY = 'event_sourcing'; |
|
13
|
|
|
public const KEY_AGGREGATE_REPOSITORIES = 'aggregate_repository'; |
|
14
|
|
|
public const KEY_REPOSITORY_CLASS = 'repository_class'; |
|
15
|
|
|
|
|
16
|
16 |
|
public function buildDefaultConfig(): array |
|
17
|
|
|
{ |
|
18
|
|
|
return [ |
|
19
|
16 |
|
self::KEY_AGGREGATE_REPOSITORIES => [], |
|
20
|
|
|
]; |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
16 |
|
public function getConfigKey(): string |
|
24
|
|
|
{ |
|
25
|
16 |
|
return self::KEY; |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
14 |
|
public function configureWithConfig(array $config): void |
|
29
|
|
|
{ |
|
30
|
14 |
|
$repositoriesConfigs = $config[self::KEY_AGGREGATE_REPOSITORIES]; |
|
31
|
|
|
|
|
32
|
14 |
|
$interopContainerServiceId = $this->getInteropContainerServiceId(); |
|
33
|
|
|
|
|
34
|
14 |
|
foreach ($repositoriesConfigs as $repositoryConfigName => $repositoryConfig) { |
|
35
|
3 |
|
$repositoryClass = $repositoryConfig[self::KEY_REPOSITORY_CLASS]; |
|
36
|
|
|
|
|
37
|
3 |
|
$repositoryDefinition = new Definition($repositoryClass); |
|
38
|
|
|
$repositoryDefinition |
|
39
|
3 |
|
->setClass($repositoryClass) |
|
40
|
3 |
|
->setFactory(AggregateRepositoryFactory::class . '::' . $repositoryConfigName) |
|
41
|
3 |
|
->addArgument( |
|
42
|
3 |
|
new Reference($interopContainerServiceId) |
|
43
|
|
|
); |
|
44
|
|
|
|
|
45
|
3 |
|
$this->containerBuilder->setDefinition('prooph.' . $repositoryConfigName, $repositoryDefinition); |
|
46
|
3 |
|
$this->containerBuilder->setAlias($repositoryClass, 'prooph.' . $repositoryConfigName); |
|
47
|
|
|
|
|
48
|
3 |
|
$implementations = class_implements($repositoryClass); |
|
49
|
3 |
|
foreach($implementations as $implementation) { |
|
50
|
3 |
|
$this->containerBuilder->setAlias($implementation, 'prooph.' . $repositoryConfigName); |
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
14 |
|
} |
|
54
|
|
|
} |
|
55
|
|
|
|