1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace IrishDan\NotificationBundle\DependencyInjection; |
4
|
|
|
|
5
|
|
|
use IrishDan\NotificationBundle\DependencyInjection\Factory\Broadcaster\SlackBroadcasterFactory; |
6
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
7
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
8
|
|
|
|
9
|
|
|
class NotificationExtension extends Extension |
10
|
|
|
{ |
11
|
|
|
public function load(array $configs, ContainerBuilder $container) |
12
|
|
|
{ |
13
|
|
|
$configuration = new Configuration(); |
14
|
|
|
$config = $this->processConfiguration($configuration, $configs); |
15
|
|
|
|
16
|
|
|
foreach ($configs as $subConfig) { |
17
|
|
|
$config = array_merge($config, $subConfig); |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
$channels = ['mail_channel', 'database_channel', 'pusher_channel', 'nexmo_channel']; |
21
|
|
|
$enabledChannels = []; |
22
|
|
|
|
23
|
|
|
foreach ($channels as $channel) { |
24
|
|
|
// Set an enabled flag for each channel. |
25
|
|
|
if (!empty($config[$channel]['enabled'])) { |
26
|
|
|
$enabledChannels[] = $channel; |
27
|
|
|
} |
28
|
|
|
$container->setParameter('notification.' . $channel . '.enabled', !empty($config[$channel]['enabled'])); |
29
|
|
|
|
30
|
|
|
// Set a configuration parameter for each channel also. |
31
|
|
|
switch ($channel) { |
32
|
|
|
case 'mail_channel': |
33
|
|
|
if (!empty($config[$channel])) { |
34
|
|
|
$configuration = $this->mailChannelConfiguration($config[$channel]); |
35
|
|
|
$container->setParameter('notification.' . $channel . '.configuration', $configuration); |
36
|
|
|
} |
37
|
|
|
break; |
38
|
|
|
|
39
|
|
|
case 'database_channel': |
40
|
|
|
case 'pusher_channel': |
41
|
|
|
case 'nexmo_channel': |
42
|
|
|
$configuration = empty($config[$channel]) ? [] : $config[$channel]; |
43
|
|
|
$container->setParameter('notification.' . $channel . '.configuration', $configuration); |
44
|
|
|
break; |
45
|
|
|
} |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
$container->setParameter('notification.available_channels', $enabledChannels); |
49
|
|
|
|
50
|
|
|
// foreach ($config['channels'] as $name => $config) { |
|
|
|
|
51
|
|
|
// $adapters[$name] = $this->createAdapter($name, $config, $container); |
|
|
|
|
52
|
|
|
// } |
53
|
|
|
|
54
|
|
|
foreach ($config['broadcasters'] as $name => $config) { |
55
|
|
|
$adapters[$name] = $this->createBroadcaster($name, $config, $container); |
|
|
|
|
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
private function createBroadcaster($name, $broadcaster, $container) |
|
|
|
|
60
|
|
|
{ |
61
|
|
|
// var_dump($name); |
|
|
|
|
62
|
|
|
// var_dump($broadcaster); |
|
|
|
|
63
|
|
|
// |
64
|
|
|
// $type = array_keys($broadcaster)[0]; |
|
|
|
|
65
|
|
|
// var_dump($type); |
|
|
|
|
66
|
|
|
// // @TODO: Use to get the factory |
67
|
|
|
// $factory = new SlackBroadcasterFactory(); |
|
|
|
|
68
|
|
|
|
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
private function mailChannelConfiguration($config) |
72
|
|
|
{ |
73
|
|
|
// @TODO: If the email config is not set use the parameters. |
74
|
|
|
|
75
|
|
|
return $config; |
76
|
|
|
} |
77
|
|
|
} |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.