1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Ivory Google Map bundle 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\GoogleMapBundle\Twig; |
13
|
|
|
|
14
|
|
|
use Ivory\GoogleMap\Helper\MapHelper; |
15
|
|
|
use Ivory\GoogleMap\Map; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @author GeLo <[email protected]> |
19
|
|
|
*/ |
20
|
|
|
class MapExtension extends \Twig_Extension |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @var MapHelper |
24
|
|
|
*/ |
25
|
|
|
private $mapHelper; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @param MapHelper $mapHelper |
29
|
|
|
*/ |
30
|
36 |
|
public function __construct(MapHelper $mapHelper) |
31
|
|
|
{ |
32
|
36 |
|
$this->mapHelper = $mapHelper; |
33
|
36 |
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* {@inheritdoc} |
37
|
|
|
*/ |
38
|
36 |
|
public function getFunctions() |
39
|
|
|
{ |
40
|
36 |
|
$functions = []; |
41
|
|
|
|
42
|
36 |
|
foreach ($this->getMapping() as $name => $method) { |
43
|
36 |
|
$functions[] = new \Twig_SimpleFunction($name, [$this, $method], ['is_safe' => ['html']]); |
44
|
28 |
|
} |
45
|
|
|
|
46
|
36 |
|
return $functions; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @param Map $map |
51
|
|
|
* @param string[] $attributes |
52
|
|
|
* |
53
|
|
|
* @return string |
54
|
|
|
*/ |
55
|
9 |
|
public function render(Map $map, array $attributes = []) |
56
|
|
|
{ |
57
|
9 |
|
$map->addHtmlAttributes($attributes); |
58
|
|
|
|
59
|
9 |
|
return $this->mapHelper->render($map); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @param Map $map |
64
|
|
|
* @param string[] $attributes |
65
|
|
|
* |
66
|
|
|
* @return string |
67
|
|
|
*/ |
68
|
9 |
|
public function renderHtml(Map $map, array $attributes = []) |
69
|
|
|
{ |
70
|
9 |
|
$map->addHtmlAttributes($attributes); |
71
|
|
|
|
72
|
9 |
|
return $this->mapHelper->renderHtml($map); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @param Map $map |
77
|
|
|
* |
78
|
|
|
* @return string |
79
|
|
|
*/ |
80
|
9 |
|
public function renderStylesheet(Map $map) |
81
|
|
|
{ |
82
|
9 |
|
return $this->mapHelper->renderStylesheet($map); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @param Map $map |
87
|
|
|
* |
88
|
|
|
* @return string |
89
|
|
|
*/ |
90
|
9 |
|
public function renderJavascript(Map $map) |
91
|
|
|
{ |
92
|
9 |
|
return $this->mapHelper->renderJavascript($map); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* {@inheritdoc} |
97
|
|
|
*/ |
98
|
36 |
|
public function getName() |
99
|
|
|
{ |
100
|
36 |
|
return 'ivory_google_map'; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @return string[] |
105
|
|
|
*/ |
106
|
36 |
|
private function getMapping() |
107
|
|
|
{ |
108
|
|
|
return [ |
109
|
36 |
|
'ivory_google_map' => 'render', |
110
|
28 |
|
'ivory_google_map_container' => 'renderHtml', |
111
|
28 |
|
'ivory_google_map_css' => 'renderStylesheet', |
112
|
28 |
|
'ivory_google_map_js' => 'renderJavascript', |
113
|
28 |
|
]; |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
|