forked from bresam/ivory-google-map-bundle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMapExtension.php
92 lines (76 loc) · 2.07 KB
/
MapExtension.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
/*
* This file is part of the Ivory Google Map bundle package.
*
* (c) Eric GELOEN <[email protected]>
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code.
*/
namespace Ivory\GoogleMapBundle\Twig;
use Ivory\GoogleMap\Helper\MapHelper;
use Ivory\GoogleMap\Map;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;
/**
* @author GeLo <[email protected]>
*/
class MapExtension extends AbstractExtension
{
private MapHelper $mapHelper;
public function __construct(MapHelper $mapHelper)
{
$this->mapHelper = $mapHelper;
}
/**
* {@inheritdoc}
*/
public function getFunctions(): array
{
$functions = [];
foreach ($this->getMapping() as $name => $method) {
$functions[] = new TwigFunction($name, [$this, $method], ['is_safe' => ['html']]);
}
return $functions;
}
/**
* @param string[] $attributes
*/
public function render(Map $map, array $attributes = []): string
{
$map->addHtmlAttributes($attributes);
return $this->mapHelper->render($map);
}
/**
* @param string[] $attributes
*/
public function renderHtml(Map $map, array $attributes = []): string
{
$map->addHtmlAttributes($attributes);
return $this->mapHelper->renderHtml($map);
}
public function renderStylesheet(Map $map): string
{
return $this->mapHelper->renderStylesheet($map);
}
public function renderJavascript(Map $map): string
{
return $this->mapHelper->renderJavascript($map);
}
public function getName(): string
{
return 'ivory_google_map';
}
/**
* @return string[]
*/
private function getMapping(): array
{
return [
'ivory_google_map' => 'render',
'ivory_google_map_container' => 'renderHtml',
'ivory_google_map_css' => 'renderStylesheet',
'ivory_google_map_js' => 'renderJavascript',
];
}
}