|
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\Collector\Image\PolylineCollector; |
|
15
|
|
|
use Ivory\GoogleMap\Helper\Event\StaticMapEvent; |
|
16
|
|
|
use Ivory\GoogleMap\Helper\Event\StaticMapEvents; |
|
17
|
|
|
use Ivory\GoogleMap\Helper\Renderer\Image\Overlay\PolylineRenderer; |
|
18
|
|
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @author GeLo <[email protected]> |
|
22
|
|
|
*/ |
|
23
|
|
View Code Duplication |
class PolylineSubscriber implements EventSubscriberInterface |
|
|
|
|
|
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* @var PolylineCollector |
|
27
|
|
|
*/ |
|
28
|
|
|
private $polylineCollector; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var PolylineRenderer |
|
32
|
|
|
*/ |
|
33
|
|
|
private $polylineRenderer; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @param PolylineCollector $polylineCollector |
|
37
|
|
|
* @param PolylineRenderer $polylineRenderer |
|
38
|
|
|
*/ |
|
39
|
|
|
public function __construct(PolylineCollector $polylineCollector, PolylineRenderer $polylineRenderer) |
|
40
|
|
|
{ |
|
41
|
|
|
$this->polylineCollector = $polylineCollector; |
|
42
|
|
|
$this->polylineRenderer = $polylineRenderer; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @param StaticMapEvent $event |
|
47
|
|
|
*/ |
|
48
|
|
|
public function handleMap(StaticMapEvent $event) |
|
49
|
|
|
{ |
|
50
|
|
|
$result = []; |
|
51
|
|
|
|
|
52
|
|
|
foreach ($this->polylineCollector->collect($event->getMap()) as $polylines) { |
|
53
|
|
|
$result[] = $this->polylineRenderer->render($polylines); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
if (!empty($result)) { |
|
57
|
|
|
$event->setParameter('path', $result); |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* {@inheritdoc} |
|
63
|
|
|
*/ |
|
64
|
|
|
public static function getSubscribedEvents() |
|
65
|
|
|
{ |
|
66
|
|
|
return [StaticMapEvents::POLYLINE => 'handleMap']; |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|
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.