Completed
Push — master ( 1494d2...398a9b )
by dan
02:07
created

BroadcasterFactory::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 21
rs 9.3142
c 0
b 0
f 0
cc 1
eloc 13
nc 1
nop 3
1
<?php
2
3
namespace IrishDan\NotificationBundle\DependencyInjection\Factory;
4
5
use Symfony\Component\DependencyInjection\ContainerBuilder;
6
use Symfony\Component\DependencyInjection\Definition;
7
8
class BroadcasterFactory
9
{
10
    public function create(ContainerBuilder $container, $name, array $config)
11
    {
12
        $type = array_keys($config)[0];
13
        $parameterName = 'notification.broadcast.config.' . $name;
14
        $serviceName = 'notification.broadcast.' . $name;
15
        $channelServiceName = 'notification.channel.' . $type;
16
17
        $container->setParameter($parameterName, $config[$type]);
18
19
        $definition = new Definition();
20
        $definition->setClass('IrishDan\NotificationBundle\Broadcast\Broadcaster');
21
        $definition->setArguments(
22
            [
23
                '@notification.broadcast.notifiable',
24
                '@' . $channelServiceName,
25
                '%' . $parameterName . '%',
26
            ]
27
        );
28
29
        $container->setDefinition($serviceName, $definition);
30
    }
31
}
32