|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace IrishDan\NotificationBundle\DependencyInjection\Factory; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\Config\Definition\Builder\NodeDefinition; |
|
6
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
7
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
|
8
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
|
9
|
|
|
|
|
10
|
|
|
class BroadcasterFactory |
|
11
|
|
|
{ |
|
12
|
|
|
public function create(ContainerBuilder $container, $name, array $config) |
|
13
|
|
|
{ |
|
14
|
|
|
$type = array_keys($config)[0]; |
|
15
|
|
|
$parameterName = 'notification.broadcast.config.' . $name; |
|
16
|
|
|
$serviceName = 'notification.broadcast.' . $name; |
|
17
|
|
|
|
|
18
|
|
|
$channelFactory = new ChannelFactory(); |
|
19
|
|
|
$channelServiceName = $channelFactory->create($container, $name, $config[$type], $type); |
|
20
|
|
|
|
|
21
|
|
|
// Create the configuration as a parameter. |
|
22
|
|
|
$container->setParameter($parameterName, $config[$type]); |
|
23
|
|
|
|
|
24
|
|
|
// Create the broadcast service |
|
25
|
|
|
$definition = new Definition(); |
|
26
|
|
|
$definition->setClass('IrishDan\NotificationBundle\Broadcast\Broadcaster'); |
|
27
|
|
|
$definition->setArguments( |
|
28
|
|
|
[ |
|
29
|
|
|
new Reference('notification.broadcast.notifiable'), |
|
30
|
|
|
new Reference($channelServiceName), |
|
31
|
|
|
'%' . $parameterName . '%', |
|
32
|
|
|
] |
|
33
|
|
|
); |
|
34
|
|
|
|
|
35
|
|
|
$container->setDefinition($serviceName, $definition); |
|
36
|
|
|
|
|
37
|
|
|
// Add the broadcast to the notification manager. |
|
38
|
|
|
$container->findDefinition('notification.manager')->addMethodCall('setBroadcaster', [$name, new Reference($serviceName)]); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function addConfiguration(NodeDefinition $node, $type) |
|
|
|
|
|
|
42
|
|
|
{ |
|
43
|
|
|
// var_dump($node->getNode()); |
|
|
|
|
|
|
44
|
|
|
} |
|
45
|
|
|
} |
|
46
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.