@@ -27,47 +27,47 @@ |
||
27 | 27 | */ |
28 | 28 | class PluginForeachelse extends BlockPlugin implements ICompilableBlock |
29 | 29 | { |
30 | - public function init() |
|
31 | - { |
|
32 | - } |
|
30 | + public function init() |
|
31 | + { |
|
32 | + } |
|
33 | 33 | |
34 | - /** |
|
35 | - * @param Compiler $compiler |
|
36 | - * @param array $params |
|
37 | - * @param string $prepend |
|
38 | - * @param string $append |
|
39 | - * @param string $type |
|
40 | - * |
|
41 | - * @return string |
|
42 | - */ |
|
43 | - public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type) |
|
44 | - { |
|
45 | - $with = &$compiler->findBlock('foreach', true); |
|
34 | + /** |
|
35 | + * @param Compiler $compiler |
|
36 | + * @param array $params |
|
37 | + * @param string $prepend |
|
38 | + * @param string $append |
|
39 | + * @param string $type |
|
40 | + * |
|
41 | + * @return string |
|
42 | + */ |
|
43 | + public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type) |
|
44 | + { |
|
45 | + $with = &$compiler->findBlock('foreach', true); |
|
46 | 46 | |
47 | - $params['initialized'] = true; |
|
48 | - $compiler->injectBlock($type, $params); |
|
47 | + $params['initialized'] = true; |
|
48 | + $compiler->injectBlock($type, $params); |
|
49 | 49 | |
50 | - return ''; |
|
51 | - } |
|
50 | + return ''; |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * @param Compiler $compiler |
|
55 | - * @param array $params |
|
56 | - * @param string $prepend |
|
57 | - * @param string $append |
|
58 | - * @param string $content |
|
59 | - * |
|
60 | - * @return string |
|
61 | - */ |
|
62 | - public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content) |
|
63 | - { |
|
64 | - if (!isset($params['initialized'])) { |
|
65 | - return ''; |
|
66 | - } |
|
53 | + /** |
|
54 | + * @param Compiler $compiler |
|
55 | + * @param array $params |
|
56 | + * @param string $prepend |
|
57 | + * @param string $append |
|
58 | + * @param string $content |
|
59 | + * |
|
60 | + * @return string |
|
61 | + */ |
|
62 | + public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content) |
|
63 | + { |
|
64 | + if (!isset($params['initialized'])) { |
|
65 | + return ''; |
|
66 | + } |
|
67 | 67 | |
68 | - $block = &$compiler->getCurrentBlock(); |
|
69 | - $block['params']['hasElse'] = Compiler::PHP_OPEN . "else {\n" . Compiler::PHP_CLOSE . $content . Compiler::PHP_OPEN . "\n}" . Compiler::PHP_CLOSE; |
|
68 | + $block = &$compiler->getCurrentBlock(); |
|
69 | + $block['params']['hasElse'] = Compiler::PHP_OPEN . "else {\n" . Compiler::PHP_CLOSE . $content . Compiler::PHP_OPEN . "\n}" . Compiler::PHP_CLOSE; |
|
70 | 70 | |
71 | - return ''; |
|
72 | - } |
|
71 | + return ''; |
|
72 | + } |
|
73 | 73 | } |
@@ -66,7 +66,7 @@ |
||
66 | 66 | } |
67 | 67 | |
68 | 68 | $block = &$compiler->getCurrentBlock(); |
69 | - $block['params']['hasElse'] = Compiler::PHP_OPEN . "else {\n" . Compiler::PHP_CLOSE . $content . Compiler::PHP_OPEN . "\n}" . Compiler::PHP_CLOSE; |
|
69 | + $block['params']['hasElse'] = Compiler::PHP_OPEN."else {\n".Compiler::PHP_CLOSE.$content.Compiler::PHP_OPEN."\n}".Compiler::PHP_CLOSE; |
|
70 | 70 | |
71 | 71 | return ''; |
72 | 72 | } |
@@ -41,234 +41,234 @@ |
||
41 | 41 | */ |
42 | 42 | class PluginIf extends BlockPlugin implements ICompilableBlock, IElseable |
43 | 43 | { |
44 | - /** |
|
45 | - * @param array $rest |
|
46 | - */ |
|
47 | - public function init(array $rest) |
|
48 | - { |
|
49 | - } |
|
44 | + /** |
|
45 | + * @param array $rest |
|
46 | + */ |
|
47 | + public function init(array $rest) |
|
48 | + { |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * @param array $params |
|
53 | - * @param array $tokens |
|
54 | - * @param Compiler $compiler |
|
55 | - * |
|
56 | - * @return array |
|
57 | - * @throws CompilationException |
|
58 | - */ |
|
59 | - public static function replaceKeywords(array $params, array $tokens, Compiler $compiler) |
|
60 | - { |
|
61 | - $p = array(); |
|
51 | + /** |
|
52 | + * @param array $params |
|
53 | + * @param array $tokens |
|
54 | + * @param Compiler $compiler |
|
55 | + * |
|
56 | + * @return array |
|
57 | + * @throws CompilationException |
|
58 | + */ |
|
59 | + public static function replaceKeywords(array $params, array $tokens, Compiler $compiler) |
|
60 | + { |
|
61 | + $p = array(); |
|
62 | 62 | |
63 | - reset($params); |
|
64 | - while (list($k, $v) = each($params)) { |
|
65 | - $v = (string)$v; |
|
66 | - if (substr($v, 0, 1) === '"' || substr($v, 0, 1) === '\'') { |
|
67 | - $vmod = strtolower(substr($v, 1, - 1)); |
|
68 | - } else { |
|
69 | - $vmod = strtolower($v); |
|
70 | - } |
|
71 | - switch ($vmod) { |
|
63 | + reset($params); |
|
64 | + while (list($k, $v) = each($params)) { |
|
65 | + $v = (string)$v; |
|
66 | + if (substr($v, 0, 1) === '"' || substr($v, 0, 1) === '\'') { |
|
67 | + $vmod = strtolower(substr($v, 1, - 1)); |
|
68 | + } else { |
|
69 | + $vmod = strtolower($v); |
|
70 | + } |
|
71 | + switch ($vmod) { |
|
72 | 72 | |
73 | - case 'and': |
|
74 | - if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
75 | - $p[] = '&&'; |
|
76 | - } else { |
|
77 | - $p[] = $v; |
|
78 | - } |
|
79 | - break; |
|
80 | - case 'or': |
|
81 | - if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
82 | - $p[] = '||'; |
|
83 | - } else { |
|
84 | - $p[] = $v; |
|
85 | - } |
|
86 | - break; |
|
87 | - case 'xor': |
|
88 | - if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
89 | - $p[] = '^'; |
|
90 | - } else { |
|
91 | - $p[] = $v; |
|
92 | - } |
|
93 | - break; |
|
94 | - case 'eq': |
|
95 | - if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
96 | - $p[] = '=='; |
|
97 | - } else { |
|
98 | - $p[] = $v; |
|
99 | - } |
|
100 | - break; |
|
101 | - case 'ne': |
|
102 | - case 'neq': |
|
103 | - if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
104 | - $p[] = '!='; |
|
105 | - } else { |
|
106 | - $p[] = $v; |
|
107 | - } |
|
108 | - break; |
|
109 | - case 'gte': |
|
110 | - case 'ge': |
|
111 | - if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
112 | - $p[] = '>='; |
|
113 | - } else { |
|
114 | - $p[] = $v; |
|
115 | - } |
|
116 | - break; |
|
117 | - case 'lte': |
|
118 | - case 'le': |
|
119 | - if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
120 | - $p[] = '<='; |
|
121 | - } else { |
|
122 | - $p[] = $v; |
|
123 | - } |
|
124 | - break; |
|
125 | - case 'gt': |
|
126 | - if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
127 | - $p[] = '>'; |
|
128 | - } else { |
|
129 | - $p[] = $v; |
|
130 | - } |
|
131 | - break; |
|
132 | - case 'lt': |
|
133 | - if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
134 | - $p[] = '<'; |
|
135 | - } else { |
|
136 | - $p[] = $v; |
|
137 | - } |
|
138 | - break; |
|
139 | - case 'mod': |
|
140 | - if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
141 | - $p[] = '%'; |
|
142 | - } else { |
|
143 | - $p[] = $v; |
|
144 | - } |
|
145 | - break; |
|
146 | - case 'not': |
|
147 | - if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
148 | - $p[] = '!'; |
|
149 | - } else { |
|
150 | - $p[] = $v; |
|
151 | - } |
|
152 | - break; |
|
153 | - case '<>': |
|
154 | - $p[] = '!='; |
|
155 | - break; |
|
156 | - case '==': |
|
157 | - case '!=': |
|
158 | - case '>=': |
|
159 | - case '<=': |
|
160 | - case '>': |
|
161 | - case '<': |
|
162 | - case '===': |
|
163 | - case '!==': |
|
164 | - case '%': |
|
165 | - case '!': |
|
166 | - case '^': |
|
167 | - $p[] = $vmod; |
|
168 | - break; |
|
169 | - case 'is': |
|
170 | - if ($tokens[$k] !== Compiler::T_UNQUOTED_STRING) { |
|
171 | - $p[] = $v; |
|
172 | - break; |
|
173 | - } |
|
174 | - if (isset($params[$k + 1]) && strtolower(trim($params[$k + 1], '"\'')) === 'not' && $tokens[$k + 1] === Compiler::T_UNQUOTED_STRING) { |
|
175 | - $negate = true; |
|
176 | - next($params); |
|
177 | - } else { |
|
178 | - $negate = false; |
|
179 | - } |
|
180 | - $ptr = 1 + (int)$negate; |
|
181 | - if ($tokens[$k + $ptr] !== Compiler::T_UNQUOTED_STRING) { |
|
182 | - break; |
|
183 | - } |
|
184 | - if (!isset($params[$k + $ptr])) { |
|
185 | - $params[$k + $ptr] = ''; |
|
186 | - } else { |
|
187 | - $params[$k + $ptr] = trim($params[$k + $ptr], '"\''); |
|
188 | - } |
|
189 | - switch ($params[$k + $ptr]) { |
|
73 | + case 'and': |
|
74 | + if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
75 | + $p[] = '&&'; |
|
76 | + } else { |
|
77 | + $p[] = $v; |
|
78 | + } |
|
79 | + break; |
|
80 | + case 'or': |
|
81 | + if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
82 | + $p[] = '||'; |
|
83 | + } else { |
|
84 | + $p[] = $v; |
|
85 | + } |
|
86 | + break; |
|
87 | + case 'xor': |
|
88 | + if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
89 | + $p[] = '^'; |
|
90 | + } else { |
|
91 | + $p[] = $v; |
|
92 | + } |
|
93 | + break; |
|
94 | + case 'eq': |
|
95 | + if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
96 | + $p[] = '=='; |
|
97 | + } else { |
|
98 | + $p[] = $v; |
|
99 | + } |
|
100 | + break; |
|
101 | + case 'ne': |
|
102 | + case 'neq': |
|
103 | + if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
104 | + $p[] = '!='; |
|
105 | + } else { |
|
106 | + $p[] = $v; |
|
107 | + } |
|
108 | + break; |
|
109 | + case 'gte': |
|
110 | + case 'ge': |
|
111 | + if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
112 | + $p[] = '>='; |
|
113 | + } else { |
|
114 | + $p[] = $v; |
|
115 | + } |
|
116 | + break; |
|
117 | + case 'lte': |
|
118 | + case 'le': |
|
119 | + if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
120 | + $p[] = '<='; |
|
121 | + } else { |
|
122 | + $p[] = $v; |
|
123 | + } |
|
124 | + break; |
|
125 | + case 'gt': |
|
126 | + if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
127 | + $p[] = '>'; |
|
128 | + } else { |
|
129 | + $p[] = $v; |
|
130 | + } |
|
131 | + break; |
|
132 | + case 'lt': |
|
133 | + if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
134 | + $p[] = '<'; |
|
135 | + } else { |
|
136 | + $p[] = $v; |
|
137 | + } |
|
138 | + break; |
|
139 | + case 'mod': |
|
140 | + if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
141 | + $p[] = '%'; |
|
142 | + } else { |
|
143 | + $p[] = $v; |
|
144 | + } |
|
145 | + break; |
|
146 | + case 'not': |
|
147 | + if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
148 | + $p[] = '!'; |
|
149 | + } else { |
|
150 | + $p[] = $v; |
|
151 | + } |
|
152 | + break; |
|
153 | + case '<>': |
|
154 | + $p[] = '!='; |
|
155 | + break; |
|
156 | + case '==': |
|
157 | + case '!=': |
|
158 | + case '>=': |
|
159 | + case '<=': |
|
160 | + case '>': |
|
161 | + case '<': |
|
162 | + case '===': |
|
163 | + case '!==': |
|
164 | + case '%': |
|
165 | + case '!': |
|
166 | + case '^': |
|
167 | + $p[] = $vmod; |
|
168 | + break; |
|
169 | + case 'is': |
|
170 | + if ($tokens[$k] !== Compiler::T_UNQUOTED_STRING) { |
|
171 | + $p[] = $v; |
|
172 | + break; |
|
173 | + } |
|
174 | + if (isset($params[$k + 1]) && strtolower(trim($params[$k + 1], '"\'')) === 'not' && $tokens[$k + 1] === Compiler::T_UNQUOTED_STRING) { |
|
175 | + $negate = true; |
|
176 | + next($params); |
|
177 | + } else { |
|
178 | + $negate = false; |
|
179 | + } |
|
180 | + $ptr = 1 + (int)$negate; |
|
181 | + if ($tokens[$k + $ptr] !== Compiler::T_UNQUOTED_STRING) { |
|
182 | + break; |
|
183 | + } |
|
184 | + if (!isset($params[$k + $ptr])) { |
|
185 | + $params[$k + $ptr] = ''; |
|
186 | + } else { |
|
187 | + $params[$k + $ptr] = trim($params[$k + $ptr], '"\''); |
|
188 | + } |
|
189 | + switch ($params[$k + $ptr]) { |
|
190 | 190 | |
191 | - case 'div': |
|
192 | - if (isset($params[$k + $ptr + 1]) && strtolower(trim($params[$k + $ptr + 1], '"\'')) === 'by') { |
|
193 | - $p[] = ' % ' . $params[$k + $ptr + 2] . ' ' . ($negate ? '!' : '=') . '== 0'; |
|
194 | - next($params); |
|
195 | - next($params); |
|
196 | - next($params); |
|
197 | - } else { |
|
198 | - throw new CompilationException($compiler, 'If : Syntax error : syntax should be "if $a is [not] div by $b", found ' . $params[$k - 1] . ' is ' . ($negate ? 'not ' : '') . 'div ' . $params[$k + $ptr + 1] . ' ' . $params[$k + $ptr + 2]); |
|
199 | - } |
|
200 | - break; |
|
201 | - case 'even': |
|
202 | - $a = array_pop($p); |
|
203 | - if (isset($params[$k + $ptr + 1]) && strtolower(trim($params[$k + $ptr + 1], '"\'')) === 'by') { |
|
204 | - $b = $params[$k + $ptr + 2]; |
|
205 | - $p[] = '(' . $a . ' / ' . $b . ') % 2 ' . ($negate ? '!' : '=') . '== 0'; |
|
206 | - next($params); |
|
207 | - next($params); |
|
208 | - } else { |
|
209 | - $p[] = $a . ' % 2 ' . ($negate ? '!' : '=') . '== 0'; |
|
210 | - } |
|
211 | - next($params); |
|
212 | - break; |
|
213 | - case 'odd': |
|
214 | - $a = array_pop($p); |
|
215 | - if (isset($params[$k + $ptr + 1]) && strtolower(trim($params[$k + $ptr + 1], '"\'')) === 'by') { |
|
216 | - $b = $params[$k + $ptr + 2]; |
|
217 | - $p[] = '(' . $a . ' / ' . $b . ') % 2 ' . ($negate ? '=' : '!') . '== 0'; |
|
218 | - next($params); |
|
219 | - next($params); |
|
220 | - } else { |
|
221 | - $p[] = $a . ' % 2 ' . ($negate ? '=' : '!') . '== 0'; |
|
222 | - } |
|
223 | - next($params); |
|
224 | - break; |
|
225 | - default: |
|
226 | - throw new CompilationException($compiler, 'If : Syntax error : syntax should be "if $a is [not] (div|even|odd) [by $b]", found ' . $params[$k - 1] . ' is ' . $params[$k + $ptr + 1]); |
|
227 | - } |
|
228 | - break; |
|
229 | - default: |
|
230 | - $p[] = $v; |
|
231 | - } |
|
232 | - } |
|
191 | + case 'div': |
|
192 | + if (isset($params[$k + $ptr + 1]) && strtolower(trim($params[$k + $ptr + 1], '"\'')) === 'by') { |
|
193 | + $p[] = ' % ' . $params[$k + $ptr + 2] . ' ' . ($negate ? '!' : '=') . '== 0'; |
|
194 | + next($params); |
|
195 | + next($params); |
|
196 | + next($params); |
|
197 | + } else { |
|
198 | + throw new CompilationException($compiler, 'If : Syntax error : syntax should be "if $a is [not] div by $b", found ' . $params[$k - 1] . ' is ' . ($negate ? 'not ' : '') . 'div ' . $params[$k + $ptr + 1] . ' ' . $params[$k + $ptr + 2]); |
|
199 | + } |
|
200 | + break; |
|
201 | + case 'even': |
|
202 | + $a = array_pop($p); |
|
203 | + if (isset($params[$k + $ptr + 1]) && strtolower(trim($params[$k + $ptr + 1], '"\'')) === 'by') { |
|
204 | + $b = $params[$k + $ptr + 2]; |
|
205 | + $p[] = '(' . $a . ' / ' . $b . ') % 2 ' . ($negate ? '!' : '=') . '== 0'; |
|
206 | + next($params); |
|
207 | + next($params); |
|
208 | + } else { |
|
209 | + $p[] = $a . ' % 2 ' . ($negate ? '!' : '=') . '== 0'; |
|
210 | + } |
|
211 | + next($params); |
|
212 | + break; |
|
213 | + case 'odd': |
|
214 | + $a = array_pop($p); |
|
215 | + if (isset($params[$k + $ptr + 1]) && strtolower(trim($params[$k + $ptr + 1], '"\'')) === 'by') { |
|
216 | + $b = $params[$k + $ptr + 2]; |
|
217 | + $p[] = '(' . $a . ' / ' . $b . ') % 2 ' . ($negate ? '=' : '!') . '== 0'; |
|
218 | + next($params); |
|
219 | + next($params); |
|
220 | + } else { |
|
221 | + $p[] = $a . ' % 2 ' . ($negate ? '=' : '!') . '== 0'; |
|
222 | + } |
|
223 | + next($params); |
|
224 | + break; |
|
225 | + default: |
|
226 | + throw new CompilationException($compiler, 'If : Syntax error : syntax should be "if $a is [not] (div|even|odd) [by $b]", found ' . $params[$k - 1] . ' is ' . $params[$k + $ptr + 1]); |
|
227 | + } |
|
228 | + break; |
|
229 | + default: |
|
230 | + $p[] = $v; |
|
231 | + } |
|
232 | + } |
|
233 | 233 | |
234 | - return $p; |
|
235 | - } |
|
234 | + return $p; |
|
235 | + } |
|
236 | 236 | |
237 | - /** |
|
238 | - * @param Compiler $compiler |
|
239 | - * @param array $params |
|
240 | - * @param string $prepend |
|
241 | - * @param string $append |
|
242 | - * @param string $type |
|
243 | - * |
|
244 | - * @return string |
|
245 | - */ |
|
246 | - public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type) |
|
247 | - { |
|
248 | - return ''; |
|
249 | - } |
|
237 | + /** |
|
238 | + * @param Compiler $compiler |
|
239 | + * @param array $params |
|
240 | + * @param string $prepend |
|
241 | + * @param string $append |
|
242 | + * @param string $type |
|
243 | + * |
|
244 | + * @return string |
|
245 | + */ |
|
246 | + public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type) |
|
247 | + { |
|
248 | + return ''; |
|
249 | + } |
|
250 | 250 | |
251 | - /** |
|
252 | - * @param Compiler $compiler |
|
253 | - * @param array $params |
|
254 | - * @param string $prepend |
|
255 | - * @param string $append |
|
256 | - * @param string $content |
|
257 | - * |
|
258 | - * @return string |
|
259 | - */ |
|
260 | - public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content) |
|
261 | - { |
|
262 | - $tokens = $compiler->getParamTokens($params); |
|
263 | - $params = $compiler->getCompiledParams($params); |
|
264 | - $pre = Compiler::PHP_OPEN . 'if (' . implode(' ', self::replaceKeywords($params['*'], $tokens['*'], $compiler)) . ") {\n" . Compiler::PHP_CLOSE; |
|
251 | + /** |
|
252 | + * @param Compiler $compiler |
|
253 | + * @param array $params |
|
254 | + * @param string $prepend |
|
255 | + * @param string $append |
|
256 | + * @param string $content |
|
257 | + * |
|
258 | + * @return string |
|
259 | + */ |
|
260 | + public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content) |
|
261 | + { |
|
262 | + $tokens = $compiler->getParamTokens($params); |
|
263 | + $params = $compiler->getCompiledParams($params); |
|
264 | + $pre = Compiler::PHP_OPEN . 'if (' . implode(' ', self::replaceKeywords($params['*'], $tokens['*'], $compiler)) . ") {\n" . Compiler::PHP_CLOSE; |
|
265 | 265 | |
266 | - $post = Compiler::PHP_OPEN . "\n}" . Compiler::PHP_CLOSE; |
|
266 | + $post = Compiler::PHP_OPEN . "\n}" . Compiler::PHP_CLOSE; |
|
267 | 267 | |
268 | - if (isset($params['hasElse'])) { |
|
269 | - $post .= $params['hasElse']; |
|
270 | - } |
|
268 | + if (isset($params['hasElse'])) { |
|
269 | + $post .= $params['hasElse']; |
|
270 | + } |
|
271 | 271 | |
272 | - return $pre . $content . $post; |
|
273 | - } |
|
272 | + return $pre . $content . $post; |
|
273 | + } |
|
274 | 274 | } |
@@ -70,164 +70,164 @@ |
||
70 | 70 | } |
71 | 71 | switch ($vmod) { |
72 | 72 | |
73 | - case 'and': |
|
74 | - if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
75 | - $p[] = '&&'; |
|
76 | - } else { |
|
77 | - $p[] = $v; |
|
78 | - } |
|
79 | - break; |
|
80 | - case 'or': |
|
81 | - if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
82 | - $p[] = '||'; |
|
83 | - } else { |
|
84 | - $p[] = $v; |
|
85 | - } |
|
86 | - break; |
|
87 | - case 'xor': |
|
88 | - if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
89 | - $p[] = '^'; |
|
90 | - } else { |
|
91 | - $p[] = $v; |
|
92 | - } |
|
93 | - break; |
|
94 | - case 'eq': |
|
95 | - if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
96 | - $p[] = '=='; |
|
97 | - } else { |
|
98 | - $p[] = $v; |
|
99 | - } |
|
100 | - break; |
|
101 | - case 'ne': |
|
102 | - case 'neq': |
|
103 | - if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
104 | - $p[] = '!='; |
|
105 | - } else { |
|
106 | - $p[] = $v; |
|
107 | - } |
|
108 | - break; |
|
109 | - case 'gte': |
|
110 | - case 'ge': |
|
111 | - if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
112 | - $p[] = '>='; |
|
113 | - } else { |
|
114 | - $p[] = $v; |
|
115 | - } |
|
116 | - break; |
|
117 | - case 'lte': |
|
118 | - case 'le': |
|
119 | - if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
120 | - $p[] = '<='; |
|
121 | - } else { |
|
122 | - $p[] = $v; |
|
123 | - } |
|
124 | - break; |
|
125 | - case 'gt': |
|
126 | - if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
127 | - $p[] = '>'; |
|
128 | - } else { |
|
129 | - $p[] = $v; |
|
130 | - } |
|
131 | - break; |
|
132 | - case 'lt': |
|
133 | - if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
134 | - $p[] = '<'; |
|
135 | - } else { |
|
136 | - $p[] = $v; |
|
137 | - } |
|
138 | - break; |
|
139 | - case 'mod': |
|
140 | - if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
141 | - $p[] = '%'; |
|
142 | - } else { |
|
143 | - $p[] = $v; |
|
144 | - } |
|
145 | - break; |
|
146 | - case 'not': |
|
147 | - if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
148 | - $p[] = '!'; |
|
149 | - } else { |
|
150 | - $p[] = $v; |
|
151 | - } |
|
152 | - break; |
|
153 | - case '<>': |
|
73 | + case 'and': |
|
74 | + if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
75 | + $p[] = '&&'; |
|
76 | + } else { |
|
77 | + $p[] = $v; |
|
78 | + } |
|
79 | + break; |
|
80 | + case 'or': |
|
81 | + if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
82 | + $p[] = '||'; |
|
83 | + } else { |
|
84 | + $p[] = $v; |
|
85 | + } |
|
86 | + break; |
|
87 | + case 'xor': |
|
88 | + if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
89 | + $p[] = '^'; |
|
90 | + } else { |
|
91 | + $p[] = $v; |
|
92 | + } |
|
93 | + break; |
|
94 | + case 'eq': |
|
95 | + if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
96 | + $p[] = '=='; |
|
97 | + } else { |
|
98 | + $p[] = $v; |
|
99 | + } |
|
100 | + break; |
|
101 | + case 'ne': |
|
102 | + case 'neq': |
|
103 | + if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
154 | 104 | $p[] = '!='; |
105 | + } else { |
|
106 | + $p[] = $v; |
|
107 | + } |
|
108 | + break; |
|
109 | + case 'gte': |
|
110 | + case 'ge': |
|
111 | + if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
112 | + $p[] = '>='; |
|
113 | + } else { |
|
114 | + $p[] = $v; |
|
115 | + } |
|
116 | + break; |
|
117 | + case 'lte': |
|
118 | + case 'le': |
|
119 | + if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
120 | + $p[] = '<='; |
|
121 | + } else { |
|
122 | + $p[] = $v; |
|
123 | + } |
|
124 | + break; |
|
125 | + case 'gt': |
|
126 | + if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
127 | + $p[] = '>'; |
|
128 | + } else { |
|
129 | + $p[] = $v; |
|
130 | + } |
|
131 | + break; |
|
132 | + case 'lt': |
|
133 | + if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
134 | + $p[] = '<'; |
|
135 | + } else { |
|
136 | + $p[] = $v; |
|
137 | + } |
|
138 | + break; |
|
139 | + case 'mod': |
|
140 | + if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
141 | + $p[] = '%'; |
|
142 | + } else { |
|
143 | + $p[] = $v; |
|
144 | + } |
|
145 | + break; |
|
146 | + case 'not': |
|
147 | + if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
148 | + $p[] = '!'; |
|
149 | + } else { |
|
150 | + $p[] = $v; |
|
151 | + } |
|
152 | + break; |
|
153 | + case '<>': |
|
154 | + $p[] = '!='; |
|
155 | + break; |
|
156 | + case '==': |
|
157 | + case '!=': |
|
158 | + case '>=': |
|
159 | + case '<=': |
|
160 | + case '>': |
|
161 | + case '<': |
|
162 | + case '===': |
|
163 | + case '!==': |
|
164 | + case '%': |
|
165 | + case '!': |
|
166 | + case '^': |
|
167 | + $p[] = $vmod; |
|
168 | + break; |
|
169 | + case 'is': |
|
170 | + if ($tokens[$k] !== Compiler::T_UNQUOTED_STRING) { |
|
171 | + $p[] = $v; |
|
155 | 172 | break; |
156 | - case '==': |
|
157 | - case '!=': |
|
158 | - case '>=': |
|
159 | - case '<=': |
|
160 | - case '>': |
|
161 | - case '<': |
|
162 | - case '===': |
|
163 | - case '!==': |
|
164 | - case '%': |
|
165 | - case '!': |
|
166 | - case '^': |
|
167 | - $p[] = $vmod; |
|
173 | + } |
|
174 | + if (isset($params[$k + 1]) && strtolower(trim($params[$k + 1], '"\'')) === 'not' && $tokens[$k + 1] === Compiler::T_UNQUOTED_STRING) { |
|
175 | + $negate = true; |
|
176 | + next($params); |
|
177 | + } else { |
|
178 | + $negate = false; |
|
179 | + } |
|
180 | + $ptr = 1 + (int)$negate; |
|
181 | + if ($tokens[$k + $ptr] !== Compiler::T_UNQUOTED_STRING) { |
|
168 | 182 | break; |
169 | - case 'is': |
|
170 | - if ($tokens[$k] !== Compiler::T_UNQUOTED_STRING) { |
|
171 | - $p[] = $v; |
|
172 | - break; |
|
173 | - } |
|
174 | - if (isset($params[$k + 1]) && strtolower(trim($params[$k + 1], '"\'')) === 'not' && $tokens[$k + 1] === Compiler::T_UNQUOTED_STRING) { |
|
175 | - $negate = true; |
|
176 | - next($params); |
|
177 | - } else { |
|
178 | - $negate = false; |
|
179 | - } |
|
180 | - $ptr = 1 + (int)$negate; |
|
181 | - if ($tokens[$k + $ptr] !== Compiler::T_UNQUOTED_STRING) { |
|
182 | - break; |
|
183 | - } |
|
184 | - if (!isset($params[$k + $ptr])) { |
|
185 | - $params[$k + $ptr] = ''; |
|
186 | - } else { |
|
187 | - $params[$k + $ptr] = trim($params[$k + $ptr], '"\''); |
|
188 | - } |
|
189 | - switch ($params[$k + $ptr]) { |
|
183 | + } |
|
184 | + if (!isset($params[$k + $ptr])) { |
|
185 | + $params[$k + $ptr] = ''; |
|
186 | + } else { |
|
187 | + $params[$k + $ptr] = trim($params[$k + $ptr], '"\''); |
|
188 | + } |
|
189 | + switch ($params[$k + $ptr]) { |
|
190 | 190 | |
191 | - case 'div': |
|
192 | - if (isset($params[$k + $ptr + 1]) && strtolower(trim($params[$k + $ptr + 1], '"\'')) === 'by') { |
|
193 | - $p[] = ' % ' . $params[$k + $ptr + 2] . ' ' . ($negate ? '!' : '=') . '== 0'; |
|
194 | - next($params); |
|
195 | - next($params); |
|
196 | - next($params); |
|
197 | - } else { |
|
198 | - throw new CompilationException($compiler, 'If : Syntax error : syntax should be "if $a is [not] div by $b", found ' . $params[$k - 1] . ' is ' . ($negate ? 'not ' : '') . 'div ' . $params[$k + $ptr + 1] . ' ' . $params[$k + $ptr + 2]); |
|
199 | - } |
|
200 | - break; |
|
201 | - case 'even': |
|
202 | - $a = array_pop($p); |
|
203 | - if (isset($params[$k + $ptr + 1]) && strtolower(trim($params[$k + $ptr + 1], '"\'')) === 'by') { |
|
204 | - $b = $params[$k + $ptr + 2]; |
|
205 | - $p[] = '(' . $a . ' / ' . $b . ') % 2 ' . ($negate ? '!' : '=') . '== 0'; |
|
206 | - next($params); |
|
207 | - next($params); |
|
208 | - } else { |
|
209 | - $p[] = $a . ' % 2 ' . ($negate ? '!' : '=') . '== 0'; |
|
210 | - } |
|
211 | - next($params); |
|
212 | - break; |
|
213 | - case 'odd': |
|
214 | - $a = array_pop($p); |
|
215 | - if (isset($params[$k + $ptr + 1]) && strtolower(trim($params[$k + $ptr + 1], '"\'')) === 'by') { |
|
216 | - $b = $params[$k + $ptr + 2]; |
|
217 | - $p[] = '(' . $a . ' / ' . $b . ') % 2 ' . ($negate ? '=' : '!') . '== 0'; |
|
218 | - next($params); |
|
219 | - next($params); |
|
220 | - } else { |
|
221 | - $p[] = $a . ' % 2 ' . ($negate ? '=' : '!') . '== 0'; |
|
222 | - } |
|
223 | - next($params); |
|
224 | - break; |
|
225 | - default: |
|
226 | - throw new CompilationException($compiler, 'If : Syntax error : syntax should be "if $a is [not] (div|even|odd) [by $b]", found ' . $params[$k - 1] . ' is ' . $params[$k + $ptr + 1]); |
|
227 | - } |
|
228 | - break; |
|
191 | + case 'div': |
|
192 | + if (isset($params[$k + $ptr + 1]) && strtolower(trim($params[$k + $ptr + 1], '"\'')) === 'by') { |
|
193 | + $p[] = ' % ' . $params[$k + $ptr + 2] . ' ' . ($negate ? '!' : '=') . '== 0'; |
|
194 | + next($params); |
|
195 | + next($params); |
|
196 | + next($params); |
|
197 | + } else { |
|
198 | + throw new CompilationException($compiler, 'If : Syntax error : syntax should be "if $a is [not] div by $b", found ' . $params[$k - 1] . ' is ' . ($negate ? 'not ' : '') . 'div ' . $params[$k + $ptr + 1] . ' ' . $params[$k + $ptr + 2]); |
|
199 | + } |
|
200 | + break; |
|
201 | + case 'even': |
|
202 | + $a = array_pop($p); |
|
203 | + if (isset($params[$k + $ptr + 1]) && strtolower(trim($params[$k + $ptr + 1], '"\'')) === 'by') { |
|
204 | + $b = $params[$k + $ptr + 2]; |
|
205 | + $p[] = '(' . $a . ' / ' . $b . ') % 2 ' . ($negate ? '!' : '=') . '== 0'; |
|
206 | + next($params); |
|
207 | + next($params); |
|
208 | + } else { |
|
209 | + $p[] = $a . ' % 2 ' . ($negate ? '!' : '=') . '== 0'; |
|
210 | + } |
|
211 | + next($params); |
|
212 | + break; |
|
213 | + case 'odd': |
|
214 | + $a = array_pop($p); |
|
215 | + if (isset($params[$k + $ptr + 1]) && strtolower(trim($params[$k + $ptr + 1], '"\'')) === 'by') { |
|
216 | + $b = $params[$k + $ptr + 2]; |
|
217 | + $p[] = '(' . $a . ' / ' . $b . ') % 2 ' . ($negate ? '=' : '!') . '== 0'; |
|
218 | + next($params); |
|
219 | + next($params); |
|
220 | + } else { |
|
221 | + $p[] = $a . ' % 2 ' . ($negate ? '=' : '!') . '== 0'; |
|
222 | + } |
|
223 | + next($params); |
|
224 | + break; |
|
229 | 225 | default: |
230 | - $p[] = $v; |
|
226 | + throw new CompilationException($compiler, 'If : Syntax error : syntax should be "if $a is [not] (div|even|odd) [by $b]", found ' . $params[$k - 1] . ' is ' . $params[$k + $ptr + 1]); |
|
227 | + } |
|
228 | + break; |
|
229 | + default: |
|
230 | + $p[] = $v; |
|
231 | 231 | } |
232 | 232 | } |
233 | 233 |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | |
63 | 63 | reset($params); |
64 | 64 | while (list($k, $v) = each($params)) { |
65 | - $v = (string)$v; |
|
65 | + $v = (string) $v; |
|
66 | 66 | if (substr($v, 0, 1) === '"' || substr($v, 0, 1) === '\'') { |
67 | 67 | $vmod = strtolower(substr($v, 1, - 1)); |
68 | 68 | } else { |
@@ -171,59 +171,59 @@ discard block |
||
171 | 171 | $p[] = $v; |
172 | 172 | break; |
173 | 173 | } |
174 | - if (isset($params[$k + 1]) && strtolower(trim($params[$k + 1], '"\'')) === 'not' && $tokens[$k + 1] === Compiler::T_UNQUOTED_STRING) { |
|
174 | + if (isset($params[$k+1]) && strtolower(trim($params[$k+1], '"\'')) === 'not' && $tokens[$k+1] === Compiler::T_UNQUOTED_STRING) { |
|
175 | 175 | $negate = true; |
176 | 176 | next($params); |
177 | 177 | } else { |
178 | 178 | $negate = false; |
179 | 179 | } |
180 | - $ptr = 1 + (int)$negate; |
|
181 | - if ($tokens[$k + $ptr] !== Compiler::T_UNQUOTED_STRING) { |
|
180 | + $ptr = 1+(int) $negate; |
|
181 | + if ($tokens[$k+$ptr] !== Compiler::T_UNQUOTED_STRING) { |
|
182 | 182 | break; |
183 | 183 | } |
184 | - if (!isset($params[$k + $ptr])) { |
|
185 | - $params[$k + $ptr] = ''; |
|
184 | + if (!isset($params[$k+$ptr])) { |
|
185 | + $params[$k+$ptr] = ''; |
|
186 | 186 | } else { |
187 | - $params[$k + $ptr] = trim($params[$k + $ptr], '"\''); |
|
187 | + $params[$k+$ptr] = trim($params[$k+$ptr], '"\''); |
|
188 | 188 | } |
189 | - switch ($params[$k + $ptr]) { |
|
189 | + switch ($params[$k+$ptr]) { |
|
190 | 190 | |
191 | 191 | case 'div': |
192 | - if (isset($params[$k + $ptr + 1]) && strtolower(trim($params[$k + $ptr + 1], '"\'')) === 'by') { |
|
193 | - $p[] = ' % ' . $params[$k + $ptr + 2] . ' ' . ($negate ? '!' : '=') . '== 0'; |
|
192 | + if (isset($params[$k+$ptr+1]) && strtolower(trim($params[$k+$ptr+1], '"\'')) === 'by') { |
|
193 | + $p[] = ' % '.$params[$k+$ptr+2].' '.($negate ? '!' : '=').'== 0'; |
|
194 | 194 | next($params); |
195 | 195 | next($params); |
196 | 196 | next($params); |
197 | 197 | } else { |
198 | - throw new CompilationException($compiler, 'If : Syntax error : syntax should be "if $a is [not] div by $b", found ' . $params[$k - 1] . ' is ' . ($negate ? 'not ' : '') . 'div ' . $params[$k + $ptr + 1] . ' ' . $params[$k + $ptr + 2]); |
|
198 | + throw new CompilationException($compiler, 'If : Syntax error : syntax should be "if $a is [not] div by $b", found '.$params[$k-1].' is '.($negate ? 'not ' : '').'div '.$params[$k+$ptr+1].' '.$params[$k+$ptr+2]); |
|
199 | 199 | } |
200 | 200 | break; |
201 | 201 | case 'even': |
202 | 202 | $a = array_pop($p); |
203 | - if (isset($params[$k + $ptr + 1]) && strtolower(trim($params[$k + $ptr + 1], '"\'')) === 'by') { |
|
204 | - $b = $params[$k + $ptr + 2]; |
|
205 | - $p[] = '(' . $a . ' / ' . $b . ') % 2 ' . ($negate ? '!' : '=') . '== 0'; |
|
203 | + if (isset($params[$k+$ptr+1]) && strtolower(trim($params[$k+$ptr+1], '"\'')) === 'by') { |
|
204 | + $b = $params[$k+$ptr+2]; |
|
205 | + $p[] = '('.$a.' / '.$b.') % 2 '.($negate ? '!' : '=').'== 0'; |
|
206 | 206 | next($params); |
207 | 207 | next($params); |
208 | 208 | } else { |
209 | - $p[] = $a . ' % 2 ' . ($negate ? '!' : '=') . '== 0'; |
|
209 | + $p[] = $a.' % 2 '.($negate ? '!' : '=').'== 0'; |
|
210 | 210 | } |
211 | 211 | next($params); |
212 | 212 | break; |
213 | 213 | case 'odd': |
214 | 214 | $a = array_pop($p); |
215 | - if (isset($params[$k + $ptr + 1]) && strtolower(trim($params[$k + $ptr + 1], '"\'')) === 'by') { |
|
216 | - $b = $params[$k + $ptr + 2]; |
|
217 | - $p[] = '(' . $a . ' / ' . $b . ') % 2 ' . ($negate ? '=' : '!') . '== 0'; |
|
215 | + if (isset($params[$k+$ptr+1]) && strtolower(trim($params[$k+$ptr+1], '"\'')) === 'by') { |
|
216 | + $b = $params[$k+$ptr+2]; |
|
217 | + $p[] = '('.$a.' / '.$b.') % 2 '.($negate ? '=' : '!').'== 0'; |
|
218 | 218 | next($params); |
219 | 219 | next($params); |
220 | 220 | } else { |
221 | - $p[] = $a . ' % 2 ' . ($negate ? '=' : '!') . '== 0'; |
|
221 | + $p[] = $a.' % 2 '.($negate ? '=' : '!').'== 0'; |
|
222 | 222 | } |
223 | 223 | next($params); |
224 | 224 | break; |
225 | 225 | default: |
226 | - throw new CompilationException($compiler, 'If : Syntax error : syntax should be "if $a is [not] (div|even|odd) [by $b]", found ' . $params[$k - 1] . ' is ' . $params[$k + $ptr + 1]); |
|
226 | + throw new CompilationException($compiler, 'If : Syntax error : syntax should be "if $a is [not] (div|even|odd) [by $b]", found '.$params[$k-1].' is '.$params[$k+$ptr+1]); |
|
227 | 227 | } |
228 | 228 | break; |
229 | 229 | default: |
@@ -261,14 +261,14 @@ discard block |
||
261 | 261 | { |
262 | 262 | $tokens = $compiler->getParamTokens($params); |
263 | 263 | $params = $compiler->getCompiledParams($params); |
264 | - $pre = Compiler::PHP_OPEN . 'if (' . implode(' ', self::replaceKeywords($params['*'], $tokens['*'], $compiler)) . ") {\n" . Compiler::PHP_CLOSE; |
|
264 | + $pre = Compiler::PHP_OPEN.'if ('.implode(' ', self::replaceKeywords($params['*'], $tokens['*'], $compiler)).") {\n".Compiler::PHP_CLOSE; |
|
265 | 265 | |
266 | - $post = Compiler::PHP_OPEN . "\n}" . Compiler::PHP_CLOSE; |
|
266 | + $post = Compiler::PHP_OPEN."\n}".Compiler::PHP_CLOSE; |
|
267 | 267 | |
268 | 268 | if (isset($params['hasElse'])) { |
269 | 269 | $post .= $params['hasElse']; |
270 | 270 | } |
271 | 271 | |
272 | - return $pre . $content . $post; |
|
272 | + return $pre.$content.$post; |
|
273 | 273 | } |
274 | 274 | } |
@@ -29,38 +29,38 @@ |
||
29 | 29 | */ |
30 | 30 | class PluginBlock extends BlockPlugin implements ICompilableBlock |
31 | 31 | { |
32 | - /** |
|
33 | - * @param string $name |
|
34 | - */ |
|
35 | - public function init($name = '') |
|
36 | - { |
|
37 | - } |
|
32 | + /** |
|
33 | + * @param string $name |
|
34 | + */ |
|
35 | + public function init($name = '') |
|
36 | + { |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * @param Compiler $compiler |
|
41 | - * @param array $params |
|
42 | - * @param string $prepend |
|
43 | - * @param string $append |
|
44 | - * @param string $type |
|
45 | - * |
|
46 | - * @return string |
|
47 | - */ |
|
48 | - public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type) |
|
49 | - { |
|
50 | - return ''; |
|
51 | - } |
|
39 | + /** |
|
40 | + * @param Compiler $compiler |
|
41 | + * @param array $params |
|
42 | + * @param string $prepend |
|
43 | + * @param string $append |
|
44 | + * @param string $type |
|
45 | + * |
|
46 | + * @return string |
|
47 | + */ |
|
48 | + public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type) |
|
49 | + { |
|
50 | + return ''; |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * @param Compiler $compiler |
|
55 | - * @param array $params |
|
56 | - * @param string $prepend |
|
57 | - * @param string $append |
|
58 | - * @param string $content |
|
59 | - * |
|
60 | - * @return string |
|
61 | - */ |
|
62 | - public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content) |
|
63 | - { |
|
64 | - return $content; |
|
65 | - } |
|
53 | + /** |
|
54 | + * @param Compiler $compiler |
|
55 | + * @param array $params |
|
56 | + * @param string $prepend |
|
57 | + * @param string $append |
|
58 | + * @param string $content |
|
59 | + * |
|
60 | + * @return string |
|
61 | + */ |
|
62 | + public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content) |
|
63 | + { |
|
64 | + return $content; |
|
65 | + } |
|
66 | 66 | } |
@@ -28,69 +28,69 @@ |
||
28 | 28 | */ |
29 | 29 | class PluginSmartyinterface extends BlockPlugin implements ICompilableBlock |
30 | 30 | { |
31 | - /** |
|
32 | - * @param $__funcname |
|
33 | - * @param $__functype |
|
34 | - * @param array $rest |
|
35 | - */ |
|
36 | - public function init($__funcname, $__functype, array $rest = array()) |
|
37 | - { |
|
38 | - } |
|
31 | + /** |
|
32 | + * @param $__funcname |
|
33 | + * @param $__functype |
|
34 | + * @param array $rest |
|
35 | + */ |
|
36 | + public function init($__funcname, $__functype, array $rest = array()) |
|
37 | + { |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * @param Compiler $compiler |
|
42 | - * @param array $params |
|
43 | - * @param string $prepend |
|
44 | - * @param string $append |
|
45 | - * @param string $type |
|
46 | - * |
|
47 | - * @return string |
|
48 | - */ |
|
49 | - public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type) |
|
50 | - { |
|
51 | - $params = $compiler->getCompiledParams($params); |
|
52 | - $func = $params['__funcname']; |
|
53 | - $pluginType = $params['__functype']; |
|
54 | - $params = $params['*']; |
|
40 | + /** |
|
41 | + * @param Compiler $compiler |
|
42 | + * @param array $params |
|
43 | + * @param string $prepend |
|
44 | + * @param string $append |
|
45 | + * @param string $type |
|
46 | + * |
|
47 | + * @return string |
|
48 | + */ |
|
49 | + public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type) |
|
50 | + { |
|
51 | + $params = $compiler->getCompiledParams($params); |
|
52 | + $func = $params['__funcname']; |
|
53 | + $pluginType = $params['__functype']; |
|
54 | + $params = $params['*']; |
|
55 | 55 | |
56 | - if ($pluginType & Core::CUSTOM_PLUGIN) { |
|
57 | - $customPlugins = $compiler->getDwoo()->getCustomPlugins(); |
|
58 | - $callback = $customPlugins[$func]['callback']; |
|
59 | - if (is_array($callback)) { |
|
60 | - if (is_object($callback[0])) { |
|
61 | - $callback = '$this->customPlugins[\'' . $func . '\'][0]->' . $callback[1] . '('; |
|
62 | - } else { |
|
63 | - $callback = '' . $callback[0] . '::' . $callback[1] . '('; |
|
64 | - } |
|
65 | - } else { |
|
66 | - $callback = $callback . '('; |
|
67 | - } |
|
68 | - } else { |
|
69 | - $callback = 'smarty_block_' . $func . '('; |
|
70 | - } |
|
56 | + if ($pluginType & Core::CUSTOM_PLUGIN) { |
|
57 | + $customPlugins = $compiler->getDwoo()->getCustomPlugins(); |
|
58 | + $callback = $customPlugins[$func]['callback']; |
|
59 | + if (is_array($callback)) { |
|
60 | + if (is_object($callback[0])) { |
|
61 | + $callback = '$this->customPlugins[\'' . $func . '\'][0]->' . $callback[1] . '('; |
|
62 | + } else { |
|
63 | + $callback = '' . $callback[0] . '::' . $callback[1] . '('; |
|
64 | + } |
|
65 | + } else { |
|
66 | + $callback = $callback . '('; |
|
67 | + } |
|
68 | + } else { |
|
69 | + $callback = 'smarty_block_' . $func . '('; |
|
70 | + } |
|
71 | 71 | |
72 | - $paramsOut = ''; |
|
73 | - foreach ($params as $i => $p) { |
|
74 | - $paramsOut .= var_export($i, true) . ' => ' . $p . ','; |
|
75 | - } |
|
72 | + $paramsOut = ''; |
|
73 | + foreach ($params as $i => $p) { |
|
74 | + $paramsOut .= var_export($i, true) . ' => ' . $p . ','; |
|
75 | + } |
|
76 | 76 | |
77 | - $curBlock = &$compiler->getCurrentBlock(); |
|
78 | - $curBlock['params']['postOut'] = Compiler::PHP_OPEN . ' $_block_content = ob_get_clean(); $_block_repeat=false; echo ' . $callback . '$_tag_stack[count($_tag_stack)-1], $_block_content, $this, $_block_repeat); } array_pop($_tag_stack);' . Compiler::PHP_CLOSE; |
|
77 | + $curBlock = &$compiler->getCurrentBlock(); |
|
78 | + $curBlock['params']['postOut'] = Compiler::PHP_OPEN . ' $_block_content = ob_get_clean(); $_block_repeat=false; echo ' . $callback . '$_tag_stack[count($_tag_stack)-1], $_block_content, $this, $_block_repeat); } array_pop($_tag_stack);' . Compiler::PHP_CLOSE; |
|
79 | 79 | |
80 | - return Compiler::PHP_OPEN . $prepend . ' if (!isset($_tag_stack)){ $_tag_stack = array(); } $_tag_stack[] = array(' . $paramsOut . '); $_block_repeat=true; ' . $callback . '$_tag_stack[count($_tag_stack)-1], null, $this, $_block_repeat); while ($_block_repeat) { ob_start();' . Compiler::PHP_CLOSE; |
|
81 | - } |
|
80 | + return Compiler::PHP_OPEN . $prepend . ' if (!isset($_tag_stack)){ $_tag_stack = array(); } $_tag_stack[] = array(' . $paramsOut . '); $_block_repeat=true; ' . $callback . '$_tag_stack[count($_tag_stack)-1], null, $this, $_block_repeat); while ($_block_repeat) { ob_start();' . Compiler::PHP_CLOSE; |
|
81 | + } |
|
82 | 82 | |
83 | - /** |
|
84 | - * @param Compiler $compiler |
|
85 | - * @param array $params |
|
86 | - * @param string $prepend |
|
87 | - * @param string $append |
|
88 | - * @param string $content |
|
89 | - * |
|
90 | - * @return string |
|
91 | - */ |
|
92 | - public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content) |
|
93 | - { |
|
94 | - return $content . $params['postOut']; |
|
95 | - } |
|
83 | + /** |
|
84 | + * @param Compiler $compiler |
|
85 | + * @param array $params |
|
86 | + * @param string $prepend |
|
87 | + * @param string $append |
|
88 | + * @param string $content |
|
89 | + * |
|
90 | + * @return string |
|
91 | + */ |
|
92 | + public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content) |
|
93 | + { |
|
94 | + return $content . $params['postOut']; |
|
95 | + } |
|
96 | 96 | } |
@@ -58,26 +58,26 @@ discard block |
||
58 | 58 | $callback = $customPlugins[$func]['callback']; |
59 | 59 | if (is_array($callback)) { |
60 | 60 | if (is_object($callback[0])) { |
61 | - $callback = '$this->customPlugins[\'' . $func . '\'][0]->' . $callback[1] . '('; |
|
61 | + $callback = '$this->customPlugins[\''.$func.'\'][0]->'.$callback[1].'('; |
|
62 | 62 | } else { |
63 | - $callback = '' . $callback[0] . '::' . $callback[1] . '('; |
|
63 | + $callback = ''.$callback[0].'::'.$callback[1].'('; |
|
64 | 64 | } |
65 | 65 | } else { |
66 | - $callback = $callback . '('; |
|
66 | + $callback = $callback.'('; |
|
67 | 67 | } |
68 | 68 | } else { |
69 | - $callback = 'smarty_block_' . $func . '('; |
|
69 | + $callback = 'smarty_block_'.$func.'('; |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | $paramsOut = ''; |
73 | 73 | foreach ($params as $i => $p) { |
74 | - $paramsOut .= var_export($i, true) . ' => ' . $p . ','; |
|
74 | + $paramsOut .= var_export($i, true).' => '.$p.','; |
|
75 | 75 | } |
76 | 76 | |
77 | 77 | $curBlock = &$compiler->getCurrentBlock(); |
78 | - $curBlock['params']['postOut'] = Compiler::PHP_OPEN . ' $_block_content = ob_get_clean(); $_block_repeat=false; echo ' . $callback . '$_tag_stack[count($_tag_stack)-1], $_block_content, $this, $_block_repeat); } array_pop($_tag_stack);' . Compiler::PHP_CLOSE; |
|
78 | + $curBlock['params']['postOut'] = Compiler::PHP_OPEN.' $_block_content = ob_get_clean(); $_block_repeat=false; echo '.$callback.'$_tag_stack[count($_tag_stack)-1], $_block_content, $this, $_block_repeat); } array_pop($_tag_stack);'.Compiler::PHP_CLOSE; |
|
79 | 79 | |
80 | - return Compiler::PHP_OPEN . $prepend . ' if (!isset($_tag_stack)){ $_tag_stack = array(); } $_tag_stack[] = array(' . $paramsOut . '); $_block_repeat=true; ' . $callback . '$_tag_stack[count($_tag_stack)-1], null, $this, $_block_repeat); while ($_block_repeat) { ob_start();' . Compiler::PHP_CLOSE; |
|
80 | + return Compiler::PHP_OPEN.$prepend.' if (!isset($_tag_stack)){ $_tag_stack = array(); } $_tag_stack[] = array('.$paramsOut.'); $_block_repeat=true; '.$callback.'$_tag_stack[count($_tag_stack)-1], null, $this, $_block_repeat); while ($_block_repeat) { ob_start();'.Compiler::PHP_CLOSE; |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | /** |
@@ -91,6 +91,6 @@ discard block |
||
91 | 91 | */ |
92 | 92 | public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content) |
93 | 93 | { |
94 | - return $content . $params['postOut']; |
|
94 | + return $content.$params['postOut']; |
|
95 | 95 | } |
96 | 96 | } |
@@ -27,47 +27,47 @@ |
||
27 | 27 | */ |
28 | 28 | class PluginWithelse extends BlockPlugin implements ICompilableBlock |
29 | 29 | { |
30 | - public function init() |
|
31 | - { |
|
32 | - } |
|
30 | + public function init() |
|
31 | + { |
|
32 | + } |
|
33 | 33 | |
34 | - /** |
|
35 | - * @param Compiler $compiler |
|
36 | - * @param array $params |
|
37 | - * @param string $prepend |
|
38 | - * @param string $append |
|
39 | - * @param string $type |
|
40 | - * |
|
41 | - * @return string |
|
42 | - */ |
|
43 | - public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type) |
|
44 | - { |
|
45 | - $with = &$compiler->findBlock('with', true); |
|
34 | + /** |
|
35 | + * @param Compiler $compiler |
|
36 | + * @param array $params |
|
37 | + * @param string $prepend |
|
38 | + * @param string $append |
|
39 | + * @param string $type |
|
40 | + * |
|
41 | + * @return string |
|
42 | + */ |
|
43 | + public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type) |
|
44 | + { |
|
45 | + $with = &$compiler->findBlock('with', true); |
|
46 | 46 | |
47 | - $params['initialized'] = true; |
|
48 | - $compiler->injectBlock($type, $params); |
|
47 | + $params['initialized'] = true; |
|
48 | + $compiler->injectBlock($type, $params); |
|
49 | 49 | |
50 | - return ''; |
|
51 | - } |
|
50 | + return ''; |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * @param Compiler $compiler |
|
55 | - * @param array $params |
|
56 | - * @param string $prepend |
|
57 | - * @param string $append |
|
58 | - * @param string $content |
|
59 | - * |
|
60 | - * @return string |
|
61 | - */ |
|
62 | - public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content) |
|
63 | - { |
|
64 | - if (!isset($params['initialized'])) { |
|
65 | - return ''; |
|
66 | - } |
|
53 | + /** |
|
54 | + * @param Compiler $compiler |
|
55 | + * @param array $params |
|
56 | + * @param string $prepend |
|
57 | + * @param string $append |
|
58 | + * @param string $content |
|
59 | + * |
|
60 | + * @return string |
|
61 | + */ |
|
62 | + public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content) |
|
63 | + { |
|
64 | + if (!isset($params['initialized'])) { |
|
65 | + return ''; |
|
66 | + } |
|
67 | 67 | |
68 | - $block = &$compiler->getCurrentBlock(); |
|
69 | - $block['params']['hasElse'] = Compiler::PHP_OPEN . "else {\n" . Compiler::PHP_CLOSE . $content . Compiler::PHP_OPEN . "\n}" . Compiler::PHP_CLOSE; |
|
68 | + $block = &$compiler->getCurrentBlock(); |
|
69 | + $block['params']['hasElse'] = Compiler::PHP_OPEN . "else {\n" . Compiler::PHP_CLOSE . $content . Compiler::PHP_OPEN . "\n}" . Compiler::PHP_CLOSE; |
|
70 | 70 | |
71 | - return ''; |
|
72 | - } |
|
71 | + return ''; |
|
72 | + } |
|
73 | 73 | } |
@@ -66,7 +66,7 @@ |
||
66 | 66 | } |
67 | 67 | |
68 | 68 | $block = &$compiler->getCurrentBlock(); |
69 | - $block['params']['hasElse'] = Compiler::PHP_OPEN . "else {\n" . Compiler::PHP_CLOSE . $content . Compiler::PHP_OPEN . "\n}" . Compiler::PHP_CLOSE; |
|
69 | + $block['params']['hasElse'] = Compiler::PHP_OPEN."else {\n".Compiler::PHP_CLOSE.$content.Compiler::PHP_OPEN."\n}".Compiler::PHP_CLOSE; |
|
70 | 70 | |
71 | 71 | return ''; |
72 | 72 | } |
@@ -36,84 +36,84 @@ |
||
36 | 36 | */ |
37 | 37 | class PluginTextformat extends BlockPlugin |
38 | 38 | { |
39 | - protected $wrap; |
|
40 | - protected $wrapChar; |
|
41 | - protected $wrapCut; |
|
42 | - protected $indent; |
|
43 | - protected $indChar; |
|
44 | - protected $indFirst; |
|
45 | - protected $assign; |
|
39 | + protected $wrap; |
|
40 | + protected $wrapChar; |
|
41 | + protected $wrapCut; |
|
42 | + protected $indent; |
|
43 | + protected $indChar; |
|
44 | + protected $indFirst; |
|
45 | + protected $assign; |
|
46 | 46 | |
47 | - /** |
|
48 | - * @param int $wrap |
|
49 | - * @param string $wrap_char |
|
50 | - * @param bool $wrap_cut |
|
51 | - * @param int $indent |
|
52 | - * @param string $indent_char |
|
53 | - * @param int $indent_first |
|
54 | - * @param string $style |
|
55 | - * @param string $assign |
|
56 | - */ |
|
57 | - public function init($wrap = 80, $wrap_char = "\r\n", $wrap_cut = false, $indent = 0, $indent_char = ' ', $indent_first = 0, $style = '', $assign = '') |
|
58 | - { |
|
59 | - if ($indent_char === 'tab') { |
|
60 | - $indent_char = "\t"; |
|
61 | - } |
|
47 | + /** |
|
48 | + * @param int $wrap |
|
49 | + * @param string $wrap_char |
|
50 | + * @param bool $wrap_cut |
|
51 | + * @param int $indent |
|
52 | + * @param string $indent_char |
|
53 | + * @param int $indent_first |
|
54 | + * @param string $style |
|
55 | + * @param string $assign |
|
56 | + */ |
|
57 | + public function init($wrap = 80, $wrap_char = "\r\n", $wrap_cut = false, $indent = 0, $indent_char = ' ', $indent_first = 0, $style = '', $assign = '') |
|
58 | + { |
|
59 | + if ($indent_char === 'tab') { |
|
60 | + $indent_char = "\t"; |
|
61 | + } |
|
62 | 62 | |
63 | - switch ($style) { |
|
63 | + switch ($style) { |
|
64 | 64 | |
65 | - case 'email': |
|
66 | - $wrap = 72; |
|
67 | - $indent_first = 0; |
|
68 | - break; |
|
69 | - case 'html': |
|
70 | - $wrap_char = '<br />'; |
|
71 | - $indent_char = $indent_char == "\t" ? ' ' : ' '; |
|
72 | - break; |
|
73 | - } |
|
65 | + case 'email': |
|
66 | + $wrap = 72; |
|
67 | + $indent_first = 0; |
|
68 | + break; |
|
69 | + case 'html': |
|
70 | + $wrap_char = '<br />'; |
|
71 | + $indent_char = $indent_char == "\t" ? ' ' : ' '; |
|
72 | + break; |
|
73 | + } |
|
74 | 74 | |
75 | - $this->wrap = (int)$wrap; |
|
76 | - $this->wrapChar = (string)$wrap_char; |
|
77 | - $this->wrapCut = (bool)$wrap_cut; |
|
78 | - $this->indent = (int)$indent; |
|
79 | - $this->indChar = (string)$indent_char; |
|
80 | - $this->indFirst = (int)$indent_first + $this->indent; |
|
81 | - $this->assign = (string)$assign; |
|
82 | - } |
|
75 | + $this->wrap = (int)$wrap; |
|
76 | + $this->wrapChar = (string)$wrap_char; |
|
77 | + $this->wrapCut = (bool)$wrap_cut; |
|
78 | + $this->indent = (int)$indent; |
|
79 | + $this->indChar = (string)$indent_char; |
|
80 | + $this->indFirst = (int)$indent_first + $this->indent; |
|
81 | + $this->assign = (string)$assign; |
|
82 | + } |
|
83 | 83 | |
84 | - /** |
|
85 | - * @return string |
|
86 | - */ |
|
87 | - public function process() |
|
88 | - { |
|
89 | - // gets paragraphs |
|
90 | - $pgs = explode("\n", str_replace(array( |
|
91 | - "\r\n", |
|
92 | - "\r" |
|
93 | - ), "\n", $this->buffer)); |
|
84 | + /** |
|
85 | + * @return string |
|
86 | + */ |
|
87 | + public function process() |
|
88 | + { |
|
89 | + // gets paragraphs |
|
90 | + $pgs = explode("\n", str_replace(array( |
|
91 | + "\r\n", |
|
92 | + "\r" |
|
93 | + ), "\n", $this->buffer)); |
|
94 | 94 | |
95 | - while (list($i) = each($pgs)) { |
|
96 | - if (empty($pgs[$i])) { |
|
97 | - continue; |
|
98 | - } |
|
95 | + while (list($i) = each($pgs)) { |
|
96 | + if (empty($pgs[$i])) { |
|
97 | + continue; |
|
98 | + } |
|
99 | 99 | |
100 | - // removes line breaks and extensive white space |
|
101 | - $pgs[$i] = preg_replace(array( |
|
102 | - '#\s+#', |
|
103 | - '#^\s*(.+?)\s*$#m' |
|
104 | - ), array( |
|
105 | - ' ', |
|
106 | - '$1' |
|
107 | - ), str_replace("\n", '', $pgs[$i])); |
|
100 | + // removes line breaks and extensive white space |
|
101 | + $pgs[$i] = preg_replace(array( |
|
102 | + '#\s+#', |
|
103 | + '#^\s*(.+?)\s*$#m' |
|
104 | + ), array( |
|
105 | + ' ', |
|
106 | + '$1' |
|
107 | + ), str_replace("\n", '', $pgs[$i])); |
|
108 | 108 | |
109 | - // wordwraps + indents lines |
|
110 | - $pgs[$i] = str_repeat($this->indChar, $this->indFirst) . wordwrap($pgs[$i], max($this->wrap - $this->indent, 1), $this->wrapChar . str_repeat($this->indChar, $this->indent), $this->wrapCut); |
|
111 | - } |
|
109 | + // wordwraps + indents lines |
|
110 | + $pgs[$i] = str_repeat($this->indChar, $this->indFirst) . wordwrap($pgs[$i], max($this->wrap - $this->indent, 1), $this->wrapChar . str_repeat($this->indChar, $this->indent), $this->wrapCut); |
|
111 | + } |
|
112 | 112 | |
113 | - if ($this->assign !== '') { |
|
114 | - $this->core->assignInScope(implode($this->wrapChar . $this->wrapChar, $pgs), $this->assign); |
|
115 | - } else { |
|
116 | - return implode($this->wrapChar . $this->wrapChar, $pgs); |
|
117 | - } |
|
118 | - } |
|
113 | + if ($this->assign !== '') { |
|
114 | + $this->core->assignInScope(implode($this->wrapChar . $this->wrapChar, $pgs), $this->assign); |
|
115 | + } else { |
|
116 | + return implode($this->wrapChar . $this->wrapChar, $pgs); |
|
117 | + } |
|
118 | + } |
|
119 | 119 | } |
@@ -62,14 +62,14 @@ |
||
62 | 62 | |
63 | 63 | switch ($style) { |
64 | 64 | |
65 | - case 'email': |
|
66 | - $wrap = 72; |
|
67 | - $indent_first = 0; |
|
68 | - break; |
|
69 | - case 'html': |
|
70 | - $wrap_char = '<br />'; |
|
71 | - $indent_char = $indent_char == "\t" ? ' ' : ' '; |
|
72 | - break; |
|
65 | + case 'email': |
|
66 | + $wrap = 72; |
|
67 | + $indent_first = 0; |
|
68 | + break; |
|
69 | + case 'html': |
|
70 | + $wrap_char = '<br />'; |
|
71 | + $indent_char = $indent_char == "\t" ? ' ' : ' '; |
|
72 | + break; |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | $this->wrap = (int)$wrap; |
@@ -72,13 +72,13 @@ discard block |
||
72 | 72 | break; |
73 | 73 | } |
74 | 74 | |
75 | - $this->wrap = (int)$wrap; |
|
76 | - $this->wrapChar = (string)$wrap_char; |
|
77 | - $this->wrapCut = (bool)$wrap_cut; |
|
78 | - $this->indent = (int)$indent; |
|
79 | - $this->indChar = (string)$indent_char; |
|
80 | - $this->indFirst = (int)$indent_first + $this->indent; |
|
81 | - $this->assign = (string)$assign; |
|
75 | + $this->wrap = (int) $wrap; |
|
76 | + $this->wrapChar = (string) $wrap_char; |
|
77 | + $this->wrapCut = (bool) $wrap_cut; |
|
78 | + $this->indent = (int) $indent; |
|
79 | + $this->indChar = (string) $indent_char; |
|
80 | + $this->indFirst = (int) $indent_first+$this->indent; |
|
81 | + $this->assign = (string) $assign; |
|
82 | 82 | } |
83 | 83 | |
84 | 84 | /** |
@@ -107,13 +107,13 @@ discard block |
||
107 | 107 | ), str_replace("\n", '', $pgs[$i])); |
108 | 108 | |
109 | 109 | // wordwraps + indents lines |
110 | - $pgs[$i] = str_repeat($this->indChar, $this->indFirst) . wordwrap($pgs[$i], max($this->wrap - $this->indent, 1), $this->wrapChar . str_repeat($this->indChar, $this->indent), $this->wrapCut); |
|
110 | + $pgs[$i] = str_repeat($this->indChar, $this->indFirst).wordwrap($pgs[$i], max($this->wrap-$this->indent, 1), $this->wrapChar.str_repeat($this->indChar, $this->indent), $this->wrapCut); |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | if ($this->assign !== '') { |
114 | - $this->core->assignInScope(implode($this->wrapChar . $this->wrapChar, $pgs), $this->assign); |
|
114 | + $this->core->assignInScope(implode($this->wrapChar.$this->wrapChar, $pgs), $this->assign); |
|
115 | 115 | } else { |
116 | - return implode($this->wrapChar . $this->wrapChar, $pgs); |
|
116 | + return implode($this->wrapChar.$this->wrapChar, $pgs); |
|
117 | 117 | } |
118 | 118 | } |
119 | 119 | } |
@@ -42,54 +42,54 @@ |
||
42 | 42 | */ |
43 | 43 | class PluginCapture extends BlockPlugin implements ICompilableBlock |
44 | 44 | { |
45 | - /** |
|
46 | - * @param string $name |
|
47 | - * @param null $assign |
|
48 | - * @param bool $cat |
|
49 | - * @param bool $trim |
|
50 | - */ |
|
51 | - public function init($name = 'default', $assign = null, $cat = false, $trim = false) |
|
52 | - { |
|
53 | - } |
|
45 | + /** |
|
46 | + * @param string $name |
|
47 | + * @param null $assign |
|
48 | + * @param bool $cat |
|
49 | + * @param bool $trim |
|
50 | + */ |
|
51 | + public function init($name = 'default', $assign = null, $cat = false, $trim = false) |
|
52 | + { |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * @param Compiler $compiler |
|
57 | - * @param array $params |
|
58 | - * @param string $prepend |
|
59 | - * @param string $append |
|
60 | - * @param string $type |
|
61 | - * |
|
62 | - * @return string |
|
63 | - */ |
|
64 | - public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type) |
|
65 | - { |
|
66 | - return Compiler::PHP_OPEN . $prepend . 'ob_start();' . $append . Compiler::PHP_CLOSE; |
|
67 | - } |
|
55 | + /** |
|
56 | + * @param Compiler $compiler |
|
57 | + * @param array $params |
|
58 | + * @param string $prepend |
|
59 | + * @param string $append |
|
60 | + * @param string $type |
|
61 | + * |
|
62 | + * @return string |
|
63 | + */ |
|
64 | + public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type) |
|
65 | + { |
|
66 | + return Compiler::PHP_OPEN . $prepend . 'ob_start();' . $append . Compiler::PHP_CLOSE; |
|
67 | + } |
|
68 | 68 | |
69 | - /** |
|
70 | - * @param Compiler $compiler |
|
71 | - * @param array $params |
|
72 | - * @param string $prepend |
|
73 | - * @param string $append |
|
74 | - * @param string $content |
|
75 | - * |
|
76 | - * @return string |
|
77 | - */ |
|
78 | - public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content) |
|
79 | - { |
|
80 | - $params = $compiler->getCompiledParams($params); |
|
69 | + /** |
|
70 | + * @param Compiler $compiler |
|
71 | + * @param array $params |
|
72 | + * @param string $prepend |
|
73 | + * @param string $append |
|
74 | + * @param string $content |
|
75 | + * |
|
76 | + * @return string |
|
77 | + */ |
|
78 | + public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content) |
|
79 | + { |
|
80 | + $params = $compiler->getCompiledParams($params); |
|
81 | 81 | |
82 | - $out = $content . Compiler::PHP_OPEN . $prepend . "\n" . '$tmp = ob_get_clean();'; |
|
83 | - if ($params['trim'] !== 'false' && $params['trim'] !== 0) { |
|
84 | - $out .= "\n" . '$tmp = trim($tmp);'; |
|
85 | - } |
|
86 | - if ($params['cat'] === 'true' || $params['cat'] === 1) { |
|
87 | - $out .= "\n" . '$tmp = $this->readVar(\'dwoo.capture.\'.' . $params['name'] . ') . $tmp;'; |
|
88 | - } |
|
89 | - if ($params['assign'] !== 'null') { |
|
90 | - $out .= "\n" . '$this->scope[' . $params['assign'] . '] = $tmp;'; |
|
91 | - } |
|
82 | + $out = $content . Compiler::PHP_OPEN . $prepend . "\n" . '$tmp = ob_get_clean();'; |
|
83 | + if ($params['trim'] !== 'false' && $params['trim'] !== 0) { |
|
84 | + $out .= "\n" . '$tmp = trim($tmp);'; |
|
85 | + } |
|
86 | + if ($params['cat'] === 'true' || $params['cat'] === 1) { |
|
87 | + $out .= "\n" . '$tmp = $this->readVar(\'dwoo.capture.\'.' . $params['name'] . ') . $tmp;'; |
|
88 | + } |
|
89 | + if ($params['assign'] !== 'null') { |
|
90 | + $out .= "\n" . '$this->scope[' . $params['assign'] . '] = $tmp;'; |
|
91 | + } |
|
92 | 92 | |
93 | - return $out . "\n" . '$this->globals[\'capture\'][' . $params['name'] . '] = $tmp;' . $append . Compiler::PHP_CLOSE; |
|
94 | - } |
|
93 | + return $out . "\n" . '$this->globals[\'capture\'][' . $params['name'] . '] = $tmp;' . $append . Compiler::PHP_CLOSE; |
|
94 | + } |
|
95 | 95 | } |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | */ |
64 | 64 | public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type) |
65 | 65 | { |
66 | - return Compiler::PHP_OPEN . $prepend . 'ob_start();' . $append . Compiler::PHP_CLOSE; |
|
66 | + return Compiler::PHP_OPEN.$prepend.'ob_start();'.$append.Compiler::PHP_CLOSE; |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | /** |
@@ -79,17 +79,17 @@ discard block |
||
79 | 79 | { |
80 | 80 | $params = $compiler->getCompiledParams($params); |
81 | 81 | |
82 | - $out = $content . Compiler::PHP_OPEN . $prepend . "\n" . '$tmp = ob_get_clean();'; |
|
82 | + $out = $content.Compiler::PHP_OPEN.$prepend."\n".'$tmp = ob_get_clean();'; |
|
83 | 83 | if ($params['trim'] !== 'false' && $params['trim'] !== 0) { |
84 | - $out .= "\n" . '$tmp = trim($tmp);'; |
|
84 | + $out .= "\n".'$tmp = trim($tmp);'; |
|
85 | 85 | } |
86 | 86 | if ($params['cat'] === 'true' || $params['cat'] === 1) { |
87 | - $out .= "\n" . '$tmp = $this->readVar(\'dwoo.capture.\'.' . $params['name'] . ') . $tmp;'; |
|
87 | + $out .= "\n".'$tmp = $this->readVar(\'dwoo.capture.\'.'.$params['name'].') . $tmp;'; |
|
88 | 88 | } |
89 | 89 | if ($params['assign'] !== 'null') { |
90 | - $out .= "\n" . '$this->scope[' . $params['assign'] . '] = $tmp;'; |
|
90 | + $out .= "\n".'$this->scope['.$params['assign'].'] = $tmp;'; |
|
91 | 91 | } |
92 | 92 | |
93 | - return $out . "\n" . '$this->globals[\'capture\'][' . $params['name'] . '] = $tmp;' . $append . Compiler::PHP_CLOSE; |
|
93 | + return $out."\n".'$this->globals[\'capture\']['.$params['name'].'] = $tmp;'.$append.Compiler::PHP_CLOSE; |
|
94 | 94 | } |
95 | 95 | } |
@@ -28,68 +28,68 @@ |
||
28 | 28 | */ |
29 | 29 | class PluginElseif extends PluginIf implements ICompilableBlock, IElseable |
30 | 30 | { |
31 | - /** |
|
32 | - * @param array $rest |
|
33 | - */ |
|
34 | - public function init(array $rest) |
|
35 | - { |
|
36 | - } |
|
31 | + /** |
|
32 | + * @param array $rest |
|
33 | + */ |
|
34 | + public function init(array $rest) |
|
35 | + { |
|
36 | + } |
|
37 | 37 | |
38 | - /** |
|
39 | - * @param Compiler $compiler |
|
40 | - * @param array $params |
|
41 | - * @param string $prepend |
|
42 | - * @param string $append |
|
43 | - * @param string $type |
|
44 | - * |
|
45 | - * @return string |
|
46 | - */ |
|
47 | - public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type) |
|
48 | - { |
|
49 | - $preContent = ''; |
|
50 | - while (true) { |
|
51 | - $preContent .= $compiler->removeTopBlock(); |
|
52 | - $block = &$compiler->getCurrentBlock(); |
|
53 | - $interfaces = class_implements($block['class']); |
|
54 | - if (in_array('Dwoo\IElseable', $interfaces) !== false) { |
|
55 | - break; |
|
56 | - } |
|
57 | - } |
|
38 | + /** |
|
39 | + * @param Compiler $compiler |
|
40 | + * @param array $params |
|
41 | + * @param string $prepend |
|
42 | + * @param string $append |
|
43 | + * @param string $type |
|
44 | + * |
|
45 | + * @return string |
|
46 | + */ |
|
47 | + public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type) |
|
48 | + { |
|
49 | + $preContent = ''; |
|
50 | + while (true) { |
|
51 | + $preContent .= $compiler->removeTopBlock(); |
|
52 | + $block = &$compiler->getCurrentBlock(); |
|
53 | + $interfaces = class_implements($block['class']); |
|
54 | + if (in_array('Dwoo\IElseable', $interfaces) !== false) { |
|
55 | + break; |
|
56 | + } |
|
57 | + } |
|
58 | 58 | |
59 | - $params['initialized'] = true; |
|
60 | - $compiler->injectBlock($type, $params); |
|
59 | + $params['initialized'] = true; |
|
60 | + $compiler->injectBlock($type, $params); |
|
61 | 61 | |
62 | - return $preContent; |
|
63 | - } |
|
62 | + return $preContent; |
|
63 | + } |
|
64 | 64 | |
65 | - /** |
|
66 | - * @param Compiler $compiler |
|
67 | - * @param array $params |
|
68 | - * @param string $prepend |
|
69 | - * @param string $append |
|
70 | - * @param string $content |
|
71 | - * |
|
72 | - * @return string |
|
73 | - */ |
|
74 | - public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content) |
|
75 | - { |
|
76 | - if (!isset($params['initialized'])) { |
|
77 | - return ''; |
|
78 | - } |
|
65 | + /** |
|
66 | + * @param Compiler $compiler |
|
67 | + * @param array $params |
|
68 | + * @param string $prepend |
|
69 | + * @param string $append |
|
70 | + * @param string $content |
|
71 | + * |
|
72 | + * @return string |
|
73 | + */ |
|
74 | + public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content) |
|
75 | + { |
|
76 | + if (!isset($params['initialized'])) { |
|
77 | + return ''; |
|
78 | + } |
|
79 | 79 | |
80 | - $tokens = $compiler->getParamTokens($params); |
|
81 | - $params = $compiler->getCompiledParams($params); |
|
80 | + $tokens = $compiler->getParamTokens($params); |
|
81 | + $params = $compiler->getCompiledParams($params); |
|
82 | 82 | |
83 | - $pre = Compiler::PHP_OPEN . 'elseif (' . implode(' ', self::replaceKeywords($params['*'], $tokens['*'], $compiler)) . ") {\n" . Compiler::PHP_CLOSE; |
|
84 | - $post = Compiler::PHP_OPEN . "\n}" . Compiler::PHP_CLOSE; |
|
83 | + $pre = Compiler::PHP_OPEN . 'elseif (' . implode(' ', self::replaceKeywords($params['*'], $tokens['*'], $compiler)) . ") {\n" . Compiler::PHP_CLOSE; |
|
84 | + $post = Compiler::PHP_OPEN . "\n}" . Compiler::PHP_CLOSE; |
|
85 | 85 | |
86 | - if (isset($params['hasElse'])) { |
|
87 | - $post .= $params['hasElse']; |
|
88 | - } |
|
86 | + if (isset($params['hasElse'])) { |
|
87 | + $post .= $params['hasElse']; |
|
88 | + } |
|
89 | 89 | |
90 | - $block = &$compiler->getCurrentBlock(); |
|
91 | - $block['params']['hasElse'] = $pre . $content . $post; |
|
90 | + $block = &$compiler->getCurrentBlock(); |
|
91 | + $block['params']['hasElse'] = $pre . $content . $post; |
|
92 | 92 | |
93 | - return ''; |
|
94 | - } |
|
93 | + return ''; |
|
94 | + } |
|
95 | 95 | } |
@@ -80,15 +80,15 @@ |
||
80 | 80 | $tokens = $compiler->getParamTokens($params); |
81 | 81 | $params = $compiler->getCompiledParams($params); |
82 | 82 | |
83 | - $pre = Compiler::PHP_OPEN . 'elseif (' . implode(' ', self::replaceKeywords($params['*'], $tokens['*'], $compiler)) . ") {\n" . Compiler::PHP_CLOSE; |
|
84 | - $post = Compiler::PHP_OPEN . "\n}" . Compiler::PHP_CLOSE; |
|
83 | + $pre = Compiler::PHP_OPEN.'elseif ('.implode(' ', self::replaceKeywords($params['*'], $tokens['*'], $compiler)).") {\n".Compiler::PHP_CLOSE; |
|
84 | + $post = Compiler::PHP_OPEN."\n}".Compiler::PHP_CLOSE; |
|
85 | 85 | |
86 | 86 | if (isset($params['hasElse'])) { |
87 | 87 | $post .= $params['hasElse']; |
88 | 88 | } |
89 | 89 | |
90 | 90 | $block = &$compiler->getCurrentBlock(); |
91 | - $block['params']['hasElse'] = $pre . $content . $post; |
|
91 | + $block['params']['hasElse'] = $pre.$content.$post; |
|
92 | 92 | |
93 | 93 | return ''; |
94 | 94 | } |
@@ -43,159 +43,159 @@ |
||
43 | 43 | */ |
44 | 44 | class PluginForeach extends BlockPlugin implements ICompilableBlock, IElseable |
45 | 45 | { |
46 | - public static $cnt = 0; |
|
47 | - |
|
48 | - /** |
|
49 | - * @param $from |
|
50 | - * @param null $key |
|
51 | - * @param null $item |
|
52 | - * @param string $name |
|
53 | - * @param null $implode |
|
54 | - */ |
|
55 | - public function init($from, $key = null, $item = null, $name = 'default', $implode = null) |
|
56 | - { |
|
57 | - } |
|
58 | - |
|
59 | - /** |
|
60 | - * @param Compiler $compiler |
|
61 | - * @param array $params |
|
62 | - * @param string $prepend |
|
63 | - * @param string $append |
|
64 | - * @param string $type |
|
65 | - * |
|
66 | - * @return string |
|
67 | - */ |
|
68 | - public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type) |
|
69 | - { |
|
70 | - // get block params and save the current template pointer to use it in the postProcessing method |
|
71 | - $currentBlock = &$compiler->getCurrentBlock(); |
|
72 | - $currentBlock['params']['tplPointer'] = $compiler->getPointer(); |
|
73 | - |
|
74 | - return ''; |
|
75 | - } |
|
76 | - |
|
77 | - /** |
|
78 | - * @param Compiler $compiler |
|
79 | - * @param array $params |
|
80 | - * @param string $prepend |
|
81 | - * @param string $append |
|
82 | - * @param string $content |
|
83 | - * |
|
84 | - * @return string |
|
85 | - * @throws CompilationException |
|
86 | - */ |
|
87 | - public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content) |
|
88 | - { |
|
89 | - $params = $compiler->getCompiledParams($params); |
|
90 | - $tpl = $compiler->getTemplateSource($params['tplPointer']); |
|
91 | - |
|
92 | - // assigns params |
|
93 | - $src = $params['from']; |
|
94 | - |
|
95 | - if ($params['item'] !== 'null') { |
|
96 | - if ($params['key'] !== 'null') { |
|
97 | - $key = $params['key']; |
|
98 | - } |
|
99 | - $val = $params['item']; |
|
100 | - } elseif ($params['key'] !== 'null') { |
|
101 | - $val = $params['key']; |
|
102 | - } else { |
|
103 | - throw new CompilationException($compiler, 'Foreach <em>item</em> parameter missing'); |
|
104 | - } |
|
105 | - $name = $params['name']; |
|
106 | - |
|
107 | - if (substr($val, 0, 1) !== '"' && substr($val, 0, 1) !== '\'') { |
|
108 | - throw new CompilationException($compiler, 'Foreach <em>item</em> parameter must be of type string'); |
|
109 | - } |
|
110 | - if (isset($key) && substr($val, 0, 1) !== '"' && substr($val, 0, 1) !== '\'') { |
|
111 | - throw new CompilationException($compiler, 'Foreach <em>key</em> parameter must be of type string'); |
|
112 | - } |
|
113 | - |
|
114 | - // evaluates which global variables have to be computed |
|
115 | - $varName = '$dwoo.foreach.' . trim($name, '"\'') . '.'; |
|
116 | - $shortVarName = '$.foreach.' . trim($name, '"\'') . '.'; |
|
117 | - $usesAny = strpos($tpl, $varName) !== false || strpos($tpl, $shortVarName) !== false; |
|
118 | - $usesFirst = strpos($tpl, $varName . 'first') !== false || strpos($tpl, $shortVarName . 'first') !== false; |
|
119 | - $usesLast = strpos($tpl, $varName . 'last') !== false || strpos($tpl, $shortVarName . 'last') !== false; |
|
120 | - $usesIndex = $usesFirst || strpos($tpl, $varName . 'index') !== false || strpos($tpl, $shortVarName . 'index') !== false; |
|
121 | - $usesIteration = $usesLast || strpos($tpl, $varName . 'iteration') !== false || strpos($tpl, $shortVarName . 'iteration') !== false; |
|
122 | - $usesShow = strpos($tpl, $varName . 'show') !== false || strpos($tpl, $shortVarName . 'show') !== false; |
|
123 | - $usesTotal = $usesLast || strpos($tpl, $varName . 'total') !== false || strpos($tpl, $shortVarName . 'total') !== false; |
|
124 | - |
|
125 | - if (strpos($name, '$this->scope[') !== false) { |
|
126 | - $usesAny = $usesFirst = $usesLast = $usesIndex = $usesIteration = $usesShow = $usesTotal = true; |
|
127 | - } |
|
128 | - |
|
129 | - // override globals vars if implode is used |
|
130 | - if ($params['implode'] !== 'null') { |
|
131 | - $implode = $params['implode']; |
|
132 | - $usesAny = true; |
|
133 | - $usesLast = true; |
|
134 | - $usesIteration = true; |
|
135 | - $usesTotal = true; |
|
136 | - } |
|
137 | - |
|
138 | - // gets foreach id |
|
139 | - $cnt = self::$cnt ++; |
|
140 | - |
|
141 | - // build pre content output |
|
142 | - $pre = Compiler::PHP_OPEN . "\n" . '$_fh' . $cnt . '_data = ' . $src . ';'; |
|
143 | - // adds foreach properties |
|
144 | - if ($usesAny) { |
|
145 | - $pre .= "\n" . '$this->globals["foreach"][' . $name . '] = array' . "\n("; |
|
146 | - if ($usesIndex) { |
|
147 | - $pre .= "\n\t" . '"index" => 0,'; |
|
148 | - } |
|
149 | - if ($usesIteration) { |
|
150 | - $pre .= "\n\t" . '"iteration" => 1,'; |
|
151 | - } |
|
152 | - if ($usesFirst) { |
|
153 | - $pre .= "\n\t" . '"first" => null,'; |
|
154 | - } |
|
155 | - if ($usesLast) { |
|
156 | - $pre .= "\n\t" . '"last" => null,'; |
|
157 | - } |
|
158 | - if ($usesShow) { |
|
159 | - $pre .= "\n\t" . '"show" => $this->isArray($_fh' . $cnt . '_data, true),'; |
|
160 | - } |
|
161 | - if ($usesTotal) { |
|
162 | - $pre .= "\n\t" . '"total" => $this->count($_fh' . $cnt . '_data),'; |
|
163 | - } |
|
164 | - $pre .= "\n);\n" . '$_fh' . $cnt . '_glob =& $this->globals["foreach"][' . $name . '];'; |
|
165 | - } |
|
166 | - // checks if foreach must be looped |
|
167 | - $pre .= "\n" . 'if ($this->isTraversable($_fh' . $cnt . '_data' . (isset($params['hasElse']) ? ', true' : '') . ') == true)' . "\n{"; |
|
168 | - // iterates over keys |
|
169 | - $pre .= "\n\t" . 'foreach ($_fh' . $cnt . '_data as ' . (isset($key) ? '$this->scope[' . $key . ']=>' : '') . '$this->scope[' . $val . '])' . "\n\t{"; |
|
170 | - // updates properties |
|
171 | - if ($usesFirst) { |
|
172 | - $pre .= "\n\t\t" . '$_fh' . $cnt . '_glob["first"] = (string) ($_fh' . $cnt . '_glob["index"] === 0);'; |
|
173 | - } |
|
174 | - if ($usesLast) { |
|
175 | - $pre .= "\n\t\t" . '$_fh' . $cnt . '_glob["last"] = (string) ($_fh' . $cnt . '_glob["iteration"] === $_fh' . $cnt . '_glob["total"]);'; |
|
176 | - } |
|
177 | - $pre .= "\n/* -- foreach start output */\n" . Compiler::PHP_CLOSE; |
|
178 | - |
|
179 | - // build post content output |
|
180 | - $post = Compiler::PHP_OPEN . "\n"; |
|
181 | - |
|
182 | - if (isset($implode)) { |
|
183 | - $post .= '/* -- implode */' . "\n" . 'if (!$_fh' . $cnt . '_glob["last"]) {' . "\n\t" . 'echo ' . $implode . ";\n}\n"; |
|
184 | - } |
|
185 | - $post .= '/* -- foreach end output */'; |
|
186 | - // update properties |
|
187 | - if ($usesIndex) { |
|
188 | - $post .= "\n\t\t" . '$_fh' . $cnt . '_glob["index"]+=1;'; |
|
189 | - } |
|
190 | - if ($usesIteration) { |
|
191 | - $post .= "\n\t\t" . '$_fh' . $cnt . '_glob["iteration"]+=1;'; |
|
192 | - } |
|
193 | - // end loop |
|
194 | - $post .= "\n\t}\n}" . Compiler::PHP_CLOSE; |
|
195 | - if (isset($params['hasElse'])) { |
|
196 | - $post .= $params['hasElse']; |
|
197 | - } |
|
198 | - |
|
199 | - return $pre . $content . $post; |
|
200 | - } |
|
46 | + public static $cnt = 0; |
|
47 | + |
|
48 | + /** |
|
49 | + * @param $from |
|
50 | + * @param null $key |
|
51 | + * @param null $item |
|
52 | + * @param string $name |
|
53 | + * @param null $implode |
|
54 | + */ |
|
55 | + public function init($from, $key = null, $item = null, $name = 'default', $implode = null) |
|
56 | + { |
|
57 | + } |
|
58 | + |
|
59 | + /** |
|
60 | + * @param Compiler $compiler |
|
61 | + * @param array $params |
|
62 | + * @param string $prepend |
|
63 | + * @param string $append |
|
64 | + * @param string $type |
|
65 | + * |
|
66 | + * @return string |
|
67 | + */ |
|
68 | + public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type) |
|
69 | + { |
|
70 | + // get block params and save the current template pointer to use it in the postProcessing method |
|
71 | + $currentBlock = &$compiler->getCurrentBlock(); |
|
72 | + $currentBlock['params']['tplPointer'] = $compiler->getPointer(); |
|
73 | + |
|
74 | + return ''; |
|
75 | + } |
|
76 | + |
|
77 | + /** |
|
78 | + * @param Compiler $compiler |
|
79 | + * @param array $params |
|
80 | + * @param string $prepend |
|
81 | + * @param string $append |
|
82 | + * @param string $content |
|
83 | + * |
|
84 | + * @return string |
|
85 | + * @throws CompilationException |
|
86 | + */ |
|
87 | + public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content) |
|
88 | + { |
|
89 | + $params = $compiler->getCompiledParams($params); |
|
90 | + $tpl = $compiler->getTemplateSource($params['tplPointer']); |
|
91 | + |
|
92 | + // assigns params |
|
93 | + $src = $params['from']; |
|
94 | + |
|
95 | + if ($params['item'] !== 'null') { |
|
96 | + if ($params['key'] !== 'null') { |
|
97 | + $key = $params['key']; |
|
98 | + } |
|
99 | + $val = $params['item']; |
|
100 | + } elseif ($params['key'] !== 'null') { |
|
101 | + $val = $params['key']; |
|
102 | + } else { |
|
103 | + throw new CompilationException($compiler, 'Foreach <em>item</em> parameter missing'); |
|
104 | + } |
|
105 | + $name = $params['name']; |
|
106 | + |
|
107 | + if (substr($val, 0, 1) !== '"' && substr($val, 0, 1) !== '\'') { |
|
108 | + throw new CompilationException($compiler, 'Foreach <em>item</em> parameter must be of type string'); |
|
109 | + } |
|
110 | + if (isset($key) && substr($val, 0, 1) !== '"' && substr($val, 0, 1) !== '\'') { |
|
111 | + throw new CompilationException($compiler, 'Foreach <em>key</em> parameter must be of type string'); |
|
112 | + } |
|
113 | + |
|
114 | + // evaluates which global variables have to be computed |
|
115 | + $varName = '$dwoo.foreach.' . trim($name, '"\'') . '.'; |
|
116 | + $shortVarName = '$.foreach.' . trim($name, '"\'') . '.'; |
|
117 | + $usesAny = strpos($tpl, $varName) !== false || strpos($tpl, $shortVarName) !== false; |
|
118 | + $usesFirst = strpos($tpl, $varName . 'first') !== false || strpos($tpl, $shortVarName . 'first') !== false; |
|
119 | + $usesLast = strpos($tpl, $varName . 'last') !== false || strpos($tpl, $shortVarName . 'last') !== false; |
|
120 | + $usesIndex = $usesFirst || strpos($tpl, $varName . 'index') !== false || strpos($tpl, $shortVarName . 'index') !== false; |
|
121 | + $usesIteration = $usesLast || strpos($tpl, $varName . 'iteration') !== false || strpos($tpl, $shortVarName . 'iteration') !== false; |
|
122 | + $usesShow = strpos($tpl, $varName . 'show') !== false || strpos($tpl, $shortVarName . 'show') !== false; |
|
123 | + $usesTotal = $usesLast || strpos($tpl, $varName . 'total') !== false || strpos($tpl, $shortVarName . 'total') !== false; |
|
124 | + |
|
125 | + if (strpos($name, '$this->scope[') !== false) { |
|
126 | + $usesAny = $usesFirst = $usesLast = $usesIndex = $usesIteration = $usesShow = $usesTotal = true; |
|
127 | + } |
|
128 | + |
|
129 | + // override globals vars if implode is used |
|
130 | + if ($params['implode'] !== 'null') { |
|
131 | + $implode = $params['implode']; |
|
132 | + $usesAny = true; |
|
133 | + $usesLast = true; |
|
134 | + $usesIteration = true; |
|
135 | + $usesTotal = true; |
|
136 | + } |
|
137 | + |
|
138 | + // gets foreach id |
|
139 | + $cnt = self::$cnt ++; |
|
140 | + |
|
141 | + // build pre content output |
|
142 | + $pre = Compiler::PHP_OPEN . "\n" . '$_fh' . $cnt . '_data = ' . $src . ';'; |
|
143 | + // adds foreach properties |
|
144 | + if ($usesAny) { |
|
145 | + $pre .= "\n" . '$this->globals["foreach"][' . $name . '] = array' . "\n("; |
|
146 | + if ($usesIndex) { |
|
147 | + $pre .= "\n\t" . '"index" => 0,'; |
|
148 | + } |
|
149 | + if ($usesIteration) { |
|
150 | + $pre .= "\n\t" . '"iteration" => 1,'; |
|
151 | + } |
|
152 | + if ($usesFirst) { |
|
153 | + $pre .= "\n\t" . '"first" => null,'; |
|
154 | + } |
|
155 | + if ($usesLast) { |
|
156 | + $pre .= "\n\t" . '"last" => null,'; |
|
157 | + } |
|
158 | + if ($usesShow) { |
|
159 | + $pre .= "\n\t" . '"show" => $this->isArray($_fh' . $cnt . '_data, true),'; |
|
160 | + } |
|
161 | + if ($usesTotal) { |
|
162 | + $pre .= "\n\t" . '"total" => $this->count($_fh' . $cnt . '_data),'; |
|
163 | + } |
|
164 | + $pre .= "\n);\n" . '$_fh' . $cnt . '_glob =& $this->globals["foreach"][' . $name . '];'; |
|
165 | + } |
|
166 | + // checks if foreach must be looped |
|
167 | + $pre .= "\n" . 'if ($this->isTraversable($_fh' . $cnt . '_data' . (isset($params['hasElse']) ? ', true' : '') . ') == true)' . "\n{"; |
|
168 | + // iterates over keys |
|
169 | + $pre .= "\n\t" . 'foreach ($_fh' . $cnt . '_data as ' . (isset($key) ? '$this->scope[' . $key . ']=>' : '') . '$this->scope[' . $val . '])' . "\n\t{"; |
|
170 | + // updates properties |
|
171 | + if ($usesFirst) { |
|
172 | + $pre .= "\n\t\t" . '$_fh' . $cnt . '_glob["first"] = (string) ($_fh' . $cnt . '_glob["index"] === 0);'; |
|
173 | + } |
|
174 | + if ($usesLast) { |
|
175 | + $pre .= "\n\t\t" . '$_fh' . $cnt . '_glob["last"] = (string) ($_fh' . $cnt . '_glob["iteration"] === $_fh' . $cnt . '_glob["total"]);'; |
|
176 | + } |
|
177 | + $pre .= "\n/* -- foreach start output */\n" . Compiler::PHP_CLOSE; |
|
178 | + |
|
179 | + // build post content output |
|
180 | + $post = Compiler::PHP_OPEN . "\n"; |
|
181 | + |
|
182 | + if (isset($implode)) { |
|
183 | + $post .= '/* -- implode */' . "\n" . 'if (!$_fh' . $cnt . '_glob["last"]) {' . "\n\t" . 'echo ' . $implode . ";\n}\n"; |
|
184 | + } |
|
185 | + $post .= '/* -- foreach end output */'; |
|
186 | + // update properties |
|
187 | + if ($usesIndex) { |
|
188 | + $post .= "\n\t\t" . '$_fh' . $cnt . '_glob["index"]+=1;'; |
|
189 | + } |
|
190 | + if ($usesIteration) { |
|
191 | + $post .= "\n\t\t" . '$_fh' . $cnt . '_glob["iteration"]+=1;'; |
|
192 | + } |
|
193 | + // end loop |
|
194 | + $post .= "\n\t}\n}" . Compiler::PHP_CLOSE; |
|
195 | + if (isset($params['hasElse'])) { |
|
196 | + $post .= $params['hasElse']; |
|
197 | + } |
|
198 | + |
|
199 | + return $pre . $content . $post; |
|
200 | + } |
|
201 | 201 | } |
@@ -112,15 +112,15 @@ discard block |
||
112 | 112 | } |
113 | 113 | |
114 | 114 | // evaluates which global variables have to be computed |
115 | - $varName = '$dwoo.foreach.' . trim($name, '"\'') . '.'; |
|
116 | - $shortVarName = '$.foreach.' . trim($name, '"\'') . '.'; |
|
115 | + $varName = '$dwoo.foreach.'.trim($name, '"\'').'.'; |
|
116 | + $shortVarName = '$.foreach.'.trim($name, '"\'').'.'; |
|
117 | 117 | $usesAny = strpos($tpl, $varName) !== false || strpos($tpl, $shortVarName) !== false; |
118 | - $usesFirst = strpos($tpl, $varName . 'first') !== false || strpos($tpl, $shortVarName . 'first') !== false; |
|
119 | - $usesLast = strpos($tpl, $varName . 'last') !== false || strpos($tpl, $shortVarName . 'last') !== false; |
|
120 | - $usesIndex = $usesFirst || strpos($tpl, $varName . 'index') !== false || strpos($tpl, $shortVarName . 'index') !== false; |
|
121 | - $usesIteration = $usesLast || strpos($tpl, $varName . 'iteration') !== false || strpos($tpl, $shortVarName . 'iteration') !== false; |
|
122 | - $usesShow = strpos($tpl, $varName . 'show') !== false || strpos($tpl, $shortVarName . 'show') !== false; |
|
123 | - $usesTotal = $usesLast || strpos($tpl, $varName . 'total') !== false || strpos($tpl, $shortVarName . 'total') !== false; |
|
118 | + $usesFirst = strpos($tpl, $varName.'first') !== false || strpos($tpl, $shortVarName.'first') !== false; |
|
119 | + $usesLast = strpos($tpl, $varName.'last') !== false || strpos($tpl, $shortVarName.'last') !== false; |
|
120 | + $usesIndex = $usesFirst || strpos($tpl, $varName.'index') !== false || strpos($tpl, $shortVarName.'index') !== false; |
|
121 | + $usesIteration = $usesLast || strpos($tpl, $varName.'iteration') !== false || strpos($tpl, $shortVarName.'iteration') !== false; |
|
122 | + $usesShow = strpos($tpl, $varName.'show') !== false || strpos($tpl, $shortVarName.'show') !== false; |
|
123 | + $usesTotal = $usesLast || strpos($tpl, $varName.'total') !== false || strpos($tpl, $shortVarName.'total') !== false; |
|
124 | 124 | |
125 | 125 | if (strpos($name, '$this->scope[') !== false) { |
126 | 126 | $usesAny = $usesFirst = $usesLast = $usesIndex = $usesIteration = $usesShow = $usesTotal = true; |
@@ -136,66 +136,66 @@ discard block |
||
136 | 136 | } |
137 | 137 | |
138 | 138 | // gets foreach id |
139 | - $cnt = self::$cnt ++; |
|
139 | + $cnt = self::$cnt++; |
|
140 | 140 | |
141 | 141 | // build pre content output |
142 | - $pre = Compiler::PHP_OPEN . "\n" . '$_fh' . $cnt . '_data = ' . $src . ';'; |
|
142 | + $pre = Compiler::PHP_OPEN."\n".'$_fh'.$cnt.'_data = '.$src.';'; |
|
143 | 143 | // adds foreach properties |
144 | 144 | if ($usesAny) { |
145 | - $pre .= "\n" . '$this->globals["foreach"][' . $name . '] = array' . "\n("; |
|
145 | + $pre .= "\n".'$this->globals["foreach"]['.$name.'] = array'."\n("; |
|
146 | 146 | if ($usesIndex) { |
147 | - $pre .= "\n\t" . '"index" => 0,'; |
|
147 | + $pre .= "\n\t".'"index" => 0,'; |
|
148 | 148 | } |
149 | 149 | if ($usesIteration) { |
150 | - $pre .= "\n\t" . '"iteration" => 1,'; |
|
150 | + $pre .= "\n\t".'"iteration" => 1,'; |
|
151 | 151 | } |
152 | 152 | if ($usesFirst) { |
153 | - $pre .= "\n\t" . '"first" => null,'; |
|
153 | + $pre .= "\n\t".'"first" => null,'; |
|
154 | 154 | } |
155 | 155 | if ($usesLast) { |
156 | - $pre .= "\n\t" . '"last" => null,'; |
|
156 | + $pre .= "\n\t".'"last" => null,'; |
|
157 | 157 | } |
158 | 158 | if ($usesShow) { |
159 | - $pre .= "\n\t" . '"show" => $this->isArray($_fh' . $cnt . '_data, true),'; |
|
159 | + $pre .= "\n\t".'"show" => $this->isArray($_fh'.$cnt.'_data, true),'; |
|
160 | 160 | } |
161 | 161 | if ($usesTotal) { |
162 | - $pre .= "\n\t" . '"total" => $this->count($_fh' . $cnt . '_data),'; |
|
162 | + $pre .= "\n\t".'"total" => $this->count($_fh'.$cnt.'_data),'; |
|
163 | 163 | } |
164 | - $pre .= "\n);\n" . '$_fh' . $cnt . '_glob =& $this->globals["foreach"][' . $name . '];'; |
|
164 | + $pre .= "\n);\n".'$_fh'.$cnt.'_glob =& $this->globals["foreach"]['.$name.'];'; |
|
165 | 165 | } |
166 | 166 | // checks if foreach must be looped |
167 | - $pre .= "\n" . 'if ($this->isTraversable($_fh' . $cnt . '_data' . (isset($params['hasElse']) ? ', true' : '') . ') == true)' . "\n{"; |
|
167 | + $pre .= "\n".'if ($this->isTraversable($_fh'.$cnt.'_data'.(isset($params['hasElse']) ? ', true' : '').') == true)'."\n{"; |
|
168 | 168 | // iterates over keys |
169 | - $pre .= "\n\t" . 'foreach ($_fh' . $cnt . '_data as ' . (isset($key) ? '$this->scope[' . $key . ']=>' : '') . '$this->scope[' . $val . '])' . "\n\t{"; |
|
169 | + $pre .= "\n\t".'foreach ($_fh'.$cnt.'_data as '.(isset($key) ? '$this->scope['.$key.']=>' : '').'$this->scope['.$val.'])'."\n\t{"; |
|
170 | 170 | // updates properties |
171 | 171 | if ($usesFirst) { |
172 | - $pre .= "\n\t\t" . '$_fh' . $cnt . '_glob["first"] = (string) ($_fh' . $cnt . '_glob["index"] === 0);'; |
|
172 | + $pre .= "\n\t\t".'$_fh'.$cnt.'_glob["first"] = (string) ($_fh'.$cnt.'_glob["index"] === 0);'; |
|
173 | 173 | } |
174 | 174 | if ($usesLast) { |
175 | - $pre .= "\n\t\t" . '$_fh' . $cnt . '_glob["last"] = (string) ($_fh' . $cnt . '_glob["iteration"] === $_fh' . $cnt . '_glob["total"]);'; |
|
175 | + $pre .= "\n\t\t".'$_fh'.$cnt.'_glob["last"] = (string) ($_fh'.$cnt.'_glob["iteration"] === $_fh'.$cnt.'_glob["total"]);'; |
|
176 | 176 | } |
177 | - $pre .= "\n/* -- foreach start output */\n" . Compiler::PHP_CLOSE; |
|
177 | + $pre .= "\n/* -- foreach start output */\n".Compiler::PHP_CLOSE; |
|
178 | 178 | |
179 | 179 | // build post content output |
180 | - $post = Compiler::PHP_OPEN . "\n"; |
|
180 | + $post = Compiler::PHP_OPEN."\n"; |
|
181 | 181 | |
182 | 182 | if (isset($implode)) { |
183 | - $post .= '/* -- implode */' . "\n" . 'if (!$_fh' . $cnt . '_glob["last"]) {' . "\n\t" . 'echo ' . $implode . ";\n}\n"; |
|
183 | + $post .= '/* -- implode */'."\n".'if (!$_fh'.$cnt.'_glob["last"]) {'."\n\t".'echo '.$implode.";\n}\n"; |
|
184 | 184 | } |
185 | 185 | $post .= '/* -- foreach end output */'; |
186 | 186 | // update properties |
187 | 187 | if ($usesIndex) { |
188 | - $post .= "\n\t\t" . '$_fh' . $cnt . '_glob["index"]+=1;'; |
|
188 | + $post .= "\n\t\t".'$_fh'.$cnt.'_glob["index"]+=1;'; |
|
189 | 189 | } |
190 | 190 | if ($usesIteration) { |
191 | - $post .= "\n\t\t" . '$_fh' . $cnt . '_glob["iteration"]+=1;'; |
|
191 | + $post .= "\n\t\t".'$_fh'.$cnt.'_glob["iteration"]+=1;'; |
|
192 | 192 | } |
193 | 193 | // end loop |
194 | - $post .= "\n\t}\n}" . Compiler::PHP_CLOSE; |
|
194 | + $post .= "\n\t}\n}".Compiler::PHP_CLOSE; |
|
195 | 195 | if (isset($params['hasElse'])) { |
196 | 196 | $post .= $params['hasElse']; |
197 | 197 | } |
198 | 198 | |
199 | - return $pre . $content . $post; |
|
199 | + return $pre.$content.$post; |
|
200 | 200 | } |
201 | 201 | } |