22/**
33 * Part of CodeIgniter Simple and Secure Twig
44 *
5- * @author Kenji Suzuki <https://github.com/kenjis>
6- * @license MIT License
7- * @copyright 2015 Kenji Suzuki
8- * @link https://github.com/kenjis/codeigniter-ss-twig
5+ * @license MIT License
6+ * @copyright 2015 Kenji Suzuki
7+ * @see https://github.com/kenjis/codeigniter-ss-twig
98 */
109
1110namespace Kenjis \CI4Twig ;
@@ -19,6 +18,7 @@ class Twig
1918
2019 /**
2120 * @var array Twig Environment Options
21+ *
2222 * @see https://twig.symfony.com/doc/3.x/api.html#environment-options
2323 */
2424 private $ config = [];
@@ -33,6 +33,7 @@ class Twig
3333
3434 /**
3535 * @var array Functions with `is_safe` option
36+ *
3637 * @see https://twig.symfony.com/doc/3.x/advanced.html#automatic-escaping
3738 */
3839 private $ functions_safe = [
@@ -42,8 +43,8 @@ class Twig
4243 'form_hidden ' ,
4344 'set_value ' ,
4445 'csrf_field ' ,
45- // 'form_open_multipart', 'form_upload', 'form_submit', 'form_dropdown',
46- // 'set_radio', 'set_select', 'set_checkbox',
46+ // 'form_open_multipart', 'form_upload', 'form_submit', 'form_dropdown',
47+ // 'set_radio', 'set_select', 'set_checkbox',
4748 ];
4849
4950 /**
@@ -64,21 +65,19 @@ class Twig
6465 public function __construct ($ params = [])
6566 {
6667 if (isset ($ params ['functions ' ])) {
67- $ this ->functions_asis =
68- array_unique (
69- array_merge ($ this ->functions_asis , $ params ['functions ' ])
70- );
68+ $ this ->functions_asis = array_unique (
69+ array_merge ($ this ->functions_asis , $ params ['functions ' ])
70+ );
7171 unset($ params ['functions ' ]);
7272 }
7373
7474 if (isset ($ params ['functions_safe ' ])) {
75- $ this ->functions_safe =
76- array_unique (
77- array_merge (
78- $ this ->functions_safe ,
79- $ params ['functions_safe ' ]
80- )
81- );
75+ $ this ->functions_safe = array_unique (
76+ array_merge (
77+ $ this ->functions_safe ,
78+ $ params ['functions_safe ' ]
79+ )
80+ );
8281 unset($ params ['functions_safe ' ]);
8382 }
8483
@@ -91,8 +90,8 @@ public function __construct($params = [])
9190
9291 // default Twig config
9392 $ this ->config = [
94- 'cache ' => WRITEPATH . 'cache/twig ' ,
95- 'debug ' => ENVIRONMENT !== 'production ' ,
93+ 'cache ' => WRITEPATH . 'cache/twig ' ,
94+ 'debug ' => ENVIRONMENT !== 'production ' ,
9695 'autoescape ' => 'html ' ,
9796 ];
9897
@@ -133,8 +132,8 @@ protected function setLoader($loader)
133132 /**
134133 * Registers a Global
135134 *
136- * @param string $name The global name
137- * @param mixed $value The global value
135+ * @param string $name The global name
136+ * @param mixed $value The global value
138137 */
139138 public function addGlobal ($ name , $ value )
140139 {
@@ -145,8 +144,9 @@ public function addGlobal($name, $value)
145144 /**
146145 * Renders Twig Template and Outputs
147146 *
148- * @param string $view Template filename without `.twig`
149- * @param array $params Array of parameters to pass to the template
147+ * @param string $view Template filename without `.twig`
148+ * @param array $params Array of parameters to pass to the template
149+ *
150150 * @throws \Twig\Error\LoaderError
151151 * @throws \Twig\Error\RuntimeError
152152 * @throws \Twig\Error\SyntaxError
@@ -159,9 +159,9 @@ public function display($view, $params = [])
159159 /**
160160 * Renders Twig Template and Returns as String
161161 *
162- * @param string $view Template filename without `.twig`
163- * @param array $params Array of parameters to pass to the template
164- * @return string
162+ * @param string $view Template filename without `.twig`
163+ * @param array $params Array of parameters to pass to the template
164+ *
165165 * @throws \Twig\Error\LoaderError
166166 * @throws \Twig\Error\RuntimeError
167167 * @throws \Twig\Error\SyntaxError
@@ -174,6 +174,7 @@ public function render($view, $params = []): string
174174 $ this ->addFunctions ();
175175
176176 $ view = $ view . '.twig ' ;
177+
177178 return $ this ->twig ->render ($ view , $ params );
178179 }
179180
@@ -234,18 +235,18 @@ protected function addFunctions()
234235 /**
235236 * @param string $uri
236237 * @param string $title
237- * @param array $attributes only array is acceptable
238- * @return string
238+ * @param array $attributes only array is acceptable
239239 */
240240 public function safe_anchor (
241241 $ uri = '' ,
242242 $ title = '' ,
243243 $ attributes = []
244244 ): string {
245- $ uri = esc ($ uri , 'url ' );
245+ $ uri = esc ($ uri , 'url ' );
246246 $ title = esc ($ title );
247247
248248 $ new_attr = [];
249+
249250 foreach ($ attributes as $ key => $ val ) {
250251 $ new_attr [esc ($ key )] = $ val ;
251252 }
@@ -258,12 +259,10 @@ public function validation_list_errors(): string
258259 return \Config \Services::validation ()->listErrors ();
259260 }
260261
261- /**
262- * @return \Twig\Environment
263- */
264262 public function getTwig (): \Twig \Environment
265263 {
266264 $ this ->createTwig ();
265+
267266 return $ this ->twig ;
268267 }
269268}
0 commit comments