1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Ivory Google Map package. |
5
|
|
|
* |
6
|
|
|
* (c) Eric GELOEN <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please read the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Ivory\GoogleMap\Helper\Builder; |
13
|
|
|
|
14
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcher; |
15
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
16
|
|
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @author GeLo <[email protected]> |
20
|
|
|
*/ |
21
|
|
|
abstract class AbstractHelperBuilder |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @var EventSubscriberInterface[] |
25
|
|
|
*/ |
26
|
|
|
private $subscribers = []; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @return static |
30
|
|
|
*/ |
31
|
|
|
public static function create() |
32
|
|
|
{ |
33
|
|
|
return new static(); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @return bool |
38
|
|
|
*/ |
39
|
|
|
public function hasSubscribers() |
40
|
|
|
{ |
41
|
|
|
return !empty($this->subscribers); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @return EventSubscriberInterface[] |
46
|
|
|
*/ |
47
|
|
|
public function getSubscribers() |
48
|
|
|
{ |
49
|
|
|
return $this->subscribers; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param EventSubscriberInterface[] $subscribers |
54
|
|
|
* |
55
|
|
|
* @return $this |
56
|
|
|
*/ |
57
|
|
|
public function setSubscribers(array $subscribers) |
58
|
|
|
{ |
59
|
|
|
$this->subscribers = []; |
60
|
|
|
$this->addSubscribers($subscribers); |
61
|
|
|
|
62
|
|
|
return $this; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @param EventSubscriberInterface[] $subscribers |
67
|
|
|
* |
68
|
|
|
* @return $this |
69
|
|
|
*/ |
70
|
|
|
public function addSubscribers(array $subscribers) |
71
|
|
|
{ |
72
|
|
|
foreach ($subscribers as $subscriber) { |
73
|
|
|
$this->addSubscriber($subscriber); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
return $this; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @param EventSubscriberInterface $subscriber |
81
|
|
|
* |
82
|
|
|
* @return bool |
83
|
|
|
*/ |
84
|
|
|
public function hasSubscriber(EventSubscriberInterface $subscriber) |
85
|
|
|
{ |
86
|
|
|
return in_array($subscriber, $this->subscribers, true); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @param EventSubscriberInterface $subscriber |
91
|
|
|
* |
92
|
|
|
* @return $this |
93
|
|
|
*/ |
94
|
|
|
public function addSubscriber(EventSubscriberInterface $subscriber) |
95
|
|
|
{ |
96
|
|
|
if (!$this->hasSubscriber($subscriber)) { |
97
|
|
|
$this->subscribers[] = $subscriber; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
return $this; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @param EventSubscriberInterface $subscriber |
105
|
|
|
* |
106
|
|
|
* @return $this |
107
|
|
|
*/ |
108
|
|
|
public function removeSubscriber(EventSubscriberInterface $subscriber) |
109
|
|
|
{ |
110
|
|
|
unset($this->subscribers[array_search($subscriber, $this->subscribers, true)]); |
111
|
|
|
$this->subscribers = array_values($this->subscribers); |
112
|
|
|
|
113
|
|
|
return $this; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @return EventDispatcherInterface |
118
|
|
|
*/ |
119
|
|
|
protected function createEventDispatcher() |
120
|
|
|
{ |
121
|
|
|
$eventDispatcher = new EventDispatcher(); |
122
|
|
|
|
123
|
|
|
foreach ($this->createSubscribers() as $subscriber) { |
124
|
|
|
$eventDispatcher->addSubscriber($subscriber); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
return $eventDispatcher; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @return EventSubscriberInterface[] |
132
|
|
|
*/ |
133
|
|
|
protected function createSubscribers() |
134
|
|
|
{ |
135
|
|
|
return $this->subscribers; |
136
|
|
|
} |
137
|
|
|
} |
138
|
|
|
|