1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace IrishDan\NotificationBundle\DependencyInjection; |
4
|
|
|
|
5
|
|
|
use IrishDan\NotificationBundle\DependencyInjection\Factory\BroadcasterFactory; |
6
|
|
|
use IrishDan\NotificationBundle\DependencyInjection\Factory\ChannelFactory; |
7
|
|
|
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; |
8
|
|
|
use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
9
|
|
|
use Symfony\Component\Config\Definition\ConfigurationInterface; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class Configuration |
13
|
|
|
* |
14
|
|
|
* @package NotificationBundle\DependencyInjection |
15
|
|
|
*/ |
16
|
|
|
class Configuration implements ConfigurationInterface |
17
|
|
|
{ |
18
|
|
|
private $defaultAdapterTypes; |
19
|
|
|
private $broadcasters; |
20
|
|
|
|
21
|
|
|
public function __construct(array $defaultAdapterTypes = [], $broadcasters = []) |
22
|
|
|
{ |
23
|
|
|
$this->defaultAdapterTypes = $defaultAdapterTypes; |
24
|
|
|
$this->broadcasters = $broadcasters; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
private function addChannelsSection(ArrayNodeDefinition $node) |
28
|
|
|
{ |
29
|
|
|
$channelNodeBuilder = $node |
30
|
|
|
->children() |
31
|
|
|
->arrayNode('channels') |
32
|
|
|
->performNoDeepMerging() |
33
|
|
|
->children(); |
34
|
|
|
|
35
|
|
|
$factory = new ChannelFactory(); |
36
|
|
|
foreach ($this->defaultAdapterTypes as $type) { |
37
|
|
|
$factoryNode = $channelNodeBuilder->arrayNode($type)->canBeUnset(); |
38
|
|
|
$factory->addConfiguration($factoryNode, $type); |
39
|
|
|
} |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
private function addBroadcastChannelsSection(ArrayNodeDefinition $node) |
43
|
|
|
{ |
44
|
|
|
$broadcastNodeBuilder = $node |
45
|
|
|
->children() |
46
|
|
|
->arrayNode('broadcasters') |
47
|
|
|
// ->useAttributeAsKey('name') |
|
|
|
|
48
|
|
|
->prototype('array') |
49
|
|
|
->performNoDeepMerging() |
50
|
|
|
->children() |
51
|
|
|
; |
52
|
|
|
|
53
|
|
|
foreach ($this->broadcasters as $name) { |
54
|
|
|
$broadcastNodeBuilder->arrayNode($name) |
55
|
|
|
->prototype('scalar')->end() |
56
|
|
|
->end(); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* The root configuration for responsive image bundle. |
62
|
|
|
* |
63
|
|
|
* @return TreeBuilder |
64
|
|
|
*/ |
65
|
|
|
public function getConfigTreeBuilder() |
66
|
|
|
{ |
67
|
|
|
$treeBuilder = new TreeBuilder(); |
68
|
|
|
$rootNode = $treeBuilder->root('notification'); |
69
|
|
|
|
70
|
|
|
|
71
|
|
|
$this->addChannelsSection($rootNode); |
72
|
|
|
$this->addBroadcastChannelsSection($rootNode); |
73
|
|
|
|
74
|
|
|
$rootNode |
75
|
|
|
->children() |
76
|
|
|
->end(); |
77
|
|
|
|
78
|
|
|
return $treeBuilder; |
79
|
|
|
} |
80
|
|
|
} |
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.