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