1 | <?php |
||
23 | class HtmlExtension extends AbstractTwigExtension implements |
||
24 | EngineExtensionInterface |
||
25 | { |
||
26 | |||
27 | /** |
||
28 | * @var UriGeneratorInterface |
||
29 | */ |
||
30 | private $generator; |
||
31 | |||
32 | /** |
||
33 | * @var array Default options for addCss and addJs template functions |
||
34 | */ |
||
35 | private static $options = [ |
||
36 | 'is_safe' => ['html'] |
||
37 | ]; |
||
38 | |||
39 | /** |
||
40 | * Creates an HTML template extension |
||
41 | * |
||
42 | * @param UriGeneratorInterface $generator |
||
43 | */ |
||
44 | public function __construct(UriGeneratorInterface $generator) |
||
48 | |||
49 | /** |
||
50 | * @return \Twig_SimpleFunction[] |
||
51 | */ |
||
52 | public function getFunctions() |
||
60 | |||
61 | /** |
||
62 | * Generates URI for provided location |
||
63 | * |
||
64 | * @param string $location Location name, path or identifier |
||
65 | * @param array $options Filter options |
||
66 | * |
||
67 | * @return null|\Psr\Http\Message\UriInterface |
||
68 | */ |
||
69 | private function location($location, array $options = []) |
||
73 | |||
74 | /** |
||
75 | * Creates a css link tag for provided css file |
||
76 | * |
||
77 | * @param string $file |
||
78 | * @param string $path |
||
79 | * @param array $options |
||
80 | * |
||
81 | * @return string |
||
82 | */ |
||
83 | private function css($file, $path = 'css', array $options = []) |
||
96 | |||
97 | /** |
||
98 | * Converts an attributes key/value array to its string representation |
||
99 | * |
||
100 | * @param array $attr |
||
101 | * |
||
102 | * @return string |
||
103 | */ |
||
104 | private function attributesStr(array $attr) |
||
112 | |||
113 | /** |
||
114 | * Creates the url() template function closure |
||
115 | * |
||
116 | * @return \Closure |
||
117 | */ |
||
118 | private function urlClosure() |
||
124 | |||
125 | /** |
||
126 | * Creates the addCss() template function closure |
||
127 | * |
||
128 | * @return \Closure |
||
129 | */ |
||
130 | private function cssClosure() |
||
136 | |||
137 | /** |
||
138 | * Creates the addJs() template function closure |
||
139 | * |
||
140 | * @return \Closure |
||
141 | */ |
||
142 | private function jsClosure() |
||
157 | } |