Completed
Push — master ( 398a9b...97130c )
by dan
02:04
created

BroadcasterFactory   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 3
dl 0
loc 30
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B create() 0 27 1
1
<?php
2
3
namespace IrishDan\NotificationBundle\DependencyInjection\Factory;
4
5
use Symfony\Component\DependencyInjection\ContainerBuilder;
6
use Symfony\Component\DependencyInjection\Definition;
7
use Symfony\Component\DependencyInjection\Reference;
8
9
class BroadcasterFactory
10
{
11
    public function create(ContainerBuilder $container, $name, array $config)
12
    {
13
        $type = array_keys($config)[0];
14
        $parameterName = 'notification.broadcast.config.' . $name;
15
        $serviceName = 'notification.broadcast.' . $name;
16
        $channelServiceName = 'notification.channel.' . $type;
17
18
        // Create the configuration as a parameter.
19
        $container->setParameter($parameterName, $config[$type]);
20
21
        // Createe the broadcast service
22
        $definition = new Definition();
23
        $definition->setClass('IrishDan\NotificationBundle\Broadcast\Broadcaster');
24
        $definition->setArguments(
25
            [
26
                '@notification.broadcast.notifiable',
27
                '@' . $channelServiceName,
28
                '%' . $parameterName . '%',
29
            ]
30
        );
31
32
        $container->setDefinition($serviceName, $definition);
33
34
        // Add the broadcast to the notification manager.
35
        $notificationManager = $container->getDefinition('notification.manager');
36
        $notificationManager->addMethodCall('setBroadcaster', [$name, new Reference($serviceName)]);
37
    }
38
}
39