Completed
Push — master ( 050190...cb3a57 )
by Tomáš
03:19
created

EventSourcingConfigurator   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 4
dl 0
loc 40
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A buildDefaultConfig() 0 6 1
A getConfigKey() 0 4 1
A configureWithConfig() 0 21 2
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 14
	}
49
}
50