|
1
|
|
|
<?php declare(strict_types = 1); |
|
2
|
|
|
|
|
3
|
|
|
namespace TomCizek\SymfonyProoph\EventStore; |
|
4
|
|
|
|
|
5
|
|
|
use Prooph\EventStore\EventStore; |
|
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 EventStoreConfigurator extends DefaultConfigurator |
|
12
|
|
|
{ |
|
13
|
|
|
public const KEY = 'event_store'; |
|
14
|
|
|
public const KEY_FACTORY = 'factory'; |
|
15
|
|
|
|
|
16
|
18 |
|
public function buildDefaultConfig(): array |
|
17
|
|
|
{ |
|
18
|
18 |
|
return []; |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
18 |
|
public function getConfigKey(): string |
|
22
|
|
|
{ |
|
23
|
18 |
|
return self::KEY; |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
18 |
|
public function configureWithConfig(array $config): void |
|
27
|
|
|
{ |
|
28
|
18 |
|
$interopContainerServiceId = $this->getInteropContainerServiceId(); |
|
29
|
|
|
|
|
30
|
18 |
|
foreach (array_reverse($config) as $eventStoreConfigName => $specificConfig) { |
|
31
|
|
|
|
|
32
|
11 |
|
$factory = $this->getFactoryName($specificConfig, $eventStoreConfigName); |
|
33
|
|
|
|
|
34
|
10 |
|
$eventStoreDefinition = new Definition(EventStore::class); |
|
35
|
|
|
$eventStoreDefinition |
|
36
|
10 |
|
->setFactory($factory . '::' . $eventStoreConfigName) |
|
37
|
10 |
|
->addArgument( |
|
38
|
10 |
|
new Reference($interopContainerServiceId) |
|
39
|
|
|
); |
|
40
|
|
|
|
|
41
|
10 |
|
$eventStoreDefinitionName = 'prooph.event_store.' . $eventStoreConfigName; |
|
42
|
|
|
|
|
43
|
10 |
|
$this->containerBuilder->setDefinition($eventStoreDefinitionName, $eventStoreDefinition); |
|
44
|
|
|
|
|
45
|
10 |
|
$this->containerBuilder->setAlias(EventStore::class, $eventStoreDefinitionName); |
|
46
|
10 |
|
$this->containerBuilder->setAlias('prooph.event_store', $eventStoreDefinitionName); |
|
47
|
|
|
} |
|
48
|
17 |
|
} |
|
49
|
|
|
|
|
50
|
11 |
|
public function getFactoryName(array $specificConfig, string $eventStoreConfigName): string |
|
51
|
|
|
{ |
|
52
|
11 |
|
if (empty($specificConfig[self::KEY_FACTORY])) { |
|
53
|
1 |
|
throw new BadConfigurationException( |
|
54
|
1 |
|
sprintf( |
|
55
|
1 |
|
'Event store config for %s has not set factory. Please provide factory class for |
|
56
|
|
|
event store under prooph.event_store.%s.factory', |
|
57
|
1 |
|
$eventStoreConfigName, |
|
58
|
1 |
|
$eventStoreConfigName |
|
59
|
|
|
) |
|
60
|
|
|
); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
10 |
|
return $specificConfig[self::KEY_FACTORY]; |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|