@@ 19-73 (lines=55) @@ | ||
16 | /** |
|
17 | * @author GeLo <[email protected]> |
|
18 | */ |
|
19 | class ApiExtension extends \Twig_Extension |
|
20 | { |
|
21 | /** |
|
22 | * @var ApiHelper |
|
23 | */ |
|
24 | private $apiHelper; |
|
25 | ||
26 | /** |
|
27 | * @param ApiHelper $apiHelper |
|
28 | */ |
|
29 | public function __construct(ApiHelper $apiHelper) |
|
30 | { |
|
31 | $this->apiHelper = $apiHelper; |
|
32 | } |
|
33 | ||
34 | /** |
|
35 | * {@inheritdoc} |
|
36 | */ |
|
37 | public function getFunctions() |
|
38 | { |
|
39 | $functions = []; |
|
40 | ||
41 | foreach ($this->getMapping() as $name => $method) { |
|
42 | $functions[] = new \Twig_SimpleFunction($name, [$this, $method], ['is_safe' => ['html']]); |
|
43 | } |
|
44 | ||
45 | return $functions; |
|
46 | } |
|
47 | ||
48 | /** |
|
49 | * @param object[] $objects |
|
50 | * |
|
51 | * @return string |
|
52 | */ |
|
53 | public function render(array $objects) |
|
54 | { |
|
55 | return $this->apiHelper->render($objects); |
|
56 | } |
|
57 | ||
58 | /** |
|
59 | * {@inheritdoc} |
|
60 | */ |
|
61 | public function getName() |
|
62 | { |
|
63 | return 'ivory_google_api'; |
|
64 | } |
|
65 | ||
66 | /** |
|
67 | * @return string[] |
|
68 | */ |
|
69 | private function getMapping() |
|
70 | { |
|
71 | return ['ivory_google_api' => 'render']; |
|
72 | } |
|
73 | } |
|
74 |
@@ 20-74 (lines=55) @@ | ||
17 | /** |
|
18 | * @author GeLo <[email protected]> |
|
19 | */ |
|
20 | class StaticMapExtension extends \Twig_Extension |
|
21 | { |
|
22 | /** |
|
23 | * @var StaticMapHelper |
|
24 | */ |
|
25 | private $staticMapHelper; |
|
26 | ||
27 | /** |
|
28 | * @param StaticMapHelper $staticMapHelper |
|
29 | */ |
|
30 | public function __construct(StaticMapHelper $staticMapHelper) |
|
31 | { |
|
32 | $this->staticMapHelper = $staticMapHelper; |
|
33 | } |
|
34 | ||
35 | /** |
|
36 | * {@inheritdoc} |
|
37 | */ |
|
38 | public function getFunctions() |
|
39 | { |
|
40 | $functions = []; |
|
41 | ||
42 | foreach ($this->getMapping() as $name => $method) { |
|
43 | $functions[] = new \Twig_SimpleFunction($name, [$this, $method], ['is_safe' => ['html']]); |
|
44 | } |
|
45 | ||
46 | return $functions; |
|
47 | } |
|
48 | ||
49 | /** |
|
50 | * @param Map $map |
|
51 | * |
|
52 | * @return string |
|
53 | */ |
|
54 | public function render(Map $map) |
|
55 | { |
|
56 | return $this->staticMapHelper->render($map); |
|
57 | } |
|
58 | ||
59 | /** |
|
60 | * {@inheritdoc} |
|
61 | */ |
|
62 | public function getName() |
|
63 | { |
|
64 | return 'ivory_google_map_static'; |
|
65 | } |
|
66 | ||
67 | /** |
|
68 | * @return string[] |
|
69 | */ |
|
70 | private function getMapping() |
|
71 | { |
|
72 | return ['ivory_google_map_static' => 'render']; |
|
73 | } |
|
74 | } |
|
75 |