@@ -30,15 +30,15 @@ |
||
30 | 30 | */ |
31 | 31 | class PluginCat extends Plugin implements ICompilable |
32 | 32 | { |
33 | - /** |
|
34 | - * @param Compiler $compiler |
|
35 | - * @param string $value |
|
36 | - * @param array $rest |
|
37 | - * |
|
38 | - * @return string |
|
39 | - */ |
|
40 | - public static function compile(Compiler $compiler, $value, array $rest) |
|
41 | - { |
|
42 | - return '(' . $value . ').(' . implode(').(', $rest) . ')'; |
|
43 | - } |
|
33 | + /** |
|
34 | + * @param Compiler $compiler |
|
35 | + * @param string $value |
|
36 | + * @param array $rest |
|
37 | + * |
|
38 | + * @return string |
|
39 | + */ |
|
40 | + public static function compile(Compiler $compiler, $value, array $rest) |
|
41 | + { |
|
42 | + return '(' . $value . ').(' . implode(').(', $rest) . ')'; |
|
43 | + } |
|
44 | 44 | } |
@@ -39,6 +39,6 @@ |
||
39 | 39 | */ |
40 | 40 | public static function compile(Compiler $compiler, $value, array $rest) |
41 | 41 | { |
42 | - return '(' . $value . ').(' . implode(').(', $rest) . ')'; |
|
42 | + return '('.$value.').('.implode(').(', $rest).')'; |
|
43 | 43 | } |
44 | 44 | } |
@@ -31,19 +31,19 @@ |
||
31 | 31 | */ |
32 | 32 | class PluginCountCharacters extends Plugin implements ICompilable |
33 | 33 | { |
34 | - /** |
|
35 | - * @param Compiler $compiler |
|
36 | - * @param string $value |
|
37 | - * @param bool $count_spaces |
|
38 | - * |
|
39 | - * @return string |
|
40 | - */ |
|
41 | - public static function compile(Compiler $compiler, $value, $count_spaces = false) |
|
42 | - { |
|
43 | - if ($count_spaces === 'false') { |
|
44 | - return 'preg_match_all(\'#[^\s\pZ]#u\', ' . $value . ', $tmp)'; |
|
45 | - } |
|
34 | + /** |
|
35 | + * @param Compiler $compiler |
|
36 | + * @param string $value |
|
37 | + * @param bool $count_spaces |
|
38 | + * |
|
39 | + * @return string |
|
40 | + */ |
|
41 | + public static function compile(Compiler $compiler, $value, $count_spaces = false) |
|
42 | + { |
|
43 | + if ($count_spaces === 'false') { |
|
44 | + return 'preg_match_all(\'#[^\s\pZ]#u\', ' . $value . ', $tmp)'; |
|
45 | + } |
|
46 | 46 | |
47 | - return 'mb_strlen(' . $value . ', $this->charset)'; |
|
48 | - } |
|
47 | + return 'mb_strlen(' . $value . ', $this->charset)'; |
|
48 | + } |
|
49 | 49 | } |
50 | 50 | \ No newline at end of file |
@@ -41,9 +41,9 @@ |
||
41 | 41 | public static function compile(Compiler $compiler, $value, $count_spaces = false) |
42 | 42 | { |
43 | 43 | if ($count_spaces === 'false') { |
44 | - return 'preg_match_all(\'#[^\s\pZ]#u\', ' . $value . ', $tmp)'; |
|
44 | + return 'preg_match_all(\'#[^\s\pZ]#u\', '.$value.', $tmp)'; |
|
45 | 45 | } |
46 | 46 | |
47 | - return 'mb_strlen(' . $value . ', $this->charset)'; |
|
47 | + return 'mb_strlen('.$value.', $this->charset)'; |
|
48 | 48 | } |
49 | 49 | } |
50 | 50 | \ No newline at end of file |
@@ -45,29 +45,29 @@ |
||
45 | 45 | |
46 | 46 | if ($tpl === null) { |
47 | 47 | throw new CompilationException($compiler, |
48 | - 'Load Templates : Resource "' . $resource . ':' . $identifier . '" not found.'); |
|
48 | + 'Load Templates : Resource "'.$resource.':'.$identifier.'" not found.'); |
|
49 | 49 | } elseif ($tpl === false) { |
50 | 50 | throw new CompilationException($compiler, |
51 | - 'Load Templates : Resource "' . $resource . '" does not support includes.'); |
|
51 | + 'Load Templates : Resource "'.$resource.'" does not support includes.'); |
|
52 | 52 | } |
53 | 53 | |
54 | - $out = '\'\';// checking for modification in ' . $resource . ':' . $identifier . "\r\n"; |
|
54 | + $out = '\'\';// checking for modification in '.$resource.':'.$identifier."\r\n"; |
|
55 | 55 | |
56 | 56 | $modCheck = $tpl->getIsModifiedCode(); |
57 | 57 | |
58 | 58 | if ($modCheck) { |
59 | - $out .= 'if (!(' . $modCheck . ')) { ob_end_clean(); return false; }'; |
|
59 | + $out .= 'if (!('.$modCheck.')) { ob_end_clean(); return false; }'; |
|
60 | 60 | } else { |
61 | 61 | $out .= 'try { |
62 | - $tpl = $this->templateFactory("' . $resource . '", "' . $identifier . '"); |
|
62 | + $tpl = $this->templateFactory("' . $resource.'", "'.$identifier.'"); |
|
63 | 63 | } catch (Dwoo\Exception $e) { |
64 | - $this->triggerError(\'Load Templates : Resource <em>' . $resource . '</em> was not added to Dwoo, can not extend <em>' . $identifier . '</em>\', E_USER_WARNING); |
|
64 | + $this->triggerError(\'Load Templates : Resource <em>' . $resource.'</em> was not added to Dwoo, can not extend <em>'.$identifier.'</em>\', E_USER_WARNING); |
|
65 | 65 | } |
66 | 66 | if ($tpl === null) |
67 | - $this->triggerError(\'Load Templates : Resource "' . $resource . ':' . $identifier . '" was not found.\', E_USER_WARNING); |
|
67 | + $this->triggerError(\'Load Templates : Resource "' . $resource.':'.$identifier.'" was not found.\', E_USER_WARNING); |
|
68 | 68 | elseif ($tpl === false) |
69 | - $this->triggerError(\'Load Templates : Resource "' . $resource . '" does not support extends.\', E_USER_WARNING); |
|
70 | -if ($tpl->getUid() != "' . $tpl->getUid() . '") { ob_end_clean(); return false; }'; |
|
69 | + $this->triggerError(\'Load Templates : Resource "' . $resource.'" does not support extends.\', E_USER_WARNING); |
|
70 | +if ($tpl->getUid() != "' . $tpl->getUid().'") { ob_end_clean(); return false; }'; |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | return $out; |
@@ -28,37 +28,37 @@ discard block |
||
28 | 28 | */ |
29 | 29 | class PluginExtendsCheck extends Plugin implements ICompilable |
30 | 30 | { |
31 | - /** |
|
32 | - * @param Compiler $compiler |
|
33 | - * @param $file |
|
34 | - * |
|
35 | - * @return string |
|
36 | - * @throws CompilationException |
|
37 | - */ |
|
38 | - public static function compile(Compiler $compiler, $file) |
|
39 | - { |
|
40 | - preg_match('#^["\']([a-z]{2,}):(.*?)["\']$#i', $file, $m); |
|
41 | - $resource = $m[1]; |
|
42 | - $identifier = $m[2]; |
|
31 | + /** |
|
32 | + * @param Compiler $compiler |
|
33 | + * @param $file |
|
34 | + * |
|
35 | + * @return string |
|
36 | + * @throws CompilationException |
|
37 | + */ |
|
38 | + public static function compile(Compiler $compiler, $file) |
|
39 | + { |
|
40 | + preg_match('#^["\']([a-z]{2,}):(.*?)["\']$#i', $file, $m); |
|
41 | + $resource = $m[1]; |
|
42 | + $identifier = $m[2]; |
|
43 | 43 | |
44 | - $tpl = $compiler->getCore()->templateFactory($resource, $identifier); |
|
44 | + $tpl = $compiler->getCore()->templateFactory($resource, $identifier); |
|
45 | 45 | |
46 | - if ($tpl === null) { |
|
47 | - throw new CompilationException($compiler, |
|
48 | - 'Load Templates : Resource "' . $resource . ':' . $identifier . '" not found.'); |
|
49 | - } elseif ($tpl === false) { |
|
50 | - throw new CompilationException($compiler, |
|
51 | - 'Load Templates : Resource "' . $resource . '" does not support includes.'); |
|
52 | - } |
|
46 | + if ($tpl === null) { |
|
47 | + throw new CompilationException($compiler, |
|
48 | + 'Load Templates : Resource "' . $resource . ':' . $identifier . '" not found.'); |
|
49 | + } elseif ($tpl === false) { |
|
50 | + throw new CompilationException($compiler, |
|
51 | + 'Load Templates : Resource "' . $resource . '" does not support includes.'); |
|
52 | + } |
|
53 | 53 | |
54 | - $out = '\'\';// checking for modification in ' . $resource . ':' . $identifier . "\r\n"; |
|
54 | + $out = '\'\';// checking for modification in ' . $resource . ':' . $identifier . "\r\n"; |
|
55 | 55 | |
56 | - $modCheck = $tpl->getIsModifiedCode(); |
|
56 | + $modCheck = $tpl->getIsModifiedCode(); |
|
57 | 57 | |
58 | - if ($modCheck) { |
|
59 | - $out .= 'if (!(' . $modCheck . ')) { ob_end_clean(); return false; }'; |
|
60 | - } else { |
|
61 | - $out .= 'try { |
|
58 | + if ($modCheck) { |
|
59 | + $out .= 'if (!(' . $modCheck . ')) { ob_end_clean(); return false; }'; |
|
60 | + } else { |
|
61 | + $out .= 'try { |
|
62 | 62 | $tpl = $this->templateFactory("' . $resource . '", "' . $identifier . '"); |
63 | 63 | } catch (Dwoo\Exception $e) { |
64 | 64 | $this->triggerError(\'Load Templates : Resource <em>' . $resource . '</em> was not added to Dwoo, can not extend <em>' . $identifier . '</em>\', E_USER_WARNING); |
@@ -68,8 +68,8 @@ discard block |
||
68 | 68 | elseif ($tpl === false) |
69 | 69 | $this->triggerError(\'Load Templates : Resource "' . $resource . '" does not support extends.\', E_USER_WARNING); |
70 | 70 | if ($tpl->getUid() != "' . $tpl->getUid() . '") { ob_end_clean(); return false; }'; |
71 | - } |
|
71 | + } |
|
72 | 72 | |
73 | - return $out; |
|
74 | - } |
|
73 | + return $out; |
|
74 | + } |
|
75 | 75 | } |
76 | 76 | \ No newline at end of file |
@@ -30,14 +30,14 @@ |
||
30 | 30 | */ |
31 | 31 | class PluginNl2br extends Plugin implements ICompilable |
32 | 32 | { |
33 | - /** |
|
34 | - * @param Compiler $compiler |
|
35 | - * @param string $value |
|
36 | - * |
|
37 | - * @return string |
|
38 | - */ |
|
39 | - public static function compile(Compiler $compiler, $value) |
|
40 | - { |
|
41 | - return 'nl2br((string) ' . $value . ')'; |
|
42 | - } |
|
33 | + /** |
|
34 | + * @param Compiler $compiler |
|
35 | + * @param string $value |
|
36 | + * |
|
37 | + * @return string |
|
38 | + */ |
|
39 | + public static function compile(Compiler $compiler, $value) |
|
40 | + { |
|
41 | + return 'nl2br((string) ' . $value . ')'; |
|
42 | + } |
|
43 | 43 | } |
44 | 44 | \ No newline at end of file |
@@ -38,6 +38,6 @@ |
||
38 | 38 | */ |
39 | 39 | public static function compile(Compiler $compiler, $value) |
40 | 40 | { |
41 | - return 'nl2br((string) ' . $value . ')'; |
|
41 | + return 'nl2br((string) '.$value.')'; |
|
42 | 42 | } |
43 | 43 | } |
44 | 44 | \ No newline at end of file |
@@ -41,159 +41,159 @@ |
||
41 | 41 | */ |
42 | 42 | class PluginMath extends Plugin implements ICompilable |
43 | 43 | { |
44 | - /** |
|
45 | - * @param Compiler $compiler |
|
46 | - * @param string $equation |
|
47 | - * @param string $format |
|
48 | - * @param string $assign |
|
49 | - * @param array $rest |
|
50 | - * |
|
51 | - * @return string |
|
52 | - * @throws CompilationException |
|
53 | - */ |
|
54 | - public static function compile(Compiler $compiler, $equation, $format = '', $assign = '', array $rest = array()) |
|
55 | - { |
|
56 | - /* |
|
44 | + /** |
|
45 | + * @param Compiler $compiler |
|
46 | + * @param string $equation |
|
47 | + * @param string $format |
|
48 | + * @param string $assign |
|
49 | + * @param array $rest |
|
50 | + * |
|
51 | + * @return string |
|
52 | + * @throws CompilationException |
|
53 | + */ |
|
54 | + public static function compile(Compiler $compiler, $equation, $format = '', $assign = '', array $rest = array()) |
|
55 | + { |
|
56 | + /* |
|
57 | 57 | * Holds the allowed function, characters, operators and constants |
58 | 58 | */ |
59 | - $allowed = array( |
|
60 | - '0', |
|
61 | - '1', |
|
62 | - '2', |
|
63 | - '3', |
|
64 | - '4', |
|
65 | - '5', |
|
66 | - '6', |
|
67 | - '7', |
|
68 | - '8', |
|
69 | - '9', |
|
70 | - '+', |
|
71 | - '-', |
|
72 | - '/', |
|
73 | - '*', |
|
74 | - '.', |
|
75 | - ' ', |
|
76 | - '<<', |
|
77 | - '>>', |
|
78 | - '%', |
|
79 | - '&', |
|
80 | - '^', |
|
81 | - '|', |
|
82 | - '~', |
|
83 | - 'abs(', |
|
84 | - 'ceil(', |
|
85 | - 'floor(', |
|
86 | - 'exp(', |
|
87 | - 'log10(', |
|
88 | - 'cos(', |
|
89 | - 'sin(', |
|
90 | - 'sqrt(', |
|
91 | - 'tan(', |
|
92 | - 'M_PI', |
|
93 | - 'INF', |
|
94 | - 'M_E', |
|
95 | - ); |
|
59 | + $allowed = array( |
|
60 | + '0', |
|
61 | + '1', |
|
62 | + '2', |
|
63 | + '3', |
|
64 | + '4', |
|
65 | + '5', |
|
66 | + '6', |
|
67 | + '7', |
|
68 | + '8', |
|
69 | + '9', |
|
70 | + '+', |
|
71 | + '-', |
|
72 | + '/', |
|
73 | + '*', |
|
74 | + '.', |
|
75 | + ' ', |
|
76 | + '<<', |
|
77 | + '>>', |
|
78 | + '%', |
|
79 | + '&', |
|
80 | + '^', |
|
81 | + '|', |
|
82 | + '~', |
|
83 | + 'abs(', |
|
84 | + 'ceil(', |
|
85 | + 'floor(', |
|
86 | + 'exp(', |
|
87 | + 'log10(', |
|
88 | + 'cos(', |
|
89 | + 'sin(', |
|
90 | + 'sqrt(', |
|
91 | + 'tan(', |
|
92 | + 'M_PI', |
|
93 | + 'INF', |
|
94 | + 'M_E', |
|
95 | + ); |
|
96 | 96 | |
97 | - /* |
|
97 | + /* |
|
98 | 98 | * Holds the functions that can accept multiple arguments |
99 | 99 | */ |
100 | - $funcs = array( |
|
101 | - 'round(', |
|
102 | - 'log(', |
|
103 | - 'pow(', |
|
104 | - 'max(', |
|
105 | - 'min(', |
|
106 | - 'rand(', |
|
107 | - ); |
|
100 | + $funcs = array( |
|
101 | + 'round(', |
|
102 | + 'log(', |
|
103 | + 'pow(', |
|
104 | + 'max(', |
|
105 | + 'min(', |
|
106 | + 'rand(', |
|
107 | + ); |
|
108 | 108 | |
109 | - $equation = $equationSrc = str_ireplace(array( |
|
110 | - 'pi', |
|
111 | - 'M_PI()', |
|
112 | - 'inf', |
|
113 | - ' e ' |
|
114 | - ), |
|
115 | - array( |
|
116 | - 'M_PI', |
|
117 | - 'M_PI', |
|
118 | - 'INF', |
|
119 | - ' M_E ' |
|
120 | - ), |
|
121 | - $equation); |
|
109 | + $equation = $equationSrc = str_ireplace(array( |
|
110 | + 'pi', |
|
111 | + 'M_PI()', |
|
112 | + 'inf', |
|
113 | + ' e ' |
|
114 | + ), |
|
115 | + array( |
|
116 | + 'M_PI', |
|
117 | + 'M_PI', |
|
118 | + 'INF', |
|
119 | + ' M_E ' |
|
120 | + ), |
|
121 | + $equation); |
|
122 | 122 | |
123 | - $delim = $equation[0]; |
|
124 | - $open = $delim . '.'; |
|
125 | - $close = '.' . $delim; |
|
126 | - $equation = substr($equation, 1, - 1); |
|
127 | - $out = ''; |
|
128 | - $ptr = 1; |
|
129 | - $allowcomma = 0; |
|
130 | - while (strlen($equation) > 0) { |
|
131 | - $substr = substr($equation, 0, $ptr); |
|
132 | - if (array_search($substr, $allowed) !== false) { |
|
133 | - // allowed string |
|
134 | - $out .= $substr; |
|
135 | - $equation = substr($equation, $ptr); |
|
136 | - $ptr = 0; |
|
137 | - } elseif (array_search($substr, $funcs) !== false) { |
|
138 | - // allowed func |
|
139 | - $out .= $substr; |
|
140 | - $equation = substr($equation, $ptr); |
|
141 | - $ptr = 0; |
|
142 | - ++ $allowcomma; |
|
143 | - if ($allowcomma === 1) { |
|
144 | - $allowed[] = ','; |
|
145 | - } |
|
146 | - } elseif (isset($rest[$substr])) { |
|
147 | - // variable |
|
148 | - $out .= $rest[$substr]; |
|
149 | - $equation = substr($equation, $ptr); |
|
150 | - $ptr = 0; |
|
151 | - } elseif ($substr === $open) { |
|
152 | - // pre-replaced variable |
|
153 | - preg_match('#.*\((?:[^()]*?|(?R))\)' . str_replace('.', '\\.', $close) . '#', substr($equation, 2), $m); |
|
154 | - if (empty($m)) { |
|
155 | - preg_match('#.*?' . str_replace('.', '\\.', $close) . '#', substr($equation, 2), $m); |
|
156 | - } |
|
157 | - $out .= substr($m[0], 0, - 2); |
|
158 | - $equation = substr($equation, strlen($m[0]) + 2); |
|
159 | - $ptr = 0; |
|
160 | - } elseif ($substr === '(') { |
|
161 | - // opening parenthesis |
|
162 | - if ($allowcomma > 0) { |
|
163 | - ++ $allowcomma; |
|
164 | - } |
|
123 | + $delim = $equation[0]; |
|
124 | + $open = $delim . '.'; |
|
125 | + $close = '.' . $delim; |
|
126 | + $equation = substr($equation, 1, - 1); |
|
127 | + $out = ''; |
|
128 | + $ptr = 1; |
|
129 | + $allowcomma = 0; |
|
130 | + while (strlen($equation) > 0) { |
|
131 | + $substr = substr($equation, 0, $ptr); |
|
132 | + if (array_search($substr, $allowed) !== false) { |
|
133 | + // allowed string |
|
134 | + $out .= $substr; |
|
135 | + $equation = substr($equation, $ptr); |
|
136 | + $ptr = 0; |
|
137 | + } elseif (array_search($substr, $funcs) !== false) { |
|
138 | + // allowed func |
|
139 | + $out .= $substr; |
|
140 | + $equation = substr($equation, $ptr); |
|
141 | + $ptr = 0; |
|
142 | + ++ $allowcomma; |
|
143 | + if ($allowcomma === 1) { |
|
144 | + $allowed[] = ','; |
|
145 | + } |
|
146 | + } elseif (isset($rest[$substr])) { |
|
147 | + // variable |
|
148 | + $out .= $rest[$substr]; |
|
149 | + $equation = substr($equation, $ptr); |
|
150 | + $ptr = 0; |
|
151 | + } elseif ($substr === $open) { |
|
152 | + // pre-replaced variable |
|
153 | + preg_match('#.*\((?:[^()]*?|(?R))\)' . str_replace('.', '\\.', $close) . '#', substr($equation, 2), $m); |
|
154 | + if (empty($m)) { |
|
155 | + preg_match('#.*?' . str_replace('.', '\\.', $close) . '#', substr($equation, 2), $m); |
|
156 | + } |
|
157 | + $out .= substr($m[0], 0, - 2); |
|
158 | + $equation = substr($equation, strlen($m[0]) + 2); |
|
159 | + $ptr = 0; |
|
160 | + } elseif ($substr === '(') { |
|
161 | + // opening parenthesis |
|
162 | + if ($allowcomma > 0) { |
|
163 | + ++ $allowcomma; |
|
164 | + } |
|
165 | 165 | |
166 | - $out .= $substr; |
|
167 | - $equation = substr($equation, $ptr); |
|
168 | - $ptr = 0; |
|
169 | - } elseif ($substr === ')') { |
|
170 | - // closing parenthesis |
|
171 | - if ($allowcomma > 0) { |
|
172 | - -- $allowcomma; |
|
173 | - if ($allowcomma === 0) { |
|
174 | - array_pop($allowed); |
|
175 | - } |
|
176 | - } |
|
166 | + $out .= $substr; |
|
167 | + $equation = substr($equation, $ptr); |
|
168 | + $ptr = 0; |
|
169 | + } elseif ($substr === ')') { |
|
170 | + // closing parenthesis |
|
171 | + if ($allowcomma > 0) { |
|
172 | + -- $allowcomma; |
|
173 | + if ($allowcomma === 0) { |
|
174 | + array_pop($allowed); |
|
175 | + } |
|
176 | + } |
|
177 | 177 | |
178 | - $out .= $substr; |
|
179 | - $equation = substr($equation, $ptr); |
|
180 | - $ptr = 0; |
|
181 | - } elseif ($ptr >= strlen($equation)) { |
|
182 | - // parse error if we've consumed the entire equation without finding anything valid |
|
183 | - throw new CompilationException($compiler, |
|
184 | - 'Math : Syntax error or variable undefined in equation ' . $equationSrc . ' at ' . $substr); |
|
185 | - } else { |
|
186 | - // nothing special, advance |
|
187 | - ++ $ptr; |
|
188 | - } |
|
189 | - } |
|
190 | - if ($format !== '\'\'') { |
|
191 | - $out = 'sprintf(' . $format . ', ' . $out . ')'; |
|
192 | - } |
|
193 | - if ($assign !== '\'\'') { |
|
194 | - return '($this->assignInScope(' . $out . ', ' . $assign . '))'; |
|
195 | - } |
|
178 | + $out .= $substr; |
|
179 | + $equation = substr($equation, $ptr); |
|
180 | + $ptr = 0; |
|
181 | + } elseif ($ptr >= strlen($equation)) { |
|
182 | + // parse error if we've consumed the entire equation without finding anything valid |
|
183 | + throw new CompilationException($compiler, |
|
184 | + 'Math : Syntax error or variable undefined in equation ' . $equationSrc . ' at ' . $substr); |
|
185 | + } else { |
|
186 | + // nothing special, advance |
|
187 | + ++ $ptr; |
|
188 | + } |
|
189 | + } |
|
190 | + if ($format !== '\'\'') { |
|
191 | + $out = 'sprintf(' . $format . ', ' . $out . ')'; |
|
192 | + } |
|
193 | + if ($assign !== '\'\'') { |
|
194 | + return '($this->assignInScope(' . $out . ', ' . $assign . '))'; |
|
195 | + } |
|
196 | 196 | |
197 | - return '(' . $out . ')'; |
|
198 | - } |
|
197 | + return '(' . $out . ')'; |
|
198 | + } |
|
199 | 199 | } |
200 | 200 | \ No newline at end of file |
@@ -121,8 +121,8 @@ discard block |
||
121 | 121 | $equation); |
122 | 122 | |
123 | 123 | $delim = $equation[0]; |
124 | - $open = $delim . '.'; |
|
125 | - $close = '.' . $delim; |
|
124 | + $open = $delim.'.'; |
|
125 | + $close = '.'.$delim; |
|
126 | 126 | $equation = substr($equation, 1, - 1); |
127 | 127 | $out = ''; |
128 | 128 | $ptr = 1; |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | $out .= $substr; |
140 | 140 | $equation = substr($equation, $ptr); |
141 | 141 | $ptr = 0; |
142 | - ++ $allowcomma; |
|
142 | + ++$allowcomma; |
|
143 | 143 | if ($allowcomma === 1) { |
144 | 144 | $allowed[] = ','; |
145 | 145 | } |
@@ -150,17 +150,17 @@ discard block |
||
150 | 150 | $ptr = 0; |
151 | 151 | } elseif ($substr === $open) { |
152 | 152 | // pre-replaced variable |
153 | - preg_match('#.*\((?:[^()]*?|(?R))\)' . str_replace('.', '\\.', $close) . '#', substr($equation, 2), $m); |
|
153 | + preg_match('#.*\((?:[^()]*?|(?R))\)'.str_replace('.', '\\.', $close).'#', substr($equation, 2), $m); |
|
154 | 154 | if (empty($m)) { |
155 | - preg_match('#.*?' . str_replace('.', '\\.', $close) . '#', substr($equation, 2), $m); |
|
155 | + preg_match('#.*?'.str_replace('.', '\\.', $close).'#', substr($equation, 2), $m); |
|
156 | 156 | } |
157 | 157 | $out .= substr($m[0], 0, - 2); |
158 | - $equation = substr($equation, strlen($m[0]) + 2); |
|
158 | + $equation = substr($equation, strlen($m[0])+2); |
|
159 | 159 | $ptr = 0; |
160 | 160 | } elseif ($substr === '(') { |
161 | 161 | // opening parenthesis |
162 | 162 | if ($allowcomma > 0) { |
163 | - ++ $allowcomma; |
|
163 | + ++$allowcomma; |
|
164 | 164 | } |
165 | 165 | |
166 | 166 | $out .= $substr; |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | } elseif ($substr === ')') { |
170 | 170 | // closing parenthesis |
171 | 171 | if ($allowcomma > 0) { |
172 | - -- $allowcomma; |
|
172 | + --$allowcomma; |
|
173 | 173 | if ($allowcomma === 0) { |
174 | 174 | array_pop($allowed); |
175 | 175 | } |
@@ -181,19 +181,19 @@ discard block |
||
181 | 181 | } elseif ($ptr >= strlen($equation)) { |
182 | 182 | // parse error if we've consumed the entire equation without finding anything valid |
183 | 183 | throw new CompilationException($compiler, |
184 | - 'Math : Syntax error or variable undefined in equation ' . $equationSrc . ' at ' . $substr); |
|
184 | + 'Math : Syntax error or variable undefined in equation '.$equationSrc.' at '.$substr); |
|
185 | 185 | } else { |
186 | 186 | // nothing special, advance |
187 | - ++ $ptr; |
|
187 | + ++$ptr; |
|
188 | 188 | } |
189 | 189 | } |
190 | 190 | if ($format !== '\'\'') { |
191 | - $out = 'sprintf(' . $format . ', ' . $out . ')'; |
|
191 | + $out = 'sprintf('.$format.', '.$out.')'; |
|
192 | 192 | } |
193 | 193 | if ($assign !== '\'\'') { |
194 | - return '($this->assignInScope(' . $out . ', ' . $assign . '))'; |
|
194 | + return '($this->assignInScope('.$out.', '.$assign.'))'; |
|
195 | 195 | } |
196 | 196 | |
197 | - return '(' . $out . ')'; |
|
197 | + return '('.$out.')'; |
|
198 | 198 | } |
199 | 199 | } |
200 | 200 | \ No newline at end of file |
@@ -35,22 +35,22 @@ |
||
35 | 35 | */ |
36 | 36 | class PluginArray extends Plugin implements ICompilable |
37 | 37 | { |
38 | - /** |
|
39 | - * @param Compiler $compiler |
|
40 | - * @param array $rest |
|
41 | - * |
|
42 | - * @return string |
|
43 | - */ |
|
44 | - public static function compile(Compiler $compiler, array $rest = array()) |
|
45 | - { |
|
46 | - $out = array(); |
|
47 | - foreach ($rest as $key => $value) { |
|
48 | - if (!is_numeric($key) && !strstr($key, '$this->scope')) { |
|
49 | - $key = "'" . $key . "'"; |
|
50 | - } |
|
51 | - $out[] = $key . '=>' . $value; |
|
52 | - } |
|
38 | + /** |
|
39 | + * @param Compiler $compiler |
|
40 | + * @param array $rest |
|
41 | + * |
|
42 | + * @return string |
|
43 | + */ |
|
44 | + public static function compile(Compiler $compiler, array $rest = array()) |
|
45 | + { |
|
46 | + $out = array(); |
|
47 | + foreach ($rest as $key => $value) { |
|
48 | + if (!is_numeric($key) && !strstr($key, '$this->scope')) { |
|
49 | + $key = "'" . $key . "'"; |
|
50 | + } |
|
51 | + $out[] = $key . '=>' . $value; |
|
52 | + } |
|
53 | 53 | |
54 | - return 'array(' . implode(', ', $out) . ')'; |
|
55 | - } |
|
54 | + return 'array(' . implode(', ', $out) . ')'; |
|
55 | + } |
|
56 | 56 | } |
57 | 57 | \ No newline at end of file |
@@ -46,11 +46,11 @@ |
||
46 | 46 | $out = array(); |
47 | 47 | foreach ($rest as $key => $value) { |
48 | 48 | if (!is_numeric($key) && !strstr($key, '$this->scope')) { |
49 | - $key = "'" . $key . "'"; |
|
49 | + $key = "'".$key."'"; |
|
50 | 50 | } |
51 | - $out[] = $key . '=>' . $value; |
|
51 | + $out[] = $key.'=>'.$value; |
|
52 | 52 | } |
53 | 53 | |
54 | - return 'array(' . implode(', ', $out) . ')'; |
|
54 | + return 'array('.implode(', ', $out).')'; |
|
55 | 55 | } |
56 | 56 | } |
57 | 57 | \ No newline at end of file |
@@ -18,7 +18,6 @@ |
||
18 | 18 | |
19 | 19 | use Dwoo\Exception as DwooException; |
20 | 20 | use Dwoo\Core as Core; |
21 | -use Dwoo\ICompiler; |
|
22 | 21 | use Dwoo\ITemplate as ITemplate; |
23 | 22 | use Dwoo\Security\Exception as SecurityException; |
24 | 23 | use Dwoo\Template\File as TemplateFile; |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | */ |
112 | 112 | protected function isValidCompiledFile($file) |
113 | 113 | { |
114 | - return parent::isValidCompiledFile($file) && (int)$this->getUid() <= filemtime($file); |
|
114 | + return parent::isValidCompiledFile($file) && (int) $this->getUid() <= filemtime($file); |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | /** |
@@ -149,12 +149,12 @@ discard block |
||
149 | 149 | } else { |
150 | 150 | foreach ($this->getIncludePath() as $path) { |
151 | 151 | $path = rtrim($path, DIRECTORY_SEPARATOR); |
152 | - if (file_exists($path . DIRECTORY_SEPARATOR . $this->file) === true) { |
|
153 | - return $this->resolvedPath = $path . DIRECTORY_SEPARATOR . $this->file; |
|
152 | + if (file_exists($path.DIRECTORY_SEPARATOR.$this->file) === true) { |
|
153 | + return $this->resolvedPath = $path.DIRECTORY_SEPARATOR.$this->file; |
|
154 | 154 | } |
155 | 155 | } |
156 | 156 | |
157 | - throw new DwooException('Template "' . $this->file . '" could not be found in any of your include path(s)'); |
|
157 | + throw new DwooException('Template "'.$this->file.'" could not be found in any of your include path(s)'); |
|
158 | 158 | } |
159 | 159 | } |
160 | 160 | |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | */ |
167 | 167 | public function getUid() |
168 | 168 | { |
169 | - return (string)filemtime($this->getResourceIdentifier()); |
|
169 | + return (string) filemtime($this->getResourceIdentifier()); |
|
170 | 170 | } |
171 | 171 | |
172 | 172 | /** |
@@ -224,7 +224,7 @@ discard block |
||
224 | 224 | throw new DwooException('When using an include path you can not reference a template into a parent directory (using ../)'); |
225 | 225 | } |
226 | 226 | } else { |
227 | - $resourceId = dirname($parentTemplate->getResourceIdentifier()) . DIRECTORY_SEPARATOR . $resourceId; |
|
227 | + $resourceId = dirname($parentTemplate->getResourceIdentifier()).DIRECTORY_SEPARATOR.$resourceId; |
|
228 | 228 | if (file_exists($resourceId) === false) { |
229 | 229 | return null; |
230 | 230 | } |
@@ -237,7 +237,7 @@ discard block |
||
237 | 237 | if ($policy = $core->getSecurityPolicy()) { |
238 | 238 | while (true) { |
239 | 239 | if (preg_match('{^([a-z]+?)://}i', $resourceId)) { |
240 | - throw new SecurityException('The security policy prevents you to read files from external sources : <em>' . $resourceId . '</em>.'); |
|
240 | + throw new SecurityException('The security policy prevents you to read files from external sources : <em>'.$resourceId.'</em>.'); |
|
241 | 241 | } |
242 | 242 | |
243 | 243 | if ($includePath) { |
@@ -251,7 +251,7 @@ discard block |
||
251 | 251 | break 2; |
252 | 252 | } |
253 | 253 | } |
254 | - throw new SecurityException('The security policy prevents you to read <em>' . $resourceId . '</em>'); |
|
254 | + throw new SecurityException('The security policy prevents you to read <em>'.$resourceId.'</em>'); |
|
255 | 255 | } |
256 | 256 | } |
257 | 257 | |
@@ -271,6 +271,6 @@ discard block |
||
271 | 271 | */ |
272 | 272 | public function getIsModifiedCode() |
273 | 273 | { |
274 | - return '"' . $this->getUid() . '" == filemtime(' . var_export($this->getResourceIdentifier(), true) . ')'; |
|
274 | + return '"'.$this->getUid().'" == filemtime('.var_export($this->getResourceIdentifier(), true).')'; |
|
275 | 275 | } |
276 | 276 | } |
@@ -30,247 +30,247 @@ |
||
30 | 30 | */ |
31 | 31 | class File extends Str |
32 | 32 | { |
33 | - /** |
|
34 | - * Template filename. |
|
35 | - * |
|
36 | - * @var string |
|
37 | - */ |
|
38 | - protected $file; |
|
33 | + /** |
|
34 | + * Template filename. |
|
35 | + * |
|
36 | + * @var string |
|
37 | + */ |
|
38 | + protected $file; |
|
39 | 39 | |
40 | - /** |
|
41 | - * Include path(s) to look into to find this template. |
|
42 | - * |
|
43 | - * @var array |
|
44 | - */ |
|
45 | - protected $includePath = array(); |
|
40 | + /** |
|
41 | + * Include path(s) to look into to find this template. |
|
42 | + * |
|
43 | + * @var array |
|
44 | + */ |
|
45 | + protected $includePath = array(); |
|
46 | 46 | |
47 | - /** |
|
48 | - * Resolved path cache when looking for a file in multiple include paths. |
|
49 | - * this is reset when the include path is changed |
|
50 | - * |
|
51 | - * @var string |
|
52 | - */ |
|
53 | - protected $resolvedPath = null; |
|
47 | + /** |
|
48 | + * Resolved path cache when looking for a file in multiple include paths. |
|
49 | + * this is reset when the include path is changed |
|
50 | + * |
|
51 | + * @var string |
|
52 | + */ |
|
53 | + protected $resolvedPath = null; |
|
54 | 54 | |
55 | - /** |
|
56 | - * Creates a template from a file. |
|
57 | - * |
|
58 | - * @param string $file the path to the template file, make sure it exists |
|
59 | - * @param int $cacheTime duration of the cache validity for this template, |
|
60 | - * if null it defaults to the Dwoo instance that will |
|
61 | - * render this template |
|
62 | - * @param string $cacheId the unique cache identifier of this page or anything else that |
|
63 | - * makes this template's content unique, if null it defaults |
|
64 | - * to the current url |
|
65 | - * @param string $compileId the unique compiled identifier, which is used to distinguish this |
|
66 | - * template from others, if null it defaults to the filename+bits of the path |
|
67 | - * @param mixed $includePath a string for a single path to look into for the given file, or an array of paths |
|
68 | - */ |
|
69 | - public function __construct($file, $cacheTime = null, $cacheId = null, $compileId = null, $includePath = array()) |
|
70 | - { |
|
71 | - parent::__construct($file, $cacheTime, $cacheId, $compileId); |
|
72 | - $this->template = null; |
|
73 | - $this->file = $file; |
|
74 | - $this->name = basename($file); |
|
75 | - $this->setIncludePath($includePath); |
|
76 | - $this->compileId = $this->getResourceIdentifier(); |
|
77 | - } |
|
55 | + /** |
|
56 | + * Creates a template from a file. |
|
57 | + * |
|
58 | + * @param string $file the path to the template file, make sure it exists |
|
59 | + * @param int $cacheTime duration of the cache validity for this template, |
|
60 | + * if null it defaults to the Dwoo instance that will |
|
61 | + * render this template |
|
62 | + * @param string $cacheId the unique cache identifier of this page or anything else that |
|
63 | + * makes this template's content unique, if null it defaults |
|
64 | + * to the current url |
|
65 | + * @param string $compileId the unique compiled identifier, which is used to distinguish this |
|
66 | + * template from others, if null it defaults to the filename+bits of the path |
|
67 | + * @param mixed $includePath a string for a single path to look into for the given file, or an array of paths |
|
68 | + */ |
|
69 | + public function __construct($file, $cacheTime = null, $cacheId = null, $compileId = null, $includePath = array()) |
|
70 | + { |
|
71 | + parent::__construct($file, $cacheTime, $cacheId, $compileId); |
|
72 | + $this->template = null; |
|
73 | + $this->file = $file; |
|
74 | + $this->name = basename($file); |
|
75 | + $this->setIncludePath($includePath); |
|
76 | + $this->compileId = $this->getResourceIdentifier(); |
|
77 | + } |
|
78 | 78 | |
79 | - /** |
|
80 | - * Sets the include path(s) to where the given template filename must be looked up. |
|
81 | - * |
|
82 | - * @param mixed $paths the path to look into, can be string for a single path or an array of paths |
|
83 | - */ |
|
84 | - public function setIncludePath($paths) |
|
85 | - { |
|
86 | - if (is_array($paths) === false) { |
|
87 | - $paths = array($paths); |
|
88 | - } |
|
79 | + /** |
|
80 | + * Sets the include path(s) to where the given template filename must be looked up. |
|
81 | + * |
|
82 | + * @param mixed $paths the path to look into, can be string for a single path or an array of paths |
|
83 | + */ |
|
84 | + public function setIncludePath($paths) |
|
85 | + { |
|
86 | + if (is_array($paths) === false) { |
|
87 | + $paths = array($paths); |
|
88 | + } |
|
89 | 89 | |
90 | - $this->includePath = $paths; |
|
91 | - $this->resolvedPath = null; |
|
92 | - } |
|
90 | + $this->includePath = $paths; |
|
91 | + $this->resolvedPath = null; |
|
92 | + } |
|
93 | 93 | |
94 | - /** |
|
95 | - * Return the current include path(s). |
|
96 | - * |
|
97 | - * @return array |
|
98 | - */ |
|
99 | - public function getIncludePath() |
|
100 | - { |
|
101 | - return $this->includePath; |
|
102 | - } |
|
94 | + /** |
|
95 | + * Return the current include path(s). |
|
96 | + * |
|
97 | + * @return array |
|
98 | + */ |
|
99 | + public function getIncludePath() |
|
100 | + { |
|
101 | + return $this->includePath; |
|
102 | + } |
|
103 | 103 | |
104 | - /** |
|
105 | - * Checks if compiled file is valid (exists and it's the modification is greater or |
|
106 | - * equal to the modification time of the template file). |
|
107 | - * |
|
108 | - * @param string file |
|
109 | - * |
|
110 | - * @return bool True cache file existance and it's modification time |
|
111 | - */ |
|
112 | - protected function isValidCompiledFile($file) |
|
113 | - { |
|
114 | - return parent::isValidCompiledFile($file) && (int)$this->getUid() <= filemtime($file); |
|
115 | - } |
|
104 | + /** |
|
105 | + * Checks if compiled file is valid (exists and it's the modification is greater or |
|
106 | + * equal to the modification time of the template file). |
|
107 | + * |
|
108 | + * @param string file |
|
109 | + * |
|
110 | + * @return bool True cache file existance and it's modification time |
|
111 | + */ |
|
112 | + protected function isValidCompiledFile($file) |
|
113 | + { |
|
114 | + return parent::isValidCompiledFile($file) && (int)$this->getUid() <= filemtime($file); |
|
115 | + } |
|
116 | 116 | |
117 | - /** |
|
118 | - * Returns the template source of this template. |
|
119 | - * |
|
120 | - * @return string |
|
121 | - */ |
|
122 | - public function getSource() |
|
123 | - { |
|
124 | - return file_get_contents($this->getResourceIdentifier()); |
|
125 | - } |
|
117 | + /** |
|
118 | + * Returns the template source of this template. |
|
119 | + * |
|
120 | + * @return string |
|
121 | + */ |
|
122 | + public function getSource() |
|
123 | + { |
|
124 | + return file_get_contents($this->getResourceIdentifier()); |
|
125 | + } |
|
126 | 126 | |
127 | - /** |
|
128 | - * Returns the resource name for this template class. |
|
129 | - * |
|
130 | - * @return string |
|
131 | - */ |
|
132 | - public function getResourceName() |
|
133 | - { |
|
134 | - return 'file'; |
|
135 | - } |
|
127 | + /** |
|
128 | + * Returns the resource name for this template class. |
|
129 | + * |
|
130 | + * @return string |
|
131 | + */ |
|
132 | + public function getResourceName() |
|
133 | + { |
|
134 | + return 'file'; |
|
135 | + } |
|
136 | 136 | |
137 | - /** |
|
138 | - * Returns this template's source filename. |
|
139 | - * |
|
140 | - * @return string |
|
141 | - * @throws DwooException |
|
142 | - */ |
|
143 | - public function getResourceIdentifier() |
|
144 | - { |
|
145 | - if ($this->resolvedPath !== null) { |
|
146 | - return $this->resolvedPath; |
|
147 | - } elseif (array_filter($this->getIncludePath()) == array()) { |
|
148 | - return $this->file; |
|
149 | - } else { |
|
150 | - foreach ($this->getIncludePath() as $path) { |
|
151 | - $path = rtrim($path, DIRECTORY_SEPARATOR); |
|
152 | - if (file_exists($path . DIRECTORY_SEPARATOR . $this->file) === true) { |
|
153 | - return $this->resolvedPath = $path . DIRECTORY_SEPARATOR . $this->file; |
|
154 | - } |
|
155 | - } |
|
137 | + /** |
|
138 | + * Returns this template's source filename. |
|
139 | + * |
|
140 | + * @return string |
|
141 | + * @throws DwooException |
|
142 | + */ |
|
143 | + public function getResourceIdentifier() |
|
144 | + { |
|
145 | + if ($this->resolvedPath !== null) { |
|
146 | + return $this->resolvedPath; |
|
147 | + } elseif (array_filter($this->getIncludePath()) == array()) { |
|
148 | + return $this->file; |
|
149 | + } else { |
|
150 | + foreach ($this->getIncludePath() as $path) { |
|
151 | + $path = rtrim($path, DIRECTORY_SEPARATOR); |
|
152 | + if (file_exists($path . DIRECTORY_SEPARATOR . $this->file) === true) { |
|
153 | + return $this->resolvedPath = $path . DIRECTORY_SEPARATOR . $this->file; |
|
154 | + } |
|
155 | + } |
|
156 | 156 | |
157 | - throw new DwooException('Template "' . $this->file . '" could not be found in any of your include path(s)'); |
|
158 | - } |
|
159 | - } |
|
157 | + throw new DwooException('Template "' . $this->file . '" could not be found in any of your include path(s)'); |
|
158 | + } |
|
159 | + } |
|
160 | 160 | |
161 | - /** |
|
162 | - * Returns an unique value identifying the current version of this template, |
|
163 | - * in this case it's the unix timestamp of the last modification. |
|
164 | - * |
|
165 | - * @return string |
|
166 | - */ |
|
167 | - public function getUid() |
|
168 | - { |
|
169 | - return (string)filemtime($this->getResourceIdentifier()); |
|
170 | - } |
|
161 | + /** |
|
162 | + * Returns an unique value identifying the current version of this template, |
|
163 | + * in this case it's the unix timestamp of the last modification. |
|
164 | + * |
|
165 | + * @return string |
|
166 | + */ |
|
167 | + public function getUid() |
|
168 | + { |
|
169 | + return (string)filemtime($this->getResourceIdentifier()); |
|
170 | + } |
|
171 | 171 | |
172 | - /** |
|
173 | - * Returns a new template object from the given include name, null if no include is |
|
174 | - * possible (resource not found), or false if include is not permitted by this resource type. |
|
175 | - * |
|
176 | - * @param Core $core the dwoo instance requiring it |
|
177 | - * @param mixed $resourceId the filename (relative to this template's dir) of the template to |
|
178 | - * include |
|
179 | - * @param int $cacheTime duration of the cache validity for this template, if null it defaults |
|
180 | - * to the Dwoo instance that will render this template if null it |
|
181 | - * defaults to the Dwoo instance that will render this template if null |
|
182 | - * it defaults to the Dwoo instance that will render this template |
|
183 | - * @param string $cacheId the unique cache identifier of this page or anything else that makes |
|
184 | - * this template's content unique, if null it defaults to the current |
|
185 | - * url makes this template's content unique, if null it defaults to the |
|
186 | - * current url makes this template's content unique, if null it defaults |
|
187 | - * to the current url |
|
188 | - * @param string $compileId the unique compiled identifier, which is used to distinguish this |
|
189 | - * template from others, if null it defaults to the filename+bits of the |
|
190 | - * path template from others, if null it defaults to the filename+bits |
|
191 | - * of the path template from others, if null it defaults to the |
|
192 | - * filename+bits of the path |
|
193 | - * @param ITemplate $parentTemplate the template that is requesting a new template object (through an |
|
194 | - * include, extends or any other plugin) an include, extends or any |
|
195 | - * other plugin) an include, extends or any other plugin) |
|
196 | - * |
|
197 | - * @return TemplateFile|null |
|
198 | - * @throws DwooException |
|
199 | - * @throws SecurityException |
|
200 | - */ |
|
201 | - public static function templateFactory(Core $core, $resourceId, $cacheTime = null, $cacheId = null, |
|
202 | - $compileId = null, ITemplate $parentTemplate = null) |
|
203 | - { |
|
204 | - if (DIRECTORY_SEPARATOR === '\\') { |
|
205 | - $resourceId = str_replace(array("\t", "\n", "\r", "\f", "\v"), array( |
|
206 | - '\\t', |
|
207 | - '\\n', |
|
208 | - '\\r', |
|
209 | - '\\f', |
|
210 | - '\\v' |
|
211 | - ), $resourceId); |
|
212 | - } |
|
213 | - $resourceId = strtr($resourceId, '\\', '/'); |
|
172 | + /** |
|
173 | + * Returns a new template object from the given include name, null if no include is |
|
174 | + * possible (resource not found), or false if include is not permitted by this resource type. |
|
175 | + * |
|
176 | + * @param Core $core the dwoo instance requiring it |
|
177 | + * @param mixed $resourceId the filename (relative to this template's dir) of the template to |
|
178 | + * include |
|
179 | + * @param int $cacheTime duration of the cache validity for this template, if null it defaults |
|
180 | + * to the Dwoo instance that will render this template if null it |
|
181 | + * defaults to the Dwoo instance that will render this template if null |
|
182 | + * it defaults to the Dwoo instance that will render this template |
|
183 | + * @param string $cacheId the unique cache identifier of this page or anything else that makes |
|
184 | + * this template's content unique, if null it defaults to the current |
|
185 | + * url makes this template's content unique, if null it defaults to the |
|
186 | + * current url makes this template's content unique, if null it defaults |
|
187 | + * to the current url |
|
188 | + * @param string $compileId the unique compiled identifier, which is used to distinguish this |
|
189 | + * template from others, if null it defaults to the filename+bits of the |
|
190 | + * path template from others, if null it defaults to the filename+bits |
|
191 | + * of the path template from others, if null it defaults to the |
|
192 | + * filename+bits of the path |
|
193 | + * @param ITemplate $parentTemplate the template that is requesting a new template object (through an |
|
194 | + * include, extends or any other plugin) an include, extends or any |
|
195 | + * other plugin) an include, extends or any other plugin) |
|
196 | + * |
|
197 | + * @return TemplateFile|null |
|
198 | + * @throws DwooException |
|
199 | + * @throws SecurityException |
|
200 | + */ |
|
201 | + public static function templateFactory(Core $core, $resourceId, $cacheTime = null, $cacheId = null, |
|
202 | + $compileId = null, ITemplate $parentTemplate = null) |
|
203 | + { |
|
204 | + if (DIRECTORY_SEPARATOR === '\\') { |
|
205 | + $resourceId = str_replace(array("\t", "\n", "\r", "\f", "\v"), array( |
|
206 | + '\\t', |
|
207 | + '\\n', |
|
208 | + '\\r', |
|
209 | + '\\f', |
|
210 | + '\\v' |
|
211 | + ), $resourceId); |
|
212 | + } |
|
213 | + $resourceId = strtr($resourceId, '\\', '/'); |
|
214 | 214 | |
215 | - $includePath = null; |
|
215 | + $includePath = null; |
|
216 | 216 | |
217 | - if (file_exists($resourceId) === false) { |
|
218 | - if ($parentTemplate === null) { |
|
219 | - $parentTemplate = $core->getTemplate(); |
|
220 | - } |
|
221 | - if ($parentTemplate instanceof self) { |
|
222 | - if ($includePath = $parentTemplate->getIncludePath()) { |
|
223 | - if (strstr($resourceId, '../')) { |
|
224 | - throw new DwooException('When using an include path you can not reference a template into a parent directory (using ../)'); |
|
225 | - } |
|
226 | - } else { |
|
227 | - $resourceId = dirname($parentTemplate->getResourceIdentifier()) . DIRECTORY_SEPARATOR . $resourceId; |
|
228 | - if (file_exists($resourceId) === false) { |
|
229 | - return null; |
|
230 | - } |
|
231 | - } |
|
232 | - } else { |
|
233 | - return null; |
|
234 | - } |
|
235 | - } |
|
217 | + if (file_exists($resourceId) === false) { |
|
218 | + if ($parentTemplate === null) { |
|
219 | + $parentTemplate = $core->getTemplate(); |
|
220 | + } |
|
221 | + if ($parentTemplate instanceof self) { |
|
222 | + if ($includePath = $parentTemplate->getIncludePath()) { |
|
223 | + if (strstr($resourceId, '../')) { |
|
224 | + throw new DwooException('When using an include path you can not reference a template into a parent directory (using ../)'); |
|
225 | + } |
|
226 | + } else { |
|
227 | + $resourceId = dirname($parentTemplate->getResourceIdentifier()) . DIRECTORY_SEPARATOR . $resourceId; |
|
228 | + if (file_exists($resourceId) === false) { |
|
229 | + return null; |
|
230 | + } |
|
231 | + } |
|
232 | + } else { |
|
233 | + return null; |
|
234 | + } |
|
235 | + } |
|
236 | 236 | |
237 | - if ($policy = $core->getSecurityPolicy()) { |
|
238 | - while (true) { |
|
239 | - if (preg_match('{^([a-z]+?)://}i', $resourceId)) { |
|
240 | - throw new SecurityException('The security policy prevents you to read files from external sources : <em>' . $resourceId . '</em>.'); |
|
241 | - } |
|
237 | + if ($policy = $core->getSecurityPolicy()) { |
|
238 | + while (true) { |
|
239 | + if (preg_match('{^([a-z]+?)://}i', $resourceId)) { |
|
240 | + throw new SecurityException('The security policy prevents you to read files from external sources : <em>' . $resourceId . '</em>.'); |
|
241 | + } |
|
242 | 242 | |
243 | - if ($includePath) { |
|
244 | - break; |
|
245 | - } |
|
243 | + if ($includePath) { |
|
244 | + break; |
|
245 | + } |
|
246 | 246 | |
247 | - $resourceId = realpath($resourceId); |
|
248 | - $dirs = $policy->getAllowedDirectories(); |
|
249 | - foreach ($dirs as $dir => $dummy) { |
|
250 | - if (strpos($resourceId, $dir) === 0) { |
|
251 | - break 2; |
|
252 | - } |
|
253 | - } |
|
254 | - throw new SecurityException('The security policy prevents you to read <em>' . $resourceId . '</em>'); |
|
255 | - } |
|
256 | - } |
|
247 | + $resourceId = realpath($resourceId); |
|
248 | + $dirs = $policy->getAllowedDirectories(); |
|
249 | + foreach ($dirs as $dir => $dummy) { |
|
250 | + if (strpos($resourceId, $dir) === 0) { |
|
251 | + break 2; |
|
252 | + } |
|
253 | + } |
|
254 | + throw new SecurityException('The security policy prevents you to read <em>' . $resourceId . '</em>'); |
|
255 | + } |
|
256 | + } |
|
257 | 257 | |
258 | - $class = 'Dwoo\Template\File'; |
|
259 | - if ($parentTemplate) { |
|
260 | - $class = get_class($parentTemplate); |
|
261 | - } |
|
258 | + $class = 'Dwoo\Template\File'; |
|
259 | + if ($parentTemplate) { |
|
260 | + $class = get_class($parentTemplate); |
|
261 | + } |
|
262 | 262 | |
263 | - return new $class($resourceId, $cacheTime, $cacheId, $compileId, $includePath); |
|
264 | - } |
|
263 | + return new $class($resourceId, $cacheTime, $cacheId, $compileId, $includePath); |
|
264 | + } |
|
265 | 265 | |
266 | - /** |
|
267 | - * Returns some php code that will check if this template has been modified or not. |
|
268 | - * if the function returns null, the template will be instanciated and then the Uid checked |
|
269 | - * |
|
270 | - * @return string |
|
271 | - */ |
|
272 | - public function getIsModifiedCode() |
|
273 | - { |
|
274 | - return '"' . $this->getUid() . '" == filemtime(' . var_export($this->getResourceIdentifier(), true) . ')'; |
|
275 | - } |
|
266 | + /** |
|
267 | + * Returns some php code that will check if this template has been modified or not. |
|
268 | + * if the function returns null, the template will be instanciated and then the Uid checked |
|
269 | + * |
|
270 | + * @return string |
|
271 | + */ |
|
272 | + public function getIsModifiedCode() |
|
273 | + { |
|
274 | + return '"' . $this->getUid() . '" == filemtime(' . var_export($this->getResourceIdentifier(), true) . ')'; |
|
275 | + } |
|
276 | 276 | } |
@@ -24,241 +24,241 @@ |
||
24 | 24 | */ |
25 | 25 | class Data implements IDataProvider |
26 | 26 | { |
27 | - /** |
|
28 | - * Data array. |
|
29 | - * |
|
30 | - * @var array |
|
31 | - */ |
|
32 | - protected $data = array(); |
|
27 | + /** |
|
28 | + * Data array. |
|
29 | + * |
|
30 | + * @var array |
|
31 | + */ |
|
32 | + protected $data = array(); |
|
33 | 33 | |
34 | - /** |
|
35 | - * Returns the data array. |
|
36 | - * |
|
37 | - * @return array |
|
38 | - */ |
|
39 | - public function getData() |
|
40 | - { |
|
41 | - return $this->data; |
|
42 | - } |
|
34 | + /** |
|
35 | + * Returns the data array. |
|
36 | + * |
|
37 | + * @return array |
|
38 | + */ |
|
39 | + public function getData() |
|
40 | + { |
|
41 | + return $this->data; |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * Clears a the entire data or only the given key. |
|
46 | - * |
|
47 | - * @param array|string $name clears only one value if you give a name, multiple values if |
|
48 | - * you give an array of names, or the entire data if left null |
|
49 | - */ |
|
50 | - public function clear($name = null) |
|
51 | - { |
|
52 | - if ($name === null) { |
|
53 | - $this->data = array(); |
|
54 | - } elseif (is_array($name)) { |
|
55 | - foreach ($name as $index) { |
|
56 | - unset($this->data[$index]); |
|
57 | - } |
|
58 | - } else { |
|
59 | - unset($this->data[$name]); |
|
60 | - } |
|
61 | - } |
|
44 | + /** |
|
45 | + * Clears a the entire data or only the given key. |
|
46 | + * |
|
47 | + * @param array|string $name clears only one value if you give a name, multiple values if |
|
48 | + * you give an array of names, or the entire data if left null |
|
49 | + */ |
|
50 | + public function clear($name = null) |
|
51 | + { |
|
52 | + if ($name === null) { |
|
53 | + $this->data = array(); |
|
54 | + } elseif (is_array($name)) { |
|
55 | + foreach ($name as $index) { |
|
56 | + unset($this->data[$index]); |
|
57 | + } |
|
58 | + } else { |
|
59 | + unset($this->data[$name]); |
|
60 | + } |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * Overwrites the entire data with the given array. |
|
65 | - * |
|
66 | - * @param array $data the new data array to use |
|
67 | - */ |
|
68 | - public function setData(array $data) |
|
69 | - { |
|
70 | - $this->data = $data; |
|
71 | - } |
|
63 | + /** |
|
64 | + * Overwrites the entire data with the given array. |
|
65 | + * |
|
66 | + * @param array $data the new data array to use |
|
67 | + */ |
|
68 | + public function setData(array $data) |
|
69 | + { |
|
70 | + $this->data = $data; |
|
71 | + } |
|
72 | 72 | |
73 | - /** |
|
74 | - * merges the given array(s) with the current data with array_merge. |
|
75 | - * |
|
76 | - * @param array $data the array to merge |
|
77 | - */ |
|
78 | - public function mergeData(array $data) |
|
79 | - { |
|
80 | - $args = func_get_args(); |
|
81 | - foreach ($args as $key => $v) { |
|
82 | - if (is_array($v)) { |
|
83 | - $this->data = array_merge($this->data, $v); |
|
84 | - } |
|
85 | - } |
|
86 | - } |
|
73 | + /** |
|
74 | + * merges the given array(s) with the current data with array_merge. |
|
75 | + * |
|
76 | + * @param array $data the array to merge |
|
77 | + */ |
|
78 | + public function mergeData(array $data) |
|
79 | + { |
|
80 | + $args = func_get_args(); |
|
81 | + foreach ($args as $key => $v) { |
|
82 | + if (is_array($v)) { |
|
83 | + $this->data = array_merge($this->data, $v); |
|
84 | + } |
|
85 | + } |
|
86 | + } |
|
87 | 87 | |
88 | - /** |
|
89 | - * Assigns a value or an array of values to the data object. |
|
90 | - * |
|
91 | - * @param array|string $name an associative array of multiple (index=>value) or a string |
|
92 | - * that is the index to use, i.e. a value assigned to "foo" will be |
|
93 | - * accessible in the template through {$foo} |
|
94 | - * @param mixed $val the value to assign, or null if $name was an array |
|
95 | - */ |
|
96 | - public function assign($name, $val = null) |
|
97 | - { |
|
98 | - if (is_array($name)) { |
|
99 | - reset($name); |
|
100 | - foreach ($name as $k => $v){ |
|
101 | - $this->data[$k] = $v; |
|
102 | - } |
|
103 | - } else { |
|
104 | - $this->data[$name] = $val; |
|
105 | - } |
|
106 | - } |
|
88 | + /** |
|
89 | + * Assigns a value or an array of values to the data object. |
|
90 | + * |
|
91 | + * @param array|string $name an associative array of multiple (index=>value) or a string |
|
92 | + * that is the index to use, i.e. a value assigned to "foo" will be |
|
93 | + * accessible in the template through {$foo} |
|
94 | + * @param mixed $val the value to assign, or null if $name was an array |
|
95 | + */ |
|
96 | + public function assign($name, $val = null) |
|
97 | + { |
|
98 | + if (is_array($name)) { |
|
99 | + reset($name); |
|
100 | + foreach ($name as $k => $v){ |
|
101 | + $this->data[$k] = $v; |
|
102 | + } |
|
103 | + } else { |
|
104 | + $this->data[$name] = $val; |
|
105 | + } |
|
106 | + } |
|
107 | 107 | |
108 | - /** |
|
109 | - * Allows to assign variables using the object syntax. |
|
110 | - * |
|
111 | - * @param string $name the variable name |
|
112 | - * @param string $value the value to assign to it |
|
113 | - */ |
|
114 | - public function __set($name, $value) |
|
115 | - { |
|
116 | - $this->assign($name, $value); |
|
117 | - } |
|
108 | + /** |
|
109 | + * Allows to assign variables using the object syntax. |
|
110 | + * |
|
111 | + * @param string $name the variable name |
|
112 | + * @param string $value the value to assign to it |
|
113 | + */ |
|
114 | + public function __set($name, $value) |
|
115 | + { |
|
116 | + $this->assign($name, $value); |
|
117 | + } |
|
118 | 118 | |
119 | - /** |
|
120 | - * Assigns a value by reference to the data object. |
|
121 | - * |
|
122 | - * @param string $name the index to use, i.e. a value assigned to "foo" will be |
|
123 | - * accessible in the template through {$foo} |
|
124 | - * @param mixed $val the value to assign by reference |
|
125 | - */ |
|
126 | - public function assignByRef($name, &$val) |
|
127 | - { |
|
128 | - $this->data[$name] = &$val; |
|
129 | - } |
|
119 | + /** |
|
120 | + * Assigns a value by reference to the data object. |
|
121 | + * |
|
122 | + * @param string $name the index to use, i.e. a value assigned to "foo" will be |
|
123 | + * accessible in the template through {$foo} |
|
124 | + * @param mixed $val the value to assign by reference |
|
125 | + */ |
|
126 | + public function assignByRef($name, &$val) |
|
127 | + { |
|
128 | + $this->data[$name] = &$val; |
|
129 | + } |
|
130 | 130 | |
131 | - /** |
|
132 | - * Appends values or an array of values to the data object. |
|
133 | - * |
|
134 | - * @param array|string $name an associative array of multiple (index=>value) or a string |
|
135 | - * that is the index to use, i.e. a value assigned to "foo" will be |
|
136 | - * accessible in the template through {$foo} |
|
137 | - * @param mixed $val the value to assign, or null if $name was an array |
|
138 | - * @param bool $merge true to merge data or false to append, defaults to false |
|
139 | - */ |
|
140 | - public function append($name, $val = null, $merge = false) |
|
141 | - { |
|
142 | - if (is_array($name)) { |
|
143 | - foreach ($name as $key => $val) { |
|
144 | - if (isset($this->data[$key]) && !is_array($this->data[$key])) { |
|
145 | - settype($this->data[$key], 'array'); |
|
146 | - } |
|
131 | + /** |
|
132 | + * Appends values or an array of values to the data object. |
|
133 | + * |
|
134 | + * @param array|string $name an associative array of multiple (index=>value) or a string |
|
135 | + * that is the index to use, i.e. a value assigned to "foo" will be |
|
136 | + * accessible in the template through {$foo} |
|
137 | + * @param mixed $val the value to assign, or null if $name was an array |
|
138 | + * @param bool $merge true to merge data or false to append, defaults to false |
|
139 | + */ |
|
140 | + public function append($name, $val = null, $merge = false) |
|
141 | + { |
|
142 | + if (is_array($name)) { |
|
143 | + foreach ($name as $key => $val) { |
|
144 | + if (isset($this->data[$key]) && !is_array($this->data[$key])) { |
|
145 | + settype($this->data[$key], 'array'); |
|
146 | + } |
|
147 | 147 | |
148 | - if ($merge === true && is_array($val)) { |
|
149 | - $this->data[$key] = $val + $this->data[$key]; |
|
150 | - } else { |
|
151 | - $this->data[$key][] = $val; |
|
152 | - } |
|
153 | - } |
|
154 | - } elseif ($val !== null) { |
|
155 | - if (isset($this->data[$name]) && !is_array($this->data[$name])) { |
|
156 | - settype($this->data[$name], 'array'); |
|
157 | - } elseif (!isset($this->data[$name])) { |
|
158 | - $this->data[$name] = array(); |
|
159 | - } |
|
148 | + if ($merge === true && is_array($val)) { |
|
149 | + $this->data[$key] = $val + $this->data[$key]; |
|
150 | + } else { |
|
151 | + $this->data[$key][] = $val; |
|
152 | + } |
|
153 | + } |
|
154 | + } elseif ($val !== null) { |
|
155 | + if (isset($this->data[$name]) && !is_array($this->data[$name])) { |
|
156 | + settype($this->data[$name], 'array'); |
|
157 | + } elseif (!isset($this->data[$name])) { |
|
158 | + $this->data[$name] = array(); |
|
159 | + } |
|
160 | 160 | |
161 | - if ($merge === true && is_array($val)) { |
|
162 | - $this->data[$name] = $val + $this->data[$name]; |
|
163 | - } else { |
|
164 | - $this->data[$name][] = $val; |
|
165 | - } |
|
166 | - } |
|
167 | - } |
|
161 | + if ($merge === true && is_array($val)) { |
|
162 | + $this->data[$name] = $val + $this->data[$name]; |
|
163 | + } else { |
|
164 | + $this->data[$name][] = $val; |
|
165 | + } |
|
166 | + } |
|
167 | + } |
|
168 | 168 | |
169 | - /** |
|
170 | - * Appends a value by reference to the data object. |
|
171 | - * |
|
172 | - * @param string $name the index to use, i.e. a value assigned to "foo" will be |
|
173 | - * accessible in the template through {$foo} |
|
174 | - * @param mixed $val the value to append by reference |
|
175 | - * @param bool $merge true to merge data or false to append, defaults to false |
|
176 | - */ |
|
177 | - public function appendByRef($name, &$val, $merge = false) |
|
178 | - { |
|
179 | - if (isset($this->data[$name]) && !is_array($this->data[$name])) { |
|
180 | - settype($this->data[$name], 'array'); |
|
181 | - } |
|
169 | + /** |
|
170 | + * Appends a value by reference to the data object. |
|
171 | + * |
|
172 | + * @param string $name the index to use, i.e. a value assigned to "foo" will be |
|
173 | + * accessible in the template through {$foo} |
|
174 | + * @param mixed $val the value to append by reference |
|
175 | + * @param bool $merge true to merge data or false to append, defaults to false |
|
176 | + */ |
|
177 | + public function appendByRef($name, &$val, $merge = false) |
|
178 | + { |
|
179 | + if (isset($this->data[$name]) && !is_array($this->data[$name])) { |
|
180 | + settype($this->data[$name], 'array'); |
|
181 | + } |
|
182 | 182 | |
183 | - if ($merge === true && is_array($val)) { |
|
184 | - foreach ($val as $key => &$value) { |
|
185 | - $this->data[$name][$key] = &$value; |
|
186 | - } |
|
187 | - } else { |
|
188 | - $this->data[$name][] = &$val; |
|
189 | - } |
|
190 | - } |
|
183 | + if ($merge === true && is_array($val)) { |
|
184 | + foreach ($val as $key => &$value) { |
|
185 | + $this->data[$name][$key] = &$value; |
|
186 | + } |
|
187 | + } else { |
|
188 | + $this->data[$name][] = &$val; |
|
189 | + } |
|
190 | + } |
|
191 | 191 | |
192 | - /** |
|
193 | - * Returns true if the variable has been assigned already, false otherwise. |
|
194 | - * |
|
195 | - * @param string $name the variable name |
|
196 | - * |
|
197 | - * @return bool |
|
198 | - */ |
|
199 | - public function isAssigned($name) |
|
200 | - { |
|
201 | - return isset($this->data[$name]); |
|
202 | - } |
|
192 | + /** |
|
193 | + * Returns true if the variable has been assigned already, false otherwise. |
|
194 | + * |
|
195 | + * @param string $name the variable name |
|
196 | + * |
|
197 | + * @return bool |
|
198 | + */ |
|
199 | + public function isAssigned($name) |
|
200 | + { |
|
201 | + return isset($this->data[$name]); |
|
202 | + } |
|
203 | 203 | |
204 | - /** |
|
205 | - * Supports calls to isset($dwoo->var). |
|
206 | - * |
|
207 | - * @param string $name the variable name |
|
208 | - * |
|
209 | - * @return bool |
|
210 | - */ |
|
211 | - public function __isset($name) |
|
212 | - { |
|
213 | - return isset($this->data[$name]); |
|
214 | - } |
|
204 | + /** |
|
205 | + * Supports calls to isset($dwoo->var). |
|
206 | + * |
|
207 | + * @param string $name the variable name |
|
208 | + * |
|
209 | + * @return bool |
|
210 | + */ |
|
211 | + public function __isset($name) |
|
212 | + { |
|
213 | + return isset($this->data[$name]); |
|
214 | + } |
|
215 | 215 | |
216 | - /** |
|
217 | - * Unassigns/removes a variable. |
|
218 | - * |
|
219 | - * @param string $name the variable name |
|
220 | - */ |
|
221 | - public function unassign($name) |
|
222 | - { |
|
223 | - unset($this->data[$name]); |
|
224 | - } |
|
216 | + /** |
|
217 | + * Unassigns/removes a variable. |
|
218 | + * |
|
219 | + * @param string $name the variable name |
|
220 | + */ |
|
221 | + public function unassign($name) |
|
222 | + { |
|
223 | + unset($this->data[$name]); |
|
224 | + } |
|
225 | 225 | |
226 | - /** |
|
227 | - * Supports unsetting variables using the object syntax. |
|
228 | - * |
|
229 | - * @param string $name the variable name |
|
230 | - */ |
|
231 | - public function __unset($name) |
|
232 | - { |
|
233 | - unset($this->data[$name]); |
|
234 | - } |
|
226 | + /** |
|
227 | + * Supports unsetting variables using the object syntax. |
|
228 | + * |
|
229 | + * @param string $name the variable name |
|
230 | + */ |
|
231 | + public function __unset($name) |
|
232 | + { |
|
233 | + unset($this->data[$name]); |
|
234 | + } |
|
235 | 235 | |
236 | - /** |
|
237 | - * Returns a variable if it was assigned. |
|
238 | - * |
|
239 | - * @param string $name the variable name |
|
240 | - * |
|
241 | - * @return mixed |
|
242 | - */ |
|
243 | - public function get($name) |
|
244 | - { |
|
245 | - return $this->__get($name); |
|
246 | - } |
|
236 | + /** |
|
237 | + * Returns a variable if it was assigned. |
|
238 | + * |
|
239 | + * @param string $name the variable name |
|
240 | + * |
|
241 | + * @return mixed |
|
242 | + */ |
|
243 | + public function get($name) |
|
244 | + { |
|
245 | + return $this->__get($name); |
|
246 | + } |
|
247 | 247 | |
248 | - /** |
|
249 | - * Allows to read variables using the object syntax. |
|
250 | - * |
|
251 | - * @param string $name the variable name |
|
252 | - * |
|
253 | - * @return mixed |
|
254 | - * @throws Exception |
|
255 | - */ |
|
256 | - public function __get($name) |
|
257 | - { |
|
258 | - if (isset($this->data[$name])) { |
|
259 | - return $this->data[$name]; |
|
260 | - } else { |
|
261 | - throw new Exception('Tried to read a value that was not assigned yet : "' . $name . '"'); |
|
262 | - } |
|
263 | - } |
|
248 | + /** |
|
249 | + * Allows to read variables using the object syntax. |
|
250 | + * |
|
251 | + * @param string $name the variable name |
|
252 | + * |
|
253 | + * @return mixed |
|
254 | + * @throws Exception |
|
255 | + */ |
|
256 | + public function __get($name) |
|
257 | + { |
|
258 | + if (isset($this->data[$name])) { |
|
259 | + return $this->data[$name]; |
|
260 | + } else { |
|
261 | + throw new Exception('Tried to read a value that was not assigned yet : "' . $name . '"'); |
|
262 | + } |
|
263 | + } |
|
264 | 264 | } |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | { |
98 | 98 | if (is_array($name)) { |
99 | 99 | reset($name); |
100 | - foreach ($name as $k => $v){ |
|
100 | + foreach ($name as $k => $v) { |
|
101 | 101 | $this->data[$k] = $v; |
102 | 102 | } |
103 | 103 | } else { |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | } |
147 | 147 | |
148 | 148 | if ($merge === true && is_array($val)) { |
149 | - $this->data[$key] = $val + $this->data[$key]; |
|
149 | + $this->data[$key] = $val+$this->data[$key]; |
|
150 | 150 | } else { |
151 | 151 | $this->data[$key][] = $val; |
152 | 152 | } |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | } |
160 | 160 | |
161 | 161 | if ($merge === true && is_array($val)) { |
162 | - $this->data[$name] = $val + $this->data[$name]; |
|
162 | + $this->data[$name] = $val+$this->data[$name]; |
|
163 | 163 | } else { |
164 | 164 | $this->data[$name][] = $val; |
165 | 165 | } |
@@ -258,7 +258,7 @@ discard block |
||
258 | 258 | if (isset($this->data[$name])) { |
259 | 259 | return $this->data[$name]; |
260 | 260 | } else { |
261 | - throw new Exception('Tried to read a value that was not assigned yet : "' . $name . '"'); |
|
261 | + throw new Exception('Tried to read a value that was not assigned yet : "'.$name.'"'); |
|
262 | 262 | } |
263 | 263 | } |
264 | 264 | } |
@@ -23,139 +23,139 @@ |
||
23 | 23 | */ |
24 | 24 | interface ITemplate |
25 | 25 | { |
26 | - /** |
|
27 | - * Returns the cache duration for this template. |
|
28 | - * defaults to null if it was not provided |
|
29 | - * |
|
30 | - * @return int|null |
|
31 | - */ |
|
32 | - public function getCacheTime(); |
|
26 | + /** |
|
27 | + * Returns the cache duration for this template. |
|
28 | + * defaults to null if it was not provided |
|
29 | + * |
|
30 | + * @return int|null |
|
31 | + */ |
|
32 | + public function getCacheTime(); |
|
33 | 33 | |
34 | - /** |
|
35 | - * Sets the cache duration for this template. |
|
36 | - * can be used to set it after the object is created if you did not provide |
|
37 | - * it in the constructor |
|
38 | - * |
|
39 | - * @param int $seconds duration of the cache validity for this template, if |
|
40 | - * null it defaults to the Dwoo instance's cache time. 0 = disable and |
|
41 | - * -1 = infinite cache |
|
42 | - */ |
|
43 | - public function setCacheTime($seconds = null); |
|
34 | + /** |
|
35 | + * Sets the cache duration for this template. |
|
36 | + * can be used to set it after the object is created if you did not provide |
|
37 | + * it in the constructor |
|
38 | + * |
|
39 | + * @param int $seconds duration of the cache validity for this template, if |
|
40 | + * null it defaults to the Dwoo instance's cache time. 0 = disable and |
|
41 | + * -1 = infinite cache |
|
42 | + */ |
|
43 | + public function setCacheTime($seconds = null); |
|
44 | 44 | |
45 | - /** |
|
46 | - * Returns the cached template output file name, true if it's cache-able but not cached |
|
47 | - * or false if it's not cached. |
|
48 | - * |
|
49 | - * @param Core $core the dwoo instance that requests it |
|
50 | - * |
|
51 | - * @return string|bool |
|
52 | - */ |
|
53 | - public function getCachedTemplate(Core $core); |
|
45 | + /** |
|
46 | + * Returns the cached template output file name, true if it's cache-able but not cached |
|
47 | + * or false if it's not cached. |
|
48 | + * |
|
49 | + * @param Core $core the dwoo instance that requests it |
|
50 | + * |
|
51 | + * @return string|bool |
|
52 | + */ |
|
53 | + public function getCachedTemplate(Core $core); |
|
54 | 54 | |
55 | - /** |
|
56 | - * Caches the provided output into the cache file. |
|
57 | - * |
|
58 | - * @param Core $core the dwoo instance that requests it |
|
59 | - * @param string $output the template output |
|
60 | - * |
|
61 | - * @return mixed full path of the cached file or false upon failure |
|
62 | - */ |
|
63 | - public function cache(Core $core, $output); |
|
55 | + /** |
|
56 | + * Caches the provided output into the cache file. |
|
57 | + * |
|
58 | + * @param Core $core the dwoo instance that requests it |
|
59 | + * @param string $output the template output |
|
60 | + * |
|
61 | + * @return mixed full path of the cached file or false upon failure |
|
62 | + */ |
|
63 | + public function cache(Core $core, $output); |
|
64 | 64 | |
65 | - /** |
|
66 | - * Clears the cached template if it's older than the given time. |
|
67 | - * |
|
68 | - * @param Core $core the dwoo instance that was used to cache that template |
|
69 | - * @param int $olderThan minimum time (in seconds) required for the cache to be cleared |
|
70 | - * |
|
71 | - * @return bool true if the cache was not present or if it was deleted, false if it remains there |
|
72 | - */ |
|
73 | - public function clearCache(Core $core, $olderThan = - 1); |
|
65 | + /** |
|
66 | + * Clears the cached template if it's older than the given time. |
|
67 | + * |
|
68 | + * @param Core $core the dwoo instance that was used to cache that template |
|
69 | + * @param int $olderThan minimum time (in seconds) required for the cache to be cleared |
|
70 | + * |
|
71 | + * @return bool true if the cache was not present or if it was deleted, false if it remains there |
|
72 | + */ |
|
73 | + public function clearCache(Core $core, $olderThan = - 1); |
|
74 | 74 | |
75 | - /** |
|
76 | - * Returns the compiled template file name. |
|
77 | - * |
|
78 | - * @param Core $core the dwoo instance that requests it |
|
79 | - * @param ICompiler $compiler the compiler that must be used |
|
80 | - * |
|
81 | - * @return string |
|
82 | - */ |
|
83 | - public function getCompiledTemplate(Core $core, ICompiler $compiler = null); |
|
75 | + /** |
|
76 | + * Returns the compiled template file name. |
|
77 | + * |
|
78 | + * @param Core $core the dwoo instance that requests it |
|
79 | + * @param ICompiler $compiler the compiler that must be used |
|
80 | + * |
|
81 | + * @return string |
|
82 | + */ |
|
83 | + public function getCompiledTemplate(Core $core, ICompiler $compiler = null); |
|
84 | 84 | |
85 | - /** |
|
86 | - * Returns the template name. |
|
87 | - * |
|
88 | - * @return string |
|
89 | - */ |
|
90 | - public function getName(); |
|
85 | + /** |
|
86 | + * Returns the template name. |
|
87 | + * |
|
88 | + * @return string |
|
89 | + */ |
|
90 | + public function getName(); |
|
91 | 91 | |
92 | - /** |
|
93 | - * Returns the resource name for this template class. |
|
94 | - * |
|
95 | - * @return string |
|
96 | - */ |
|
97 | - public function getResourceName(); |
|
92 | + /** |
|
93 | + * Returns the resource name for this template class. |
|
94 | + * |
|
95 | + * @return string |
|
96 | + */ |
|
97 | + public function getResourceName(); |
|
98 | 98 | |
99 | - /** |
|
100 | - * Returns the resource identifier for this template or false if it has no identifier. |
|
101 | - * |
|
102 | - * @return string|false |
|
103 | - */ |
|
104 | - public function getResourceIdentifier(); |
|
99 | + /** |
|
100 | + * Returns the resource identifier for this template or false if it has no identifier. |
|
101 | + * |
|
102 | + * @return string|false |
|
103 | + */ |
|
104 | + public function getResourceIdentifier(); |
|
105 | 105 | |
106 | - /** |
|
107 | - * Returns the template source of this template. |
|
108 | - * |
|
109 | - * @return string |
|
110 | - */ |
|
111 | - public function getSource(); |
|
106 | + /** |
|
107 | + * Returns the template source of this template. |
|
108 | + * |
|
109 | + * @return string |
|
110 | + */ |
|
111 | + public function getSource(); |
|
112 | 112 | |
113 | - /** |
|
114 | - * Returns an unique string identifying the current version of this template, |
|
115 | - * for example a timestamp of the last modified date or a hash of the template source. |
|
116 | - * |
|
117 | - * @return string |
|
118 | - */ |
|
119 | - public function getUid(); |
|
113 | + /** |
|
114 | + * Returns an unique string identifying the current version of this template, |
|
115 | + * for example a timestamp of the last modified date or a hash of the template source. |
|
116 | + * |
|
117 | + * @return string |
|
118 | + */ |
|
119 | + public function getUid(); |
|
120 | 120 | |
121 | - /** |
|
122 | - * Returns the compiler used by this template, if it was just compiled, or null. |
|
123 | - * |
|
124 | - * @return ICompiler |
|
125 | - */ |
|
126 | - public function getCompiler(); |
|
121 | + /** |
|
122 | + * Returns the compiler used by this template, if it was just compiled, or null. |
|
123 | + * |
|
124 | + * @return ICompiler |
|
125 | + */ |
|
126 | + public function getCompiler(); |
|
127 | 127 | |
128 | - /** |
|
129 | - * Returns some php code that will check if this template has been modified or not. |
|
130 | - * if the function returns null, the template will be instanciated and then the Uid checked |
|
131 | - * |
|
132 | - * @return string |
|
133 | - */ |
|
134 | - public function getIsModifiedCode(); |
|
128 | + /** |
|
129 | + * Returns some php code that will check if this template has been modified or not. |
|
130 | + * if the function returns null, the template will be instanciated and then the Uid checked |
|
131 | + * |
|
132 | + * @return string |
|
133 | + */ |
|
134 | + public function getIsModifiedCode(); |
|
135 | 135 | |
136 | - /** |
|
137 | - * Returns a new template object from the given resource identifier, null if no include is |
|
138 | - * possible (resource not found), or false if include is not permitted by this resource type. |
|
139 | - * this method should also check if $dwoo->getSecurityPolicy() is null or not and do the |
|
140 | - * necessary permission checks if required, if the security policy prevents the template |
|
141 | - * generation it should throw a new Security\Exception with a relevant message |
|
142 | - * |
|
143 | - * @param Core $core |
|
144 | - * @param mixed $resourceId the resource identifier |
|
145 | - * @param int $cacheTime duration of the cache validity for this template, if null it defaults to the |
|
146 | - * Dwoo instance that will render this template if null it defaults to the Dwoo |
|
147 | - * instance that will render this template |
|
148 | - * @param string $cacheId the unique cache identifier of this page or anything else that makes this |
|
149 | - * template's content unique, if null it defaults to the current url makes this |
|
150 | - * template's content unique, if null it defaults to the current url |
|
151 | - * @param string $compileId the unique compiled identifier, which is used to distinguish this template from |
|
152 | - * others, if null it defaults to the filename+bits of the path template from |
|
153 | - * others, if null it defaults to the filename+bits of the path |
|
154 | - * @param ITemplate $parentTemplate the template that is requesting a new template object (through an include, |
|
155 | - * extends or any other plugin) an include, extends or any other plugin) |
|
156 | - * |
|
157 | - * @return ITemplate|false|null |
|
158 | - */ |
|
159 | - public static function templateFactory(Core $core, $resourceId, $cacheTime = null, $cacheId = null, |
|
160 | - $compileId = null, ITemplate $parentTemplate = null); |
|
136 | + /** |
|
137 | + * Returns a new template object from the given resource identifier, null if no include is |
|
138 | + * possible (resource not found), or false if include is not permitted by this resource type. |
|
139 | + * this method should also check if $dwoo->getSecurityPolicy() is null or not and do the |
|
140 | + * necessary permission checks if required, if the security policy prevents the template |
|
141 | + * generation it should throw a new Security\Exception with a relevant message |
|
142 | + * |
|
143 | + * @param Core $core |
|
144 | + * @param mixed $resourceId the resource identifier |
|
145 | + * @param int $cacheTime duration of the cache validity for this template, if null it defaults to the |
|
146 | + * Dwoo instance that will render this template if null it defaults to the Dwoo |
|
147 | + * instance that will render this template |
|
148 | + * @param string $cacheId the unique cache identifier of this page or anything else that makes this |
|
149 | + * template's content unique, if null it defaults to the current url makes this |
|
150 | + * template's content unique, if null it defaults to the current url |
|
151 | + * @param string $compileId the unique compiled identifier, which is used to distinguish this template from |
|
152 | + * others, if null it defaults to the filename+bits of the path template from |
|
153 | + * others, if null it defaults to the filename+bits of the path |
|
154 | + * @param ITemplate $parentTemplate the template that is requesting a new template object (through an include, |
|
155 | + * extends or any other plugin) an include, extends or any other plugin) |
|
156 | + * |
|
157 | + * @return ITemplate|false|null |
|
158 | + */ |
|
159 | + public static function templateFactory(Core $core, $resourceId, $cacheTime = null, $cacheId = null, |
|
160 | + $compileId = null, ITemplate $parentTemplate = null); |
|
161 | 161 | } |