|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of ocubom/twig-svg-extension |
|
5
|
|
|
* |
|
6
|
|
|
* © Oscar Cubo Medina <https://ocubom.github.io> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Ocubom\Twig\Extension; |
|
13
|
|
|
|
|
14
|
|
|
use Ocubom\Twig\Extension\Svg\Provider\FontAwesome\FontAwesomeRuntime; |
|
15
|
|
|
use Ocubom\Twig\Extension\Svg\Provider\Iconify\IconifyRuntime; |
|
16
|
|
|
use Twig\Extension\AbstractExtension; |
|
17
|
|
|
use Twig\TwigFilter; |
|
18
|
|
|
use Twig\TwigFunction; |
|
19
|
|
|
|
|
20
|
|
|
class SvgExtension extends AbstractExtension |
|
21
|
|
|
{ |
|
22
|
20 |
|
public function getFilters(): array |
|
23
|
|
|
{ |
|
24
|
20 |
|
return [ |
|
25
|
|
|
// SVG core |
|
26
|
20 |
|
new TwigFilter( |
|
27
|
20 |
|
'svg', |
|
28
|
20 |
|
[SvgRuntime::class, 'convertToSymbols'], |
|
29
|
20 |
|
[ |
|
30
|
20 |
|
'is_safe' => ['html'], |
|
31
|
20 |
|
'needs_environment' => true, |
|
32
|
20 |
|
] |
|
33
|
20 |
|
), |
|
34
|
20 |
|
new TwigFilter( |
|
35
|
20 |
|
'svg_symbols', |
|
36
|
20 |
|
[SvgRuntime::class, 'convertToSymbols'], |
|
37
|
20 |
|
[ |
|
38
|
20 |
|
'is_safe' => ['html'], |
|
39
|
20 |
|
'needs_environment' => true, |
|
40
|
20 |
|
] |
|
41
|
20 |
|
), |
|
42
|
|
|
|
|
43
|
|
|
// Providers |
|
44
|
20 |
|
new TwigFilter( |
|
45
|
20 |
|
'fontawesome', |
|
46
|
20 |
|
[FontAwesomeRuntime::class, 'replaceIcons'], |
|
47
|
20 |
|
[ |
|
48
|
20 |
|
'is_safe' => ['html'], |
|
49
|
20 |
|
'needs_environment' => true, |
|
50
|
20 |
|
] |
|
51
|
20 |
|
), |
|
52
|
20 |
|
new TwigFilter( |
|
53
|
20 |
|
'iconify', |
|
54
|
20 |
|
[IconifyRuntime::class, 'replaceIcons'], |
|
55
|
20 |
|
[ |
|
56
|
20 |
|
'is_safe' => ['html'], |
|
57
|
20 |
|
'needs_environment' => true, |
|
58
|
20 |
|
'is_variadic' => true, |
|
59
|
20 |
|
] |
|
60
|
20 |
|
), |
|
61
|
20 |
|
]; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
20 |
|
public function getFunctions(): array |
|
65
|
|
|
{ |
|
66
|
20 |
|
return [ |
|
67
|
|
|
// SVG Core |
|
68
|
20 |
|
new TwigFunction( |
|
69
|
20 |
|
'svg', |
|
70
|
20 |
|
[SvgRuntime::class, 'embedSvg'], |
|
71
|
20 |
|
[ |
|
72
|
20 |
|
'is_safe' => ['html'], |
|
73
|
20 |
|
'needs_environment' => true, |
|
74
|
20 |
|
] |
|
75
|
20 |
|
), |
|
76
|
|
|
|
|
77
|
|
|
// Providers |
|
78
|
20 |
|
new TwigFunction( |
|
79
|
20 |
|
'fa', |
|
80
|
20 |
|
[FontAwesomeRuntime::class, 'renderHtmlTag'], |
|
81
|
20 |
|
[ |
|
82
|
20 |
|
'is_safe' => ['html'], |
|
83
|
20 |
|
] |
|
84
|
20 |
|
), |
|
85
|
20 |
|
]; |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|