|
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\Event; |
|
13
|
|
|
|
|
14
|
|
|
use Ivory\GoogleMap\Helper\Collector\Event\EventCollector; |
|
15
|
|
|
use Ivory\GoogleMap\Helper\Event\MapEvent; |
|
16
|
|
|
use Ivory\GoogleMap\Helper\Event\MapEvents; |
|
17
|
|
|
use Ivory\GoogleMap\Helper\Formatter\Formatter; |
|
18
|
|
|
use Ivory\GoogleMap\Helper\Renderer\Event\EventRenderer; |
|
19
|
|
|
use Ivory\GoogleMap\Helper\Subscriber\AbstractSubscriber; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @author GeLo <[email protected]> |
|
23
|
|
|
*/ |
|
24
|
|
View Code Duplication |
class SimpleEventSubscriber extends AbstractSubscriber |
|
|
|
|
|
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
27
|
|
|
* @var EventCollector |
|
28
|
|
|
*/ |
|
29
|
|
|
private $eventCollector; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @var EventRenderer |
|
33
|
|
|
*/ |
|
34
|
|
|
private $eventRenderer; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @param Formatter $formatter |
|
38
|
|
|
* @param EventCollector $eventCollector |
|
39
|
|
|
* @param EventRenderer $eventRenderer |
|
40
|
|
|
*/ |
|
41
|
224 |
|
public function __construct( |
|
42
|
|
|
Formatter $formatter, |
|
43
|
|
|
EventCollector $eventCollector, |
|
44
|
|
|
EventRenderer $eventRenderer |
|
45
|
|
|
) { |
|
46
|
224 |
|
parent::__construct($formatter); |
|
47
|
|
|
|
|
48
|
224 |
|
$this->setEventCollector($eventCollector); |
|
49
|
224 |
|
$this->setEventRenderer($eventRenderer); |
|
50
|
224 |
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @return EventCollector |
|
54
|
|
|
*/ |
|
55
|
|
|
public function getEventCollector() |
|
56
|
|
|
{ |
|
57
|
|
|
return $this->eventCollector; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @param EventCollector $eventCollector |
|
62
|
|
|
*/ |
|
63
|
224 |
|
public function setEventCollector(EventCollector $eventCollector) |
|
64
|
|
|
{ |
|
65
|
224 |
|
$this->eventCollector = $eventCollector; |
|
66
|
224 |
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @return EventRenderer |
|
70
|
|
|
*/ |
|
71
|
|
|
public function getEventRenderer() |
|
72
|
|
|
{ |
|
73
|
|
|
return $this->eventRenderer; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* @param EventRenderer $eventRenderer |
|
78
|
|
|
*/ |
|
79
|
224 |
|
public function setEventRenderer(EventRenderer $eventRenderer) |
|
80
|
|
|
{ |
|
81
|
224 |
|
$this->eventRenderer = $eventRenderer; |
|
82
|
224 |
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* @param MapEvent $event |
|
86
|
|
|
*/ |
|
87
|
220 |
|
public function handleMap(MapEvent $event) |
|
88
|
|
|
{ |
|
89
|
220 |
|
$formatter = $this->getFormatter(); |
|
90
|
220 |
|
$map = $event->getMap(); |
|
91
|
|
|
|
|
92
|
220 |
|
foreach ($this->eventCollector->collect($map) as $rawEvent) { |
|
93
|
4 |
|
$event->addCode($formatter->renderContainerAssignment( |
|
94
|
2 |
|
$map, |
|
95
|
4 |
|
$this->eventRenderer->render($rawEvent), |
|
96
|
4 |
|
'events.events', |
|
97
|
2 |
|
$rawEvent |
|
98
|
2 |
|
)); |
|
99
|
110 |
|
} |
|
100
|
220 |
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* {@inheritdoc} |
|
104
|
|
|
*/ |
|
105
|
224 |
|
public static function getSubscribedEvents() |
|
106
|
|
|
{ |
|
107
|
224 |
|
return [MapEvents::JAVASCRIPT_EVENT_EVENT => 'handleMap']; |
|
108
|
|
|
} |
|
109
|
|
|
} |
|
110
|
|
|
|
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.