Skip to content

Commit f8dcca9

Browse files
committed
Now $this->config has only params for Twig Environment options
1 parent 1dd3d29 commit f8dcca9

File tree

1 file changed

+30
-11
lines changed

1 file changed

+30
-11
lines changed

libraries/Twig.php

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,14 @@
1616

1717
class Twig
1818
{
19+
/**
20+
* @var array Paths to Twig templates
21+
*/
22+
private $paths = [];
23+
1924
/**
2025
* @var array Twig Environment Options
26+
* @see http://twig.sensiolabs.org/doc/api.html#environment-options
2127
*/
2228
private $config = [];
2329

@@ -34,6 +40,8 @@ class Twig
3440
*/
3541
private $functions_safe = [
3642
'form_open', 'form_close', 'form_error', 'form_hidden', 'set_value',
43+
// 'form_open_multipart', 'form_upload', 'form_submit', 'form_dropdown',
44+
// 'set_radio',
3745
];
3846

3947
/**
@@ -53,30 +61,41 @@ class Twig
5361

5462
public function __construct($params = [])
5563
{
56-
// default config
57-
$this->config = [
58-
'paths' => [VIEWPATH],
59-
'cache' => APPPATH . 'cache/twig',
60-
'debug' => ENVIRONMENT !== 'production',
61-
'autoescape' => TRUE,
62-
];
63-
64-
$this->config = array_merge($this->config, $params);
65-
6664
if (isset($params['functions']))
6765
{
6866
$this->functions_asis =
6967
array_unique(
7068
array_merge($this->functions_asis, $params['functions'])
7169
);
70+
unset($params['functions']);
7271
}
7372
if (isset($params['functions_safe']))
7473
{
7574
$this->functions_safe =
7675
array_unique(
7776
array_merge($this->functions_safe, $params['functions_safe'])
7877
);
78+
unset($params['functions_safe']);
79+
}
80+
81+
if (isset($params['paths']))
82+
{
83+
$this->paths = $params['paths'];
84+
unset($params['paths']);
85+
}
86+
else
87+
{
88+
$this->paths = [VIEWPATH];
7989
}
90+
91+
// default Twig config
92+
$this->config = [
93+
'cache' => APPPATH . 'cache/twig',
94+
'debug' => ENVIRONMENT !== 'production',
95+
'autoescape' => TRUE,
96+
];
97+
98+
$this->config = array_merge($this->config, $params);
8099
}
81100

82101
protected function resetTwig()
@@ -95,7 +114,7 @@ protected function createTwig()
95114

96115
if ($this->loader === null)
97116
{
98-
$this->loader = new \Twig_Loader_Filesystem($this->config['paths']);
117+
$this->loader = new \Twig_Loader_Filesystem($this->paths);
99118
}
100119

101120
$twig = new \Twig_Environment($this->loader, $this->config);

0 commit comments

Comments
 (0)