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\Subscriber\Image; |
13
|
|
|
|
14
|
|
|
use Ivory\GoogleMap\Helper\Event\StaticMapEvents; |
15
|
|
|
use Ivory\GoogleMap\Helper\Subscriber\DelegateSubscriberInterface; |
16
|
|
|
use Symfony\Component\EventDispatcher\Event; |
17
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @author GeLo <[email protected]> |
21
|
|
|
*/ |
22
|
|
|
class StaticSubscriber implements DelegateSubscriberInterface |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @param Event $event |
26
|
|
|
* @param string $eventName |
27
|
|
|
* @param EventDispatcherInterface $eventDispatcher |
28
|
|
|
*/ |
29
|
|
View Code Duplication |
public function handle(Event $event, $eventName, EventDispatcherInterface $eventDispatcher) |
|
|
|
|
30
|
|
|
{ |
31
|
|
|
$delegates = static::getDelegatedSubscribedEvents(); |
32
|
|
|
|
33
|
|
|
if (isset($delegates[$eventName])) { |
34
|
|
|
foreach ($delegates[$eventName] as $delegate) { |
35
|
|
|
$eventDispatcher->dispatch($delegate, $event); |
36
|
|
|
} |
37
|
|
|
} |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* {@inheritdoc} |
42
|
|
|
*/ |
43
|
|
View Code Duplication |
public static function getSubscribedEvents() |
|
|
|
|
44
|
|
|
{ |
45
|
|
|
$events = []; |
46
|
|
|
|
47
|
|
|
foreach (array_keys(static::getDelegatedSubscribedEvents()) as $event) { |
48
|
|
|
$events[$event] = 'handle'; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
return $events; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* {@inheritdoc} |
56
|
|
|
*/ |
57
|
|
|
public static function getDelegatedSubscribedEvents() |
58
|
|
|
{ |
59
|
|
|
return [ |
|
|
|
|
60
|
|
|
StaticMapEvents::HTML => [ |
61
|
|
|
StaticMapEvents::CENTER, |
62
|
|
|
StaticMapEvents::FORMAT, |
63
|
|
|
StaticMapEvents::SCALE, |
64
|
|
|
StaticMapEvents::SIZE, |
65
|
|
|
StaticMapEvents::TYPE, |
66
|
|
|
StaticMapEvents::VISIBLE, |
67
|
|
|
StaticMapEvents::ZOOM, |
68
|
|
|
StaticMapEvents::MARKER, |
69
|
|
|
StaticMapEvents::POLYLINE, |
70
|
|
|
StaticMapEvents::ENCODED_POLYLINE, |
71
|
|
|
StaticMapEvents::KEY, |
72
|
|
|
], |
73
|
|
|
]; |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.