AbstractBusConfigurator::configureWithConfig()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 19
ccs 11
cts 11
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 11
nc 1
nop 1
crap 1
1
<?php declare(strict_types = 1);
2
3
namespace TomCizek\SymfonyProoph\ServiceBus\ServiceBusConfigurators;
4
5
use Prooph\Common\Messaging\MessageFactory;
6
use Symfony\Component\DependencyInjection\Definition;
7
use Symfony\Component\DependencyInjection\Reference;
8
use TomCizek\SymfonyProoph\Common\DefaultConfigurator;
9
10
abstract class AbstractBusConfigurator extends DefaultConfigurator
11
{
12
	protected const KEY_BUS_PLUGINS = 'plugins';
13
	protected const KEY_BUS_ROUTER = 'router';
14
	protected const KEY_BUS_ROUTER_ROUTES = 'routes';
15
	protected const KEY_ENABLE_HANDLER_LOCATION = 'enable_handler_location';
16
	protected const KEY_MESSAGE_FACTORY = 'message_factory';
17
18
	abstract public function getBusClass(): string;
19
20
	abstract public function getBusFactoryClass(): string;
21
22 18
	public function buildDefaultConfig(): array
23
	{
24
		return [
25 18
			self::KEY_BUS_PLUGINS => [],
26 18
			self::KEY_BUS_ROUTER => [
27 18
				self::KEY_BUS_ROUTER_ROUTES => [],
28
			],
29 18
			self::KEY_ENABLE_HANDLER_LOCATION => true,
30 18
			self::KEY_MESSAGE_FACTORY => MessageFactory::class,
31
		];
32
	}
33
34 16
	public function configureWithConfig(array $config): void
35
	{
36 16
		$interopContainerServiceId = $this->getInteropContainerServiceId();
37
38 16
		$factory = $this->getBusFactoryClass();
39
40 16
		$serviceBusDefinition = new Definition($this->getBusClass());
41
42
		$serviceBusDefinition
43 16
			->setFactory($factory . '::' . $this->getConfigKey())
44 16
			->addArgument(
45 16
				new Reference($interopContainerServiceId)
46
			);
47
48 16
		$serviceBusDefinitionName = 'prooph.service_bus.' . $this->getConfigKey();
49
50 16
		$this->containerBuilder->setDefinition($serviceBusDefinitionName, $serviceBusDefinition);
51 16
		$this->containerBuilder->setAlias($this->getBusClass(), $serviceBusDefinitionName);
52 16
	}
53
}
54