@@ -53,278 +53,3 @@ |
||
53 | 53 | */ |
54 | 54 | |
55 | 55 | const REGEX_PARSE_LINE = <<<'ENDREGEX' |
56 | - /^(\s*)(?:(?:([a-zA-Z0-9-]*)((?:[\.#!][\w\-\_]+)*)(\[(?:(?:\{\$[^\}]+\})?[^\\\]{]*?(?:\\.)*?(?:{[^\$])*?)+\])?)|([_\/]{1,3})|([\|:\$]\w+)|({?\$[^}]+}?)|)(?: (.*))?$/ |
|
57 | - ENDREGEX; |
|
58 | - |
|
59 | - /** |
|
60 | - * @var int Current Line Number |
|
61 | - */ |
|
62 | - protected int $lineNo = 0; |
|
63 | - /** |
|
64 | - * @var int Total Lines in File |
|
65 | - */ |
|
66 | - protected int $lineCount = 0; |
|
67 | - |
|
68 | - function __construct() |
|
69 | - { |
|
70 | - $this->init(); |
|
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * Clear Lines, and Line Number, so if output is |
|
75 | - * called, no output will be produced |
|
76 | - */ |
|
77 | - protected function init():void |
|
78 | - { |
|
79 | - $this->lines = []; |
|
80 | - $this->lineNo = 0; |
|
81 | - $this->lineCount = 0; |
|
82 | - $this->root = []; |
|
83 | - } |
|
84 | - |
|
85 | - protected function loadLines(string $s):void |
|
86 | - { |
|
87 | - $this->lines = explode("\n", str_replace("\r", '', $s)); |
|
88 | - $this->lineCount = count($this->lines); |
|
89 | - $this->lineNo = 0; |
|
90 | - } |
|
91 | - |
|
92 | - function parseFilter(ParseFilter $filter):void |
|
93 | - { |
|
94 | - foreach ($this->root as $k => $tag) { |
|
95 | - $this->root[$k] = $filter->filterTag($tag); |
|
96 | - } |
|
97 | - } |
|
98 | - |
|
99 | - function parseSnip(string $s):void |
|
100 | - { |
|
101 | - //save root tags |
|
102 | - /** @var Tag[] $roots */ |
|
103 | - $roots = $this->root; |
|
104 | - $this->root = []; |
|
105 | - $this->loadLines($s); |
|
106 | - $this->procLines(); |
|
107 | - $this->root = array_merge($roots, $this->root); |
|
108 | - } |
|
109 | - |
|
110 | - function applySnip():void |
|
111 | - { |
|
112 | - /** @var Tag\Snippet[] $fwdSnip */ |
|
113 | - $fwdSnip = []; |
|
114 | - /** @var Tag\Snippet[] $revSnip */ |
|
115 | - $revSnip = []; |
|
116 | - /** @var Tag[] $roots */ |
|
117 | - $roots = []; |
|
118 | - foreach ($this->root as $snip) { |
|
119 | - if ($snip instanceof Tag\Snippet) { |
|
120 | - if ($snip->getType() == 'append') { |
|
121 | - array_unshift($revSnip, $snip); |
|
122 | - } else { |
|
123 | - $fwdSnip[] = $snip; |
|
124 | - } |
|
125 | - } else { |
|
126 | - $roots[] = $snip; |
|
127 | - } |
|
128 | - } |
|
129 | - foreach ($fwdSnip as $snip) { |
|
130 | - foreach ($roots as $root) { |
|
131 | - $snip->apply($root); |
|
132 | - } |
|
133 | - } |
|
134 | - foreach ($revSnip as $snip) { |
|
135 | - foreach ($roots as $root) { |
|
136 | - $snip->apply($root); |
|
137 | - } |
|
138 | - } |
|
139 | - $this->root = $roots; |
|
140 | - } |
|
141 | - |
|
142 | - /** |
|
143 | - * Parse HAMLE template, from a string |
|
144 | - * @param string $s String to parse |
|
145 | - */ |
|
146 | - function str($s):void |
|
147 | - { |
|
148 | - $this->init(); |
|
149 | - $this->loadLines($s); |
|
150 | - $this->procLines(); |
|
151 | - } |
|
152 | - |
|
153 | - function procLines():void |
|
154 | - { |
|
155 | - /* @var $heir Tag[] Tag Heirachy Array */ |
|
156 | - $heir = []; |
|
157 | - while ($this->lineNo < $this->lineCount) { |
|
158 | - $line = $this->lines[$this->lineNo]; |
|
159 | - if (trim($line)) { |
|
160 | - if (preg_match(self::REGEX_PARSE_LINE, $line, $m)) { |
|
161 | - if (false !== strpos($m[1], "\t")) { |
|
162 | - throw new ParseError( |
|
163 | - 'Tabs are not supported in templates at this time', |
|
164 | - ); |
|
165 | - } |
|
166 | - $indent = strlen($m[1]); |
|
167 | - $tag = isset($m[2]) ? ($tag = $m[2]) : ''; |
|
168 | - $classid = isset($m[3]) ? $m[3] : ''; |
|
169 | - $params = str_replace( |
|
170 | - ['\[', '\]', '\\&'], |
|
171 | - ['[', ']', '%26'], |
|
172 | - isset($m[4]) ? $m[4] : '', |
|
173 | - ); |
|
174 | - $textcode = isset($m[5]) ? $m[5] : ''; |
|
175 | - $text = isset($m[8]) ? $m[8] : ''; |
|
176 | - $code = isset($m[6]) ? $m[6] : ''; |
|
177 | - $i = self::indentLevel($indent); |
|
178 | - unset($m[0]); |
|
179 | - switch (strlen($code) ? $code[0] : ($textcode ? $textcode : '')) { |
|
180 | - case '|': //Control Tag |
|
181 | - if ($code == '|snippet') { |
|
182 | - $hTag = new Tag\Snippet($text); |
|
183 | - } elseif ($code == '|form') { |
|
184 | - $hTag = new Tag\Form($text); |
|
185 | - } elseif ($code == '|formhint') { |
|
186 | - $hTag = new Tag\FormHint(); |
|
187 | - } elseif ($code == '|else') { |
|
188 | - $hTag = new Tag\Control(substr($code, 1), $heir[$i - 1]); |
|
189 | - $hTag->setVar($text); |
|
190 | - } else { |
|
191 | - $hTag = new Tag\Control(substr($code, 1)); |
|
192 | - $hTag->setVar($text); |
|
193 | - } |
|
194 | - break; |
|
195 | - case ':': //Filter Tag |
|
196 | - $hTag = new Tag\Filter(substr($code, 1)); |
|
197 | - $hTag->addContent($text, Text::TOKEN_CODE); |
|
198 | - foreach ($this->consumeBlock($indent) as $l) { |
|
199 | - $hTag->addContent($l, Text::TOKEN_CODE); |
|
200 | - } |
|
201 | - break; |
|
202 | - case '_': //String Tag |
|
203 | - case '__': //Unescape String Tag |
|
204 | - case '___': //Unescape String Tag (with unescaped vars) |
|
205 | - $hTag = new Tag\Text($textcode); |
|
206 | - $hTag->addContent($text); |
|
207 | - break; |
|
208 | - case '___': //Unescape String Tag |
|
209 | - $hTag = new Tag\Text($textcode); |
|
210 | - $hTag->addContent($text); |
|
211 | - break; |
|
212 | - case '/': // HTML Comment |
|
213 | - case '//': // Non Printed Comment |
|
214 | - $hTag = new Tag\Comment($textcode); |
|
215 | - $hTag->addContent($text); |
|
216 | - foreach ($this->consumeBlock($indent) as $l) { |
|
217 | - $hTag->addContent($l, Text::TOKEN_CODE); |
|
218 | - } |
|
219 | - break; |
|
220 | - default: |
|
221 | - $attr = []; |
|
222 | - if (isset($params[0]) && $params[0] == '[') { |
|
223 | - $param = substr($params, 1, -1); |
|
224 | - $param = str_replace(['+', '\\&'], ['%2B', '%26'], $param); |
|
225 | - $attr = $this->parseQueryString($param); |
|
226 | - } |
|
227 | - $class = []; |
|
228 | - $id = ''; |
|
229 | - $ref = ''; |
|
230 | - preg_match_all('/[#\.!][a-zA-Z0-9\-\_]+/m', $classid, $cid); |
|
231 | - if (isset($cid[0])) { |
|
232 | - foreach ($cid[0] as $s) { |
|
233 | - if ($s[0] == '#') { |
|
234 | - $id = substr($s, 1); |
|
235 | - } |
|
236 | - if ($s[0] == '.') { |
|
237 | - $class[] = substr($s, 1); |
|
238 | - } |
|
239 | - if ($s[0] == '!') { |
|
240 | - $ref = substr($s, 1); |
|
241 | - } |
|
242 | - } |
|
243 | - } |
|
244 | - if ($ref) { |
|
245 | - $hTag = new Tag\DynHtml($tag, $class, $attr, $id, $ref); |
|
246 | - } else { |
|
247 | - $hTag = new Tag\Html($tag, $class, $attr, $id); |
|
248 | - } |
|
249 | - $hTag->addContent($text); |
|
250 | - break; |
|
251 | - } |
|
252 | - $heir[$i] = $hTag; |
|
253 | - if ($i > 0) { |
|
254 | - $heir[$i - 1]->addChild($hTag); |
|
255 | - } else { |
|
256 | - $this->root[] = $hTag; |
|
257 | - } |
|
258 | - } else { |
|
259 | - throw new ParseError( |
|
260 | - "Unable to parse line {$this->lineNo}\n\"$line\"/" . |
|
261 | - preg_last_error(), |
|
262 | - ); |
|
263 | - } |
|
264 | - } |
|
265 | - $this->lineNo++; |
|
266 | - } |
|
267 | - } |
|
268 | - |
|
269 | - function parseQueryString(string $qs):array |
|
270 | - { |
|
271 | - $out = []; |
|
272 | - foreach (explode('&', $qs) as $s) { |
|
273 | - $kv = explode('=', $s, 2); |
|
274 | - $out[urldecode($kv[0])] = isset($kv[1]) ? urldecode($kv[1]) : null; |
|
275 | - } |
|
276 | - return $out; |
|
277 | - } |
|
278 | - |
|
279 | - function output(bool $minify = false):string |
|
280 | - { |
|
281 | - $out = "<?php\nuse Seufert\\Hamle;\n?>"; |
|
282 | - foreach ($this->root as $tag) { |
|
283 | - $out .= $tag->render(0, $minify); |
|
284 | - } |
|
285 | - return $out; |
|
286 | - } |
|
287 | - |
|
288 | - function consumeBlock(int $indent):array |
|
289 | - { |
|
290 | - $out = []; |
|
291 | - $m = []; |
|
292 | - while ( |
|
293 | - $this->lineNo + 1 < $this->lineCount && |
|
294 | - (!trim($this->lines[$this->lineNo + 1]) || |
|
295 | - preg_match( |
|
296 | - '/^(\s){' . $indent . '}((\s)+[^\s].*)$/', |
|
297 | - $this->lines[$this->lineNo + 1], |
|
298 | - $m, |
|
299 | - )) |
|
300 | - ) { |
|
301 | - if (trim($this->lines[$this->lineNo + 1])) { |
|
302 | - $out[] = $m[2]; |
|
303 | - } |
|
304 | - $this->lineNo++; |
|
305 | - } |
|
306 | - return $out; |
|
307 | - } |
|
308 | - |
|
309 | - function indentLevel(int $indent):int |
|
310 | - { |
|
311 | - if (!count($this->indents)) { |
|
312 | - $this->indents = [0 => $indent]; |
|
313 | - // Key = indent level, Value = Depth in spaces |
|
314 | - return 0; |
|
315 | - } |
|
316 | - foreach ($this->indents as $k => $v) { |
|
317 | - if ($v == $indent) { |
|
318 | - $this->indents = array_slice($this->indents, 0, 1 + (int) $k ); |
|
319 | - return $k; |
|
320 | - } |
|
321 | - } |
|
322 | - $this->indents[] = $indent; |
|
323 | - return max(array_keys($this->indents)); |
|
324 | - } |
|
325 | - |
|
326 | - function getLineNo():int |
|
327 | - { |
|
328 | - return $this->lineNo; |
|
329 | - } |
|
330 | -} |
@@ -53,278 +53,3 @@ |
||
53 | 53 | */ |
54 | 54 | |
55 | 55 | const REGEX_PARSE_LINE = <<<'ENDREGEX' |
56 | - /^(\s*)(?:(?:([a-zA-Z0-9-]*)((?:[\.#!][\w\-\_]+)*)(\[(?:(?:\{\$[^\}]+\})?[^\\\]{]*?(?:\\.)*?(?:{[^\$])*?)+\])?)|([_\/]{1,3})|([\|:\$]\w+)|({?\$[^}]+}?)|)(?: (.*))?$/ |
|
57 | - ENDREGEX; |
|
58 | - |
|
59 | - /** |
|
60 | - * @var int Current Line Number |
|
61 | - */ |
|
62 | - protected int $lineNo = 0; |
|
63 | - /** |
|
64 | - * @var int Total Lines in File |
|
65 | - */ |
|
66 | - protected int $lineCount = 0; |
|
67 | - |
|
68 | - function __construct() |
|
69 | - { |
|
70 | - $this->init(); |
|
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * Clear Lines, and Line Number, so if output is |
|
75 | - * called, no output will be produced |
|
76 | - */ |
|
77 | - protected function init():void |
|
78 | - { |
|
79 | - $this->lines = []; |
|
80 | - $this->lineNo = 0; |
|
81 | - $this->lineCount = 0; |
|
82 | - $this->root = []; |
|
83 | - } |
|
84 | - |
|
85 | - protected function loadLines(string $s):void |
|
86 | - { |
|
87 | - $this->lines = explode("\n", str_replace("\r", '', $s)); |
|
88 | - $this->lineCount = count($this->lines); |
|
89 | - $this->lineNo = 0; |
|
90 | - } |
|
91 | - |
|
92 | - function parseFilter(ParseFilter $filter):void |
|
93 | - { |
|
94 | - foreach ($this->root as $k => $tag) { |
|
95 | - $this->root[$k] = $filter->filterTag($tag); |
|
96 | - } |
|
97 | - } |
|
98 | - |
|
99 | - function parseSnip(string $s):void |
|
100 | - { |
|
101 | - //save root tags |
|
102 | - /** @var Tag[] $roots */ |
|
103 | - $roots = $this->root; |
|
104 | - $this->root = []; |
|
105 | - $this->loadLines($s); |
|
106 | - $this->procLines(); |
|
107 | - $this->root = array_merge($roots, $this->root); |
|
108 | - } |
|
109 | - |
|
110 | - function applySnip():void |
|
111 | - { |
|
112 | - /** @var Tag\Snippet[] $fwdSnip */ |
|
113 | - $fwdSnip = []; |
|
114 | - /** @var Tag\Snippet[] $revSnip */ |
|
115 | - $revSnip = []; |
|
116 | - /** @var Tag[] $roots */ |
|
117 | - $roots = []; |
|
118 | - foreach ($this->root as $snip) { |
|
119 | - if ($snip instanceof Tag\Snippet) { |
|
120 | - if ($snip->getType() == 'append') { |
|
121 | - array_unshift($revSnip, $snip); |
|
122 | - } else { |
|
123 | - $fwdSnip[] = $snip; |
|
124 | - } |
|
125 | - } else { |
|
126 | - $roots[] = $snip; |
|
127 | - } |
|
128 | - } |
|
129 | - foreach ($fwdSnip as $snip) { |
|
130 | - foreach ($roots as $root) { |
|
131 | - $snip->apply($root); |
|
132 | - } |
|
133 | - } |
|
134 | - foreach ($revSnip as $snip) { |
|
135 | - foreach ($roots as $root) { |
|
136 | - $snip->apply($root); |
|
137 | - } |
|
138 | - } |
|
139 | - $this->root = $roots; |
|
140 | - } |
|
141 | - |
|
142 | - /** |
|
143 | - * Parse HAMLE template, from a string |
|
144 | - * @param string $s String to parse |
|
145 | - */ |
|
146 | - function str($s):void |
|
147 | - { |
|
148 | - $this->init(); |
|
149 | - $this->loadLines($s); |
|
150 | - $this->procLines(); |
|
151 | - } |
|
152 | - |
|
153 | - function procLines():void |
|
154 | - { |
|
155 | - /* @var $heir Tag[] Tag Heirachy Array */ |
|
156 | - $heir = []; |
|
157 | - while ($this->lineNo < $this->lineCount) { |
|
158 | - $line = $this->lines[$this->lineNo]; |
|
159 | - if (trim($line)) { |
|
160 | - if (preg_match(self::REGEX_PARSE_LINE, $line, $m)) { |
|
161 | - if (false !== strpos($m[1], "\t")) { |
|
162 | - throw new ParseError( |
|
163 | - 'Tabs are not supported in templates at this time', |
|
164 | - ); |
|
165 | - } |
|
166 | - $indent = strlen($m[1]); |
|
167 | - $tag = isset($m[2]) ? ($tag = $m[2]) : ''; |
|
168 | - $classid = isset($m[3]) ? $m[3] : ''; |
|
169 | - $params = str_replace( |
|
170 | - ['\[', '\]', '\\&'], |
|
171 | - ['[', ']', '%26'], |
|
172 | - isset($m[4]) ? $m[4] : '', |
|
173 | - ); |
|
174 | - $textcode = isset($m[5]) ? $m[5] : ''; |
|
175 | - $text = isset($m[8]) ? $m[8] : ''; |
|
176 | - $code = isset($m[6]) ? $m[6] : ''; |
|
177 | - $i = self::indentLevel($indent); |
|
178 | - unset($m[0]); |
|
179 | - switch (strlen($code) ? $code[0] : ($textcode ? $textcode : '')) { |
|
180 | - case '|': //Control Tag |
|
181 | - if ($code == '|snippet') { |
|
182 | - $hTag = new Tag\Snippet($text); |
|
183 | - } elseif ($code == '|form') { |
|
184 | - $hTag = new Tag\Form($text); |
|
185 | - } elseif ($code == '|formhint') { |
|
186 | - $hTag = new Tag\FormHint(); |
|
187 | - } elseif ($code == '|else') { |
|
188 | - $hTag = new Tag\Control(substr($code, 1), $heir[$i - 1]); |
|
189 | - $hTag->setVar($text); |
|
190 | - } else { |
|
191 | - $hTag = new Tag\Control(substr($code, 1)); |
|
192 | - $hTag->setVar($text); |
|
193 | - } |
|
194 | - break; |
|
195 | - case ':': //Filter Tag |
|
196 | - $hTag = new Tag\Filter(substr($code, 1)); |
|
197 | - $hTag->addContent($text, Text::TOKEN_CODE); |
|
198 | - foreach ($this->consumeBlock($indent) as $l) { |
|
199 | - $hTag->addContent($l, Text::TOKEN_CODE); |
|
200 | - } |
|
201 | - break; |
|
202 | - case '_': //String Tag |
|
203 | - case '__': //Unescape String Tag |
|
204 | - case '___': //Unescape String Tag (with unescaped vars) |
|
205 | - $hTag = new Tag\Text($textcode); |
|
206 | - $hTag->addContent($text); |
|
207 | - break; |
|
208 | - case '___': //Unescape String Tag |
|
209 | - $hTag = new Tag\Text($textcode); |
|
210 | - $hTag->addContent($text); |
|
211 | - break; |
|
212 | - case '/': // HTML Comment |
|
213 | - case '//': // Non Printed Comment |
|
214 | - $hTag = new Tag\Comment($textcode); |
|
215 | - $hTag->addContent($text); |
|
216 | - foreach ($this->consumeBlock($indent) as $l) { |
|
217 | - $hTag->addContent($l, Text::TOKEN_CODE); |
|
218 | - } |
|
219 | - break; |
|
220 | - default: |
|
221 | - $attr = []; |
|
222 | - if (isset($params[0]) && $params[0] == '[') { |
|
223 | - $param = substr($params, 1, -1); |
|
224 | - $param = str_replace(['+', '\\&'], ['%2B', '%26'], $param); |
|
225 | - $attr = $this->parseQueryString($param); |
|
226 | - } |
|
227 | - $class = []; |
|
228 | - $id = ''; |
|
229 | - $ref = ''; |
|
230 | - preg_match_all('/[#\.!][a-zA-Z0-9\-\_]+/m', $classid, $cid); |
|
231 | - if (isset($cid[0])) { |
|
232 | - foreach ($cid[0] as $s) { |
|
233 | - if ($s[0] == '#') { |
|
234 | - $id = substr($s, 1); |
|
235 | - } |
|
236 | - if ($s[0] == '.') { |
|
237 | - $class[] = substr($s, 1); |
|
238 | - } |
|
239 | - if ($s[0] == '!') { |
|
240 | - $ref = substr($s, 1); |
|
241 | - } |
|
242 | - } |
|
243 | - } |
|
244 | - if ($ref) { |
|
245 | - $hTag = new Tag\DynHtml($tag, $class, $attr, $id, $ref); |
|
246 | - } else { |
|
247 | - $hTag = new Tag\Html($tag, $class, $attr, $id); |
|
248 | - } |
|
249 | - $hTag->addContent($text); |
|
250 | - break; |
|
251 | - } |
|
252 | - $heir[$i] = $hTag; |
|
253 | - if ($i > 0) { |
|
254 | - $heir[$i - 1]->addChild($hTag); |
|
255 | - } else { |
|
256 | - $this->root[] = $hTag; |
|
257 | - } |
|
258 | - } else { |
|
259 | - throw new ParseError( |
|
260 | - "Unable to parse line {$this->lineNo}\n\"$line\"/" . |
|
261 | - preg_last_error(), |
|
262 | - ); |
|
263 | - } |
|
264 | - } |
|
265 | - $this->lineNo++; |
|
266 | - } |
|
267 | - } |
|
268 | - |
|
269 | - function parseQueryString(string $qs):array |
|
270 | - { |
|
271 | - $out = []; |
|
272 | - foreach (explode('&', $qs) as $s) { |
|
273 | - $kv = explode('=', $s, 2); |
|
274 | - $out[urldecode($kv[0])] = isset($kv[1]) ? urldecode($kv[1]) : null; |
|
275 | - } |
|
276 | - return $out; |
|
277 | - } |
|
278 | - |
|
279 | - function output(bool $minify = false):string |
|
280 | - { |
|
281 | - $out = "<?php\nuse Seufert\\Hamle;\n?>"; |
|
282 | - foreach ($this->root as $tag) { |
|
283 | - $out .= $tag->render(0, $minify); |
|
284 | - } |
|
285 | - return $out; |
|
286 | - } |
|
287 | - |
|
288 | - function consumeBlock(int $indent):array |
|
289 | - { |
|
290 | - $out = []; |
|
291 | - $m = []; |
|
292 | - while ( |
|
293 | - $this->lineNo + 1 < $this->lineCount && |
|
294 | - (!trim($this->lines[$this->lineNo + 1]) || |
|
295 | - preg_match( |
|
296 | - '/^(\s){' . $indent . '}((\s)+[^\s].*)$/', |
|
297 | - $this->lines[$this->lineNo + 1], |
|
298 | - $m, |
|
299 | - )) |
|
300 | - ) { |
|
301 | - if (trim($this->lines[$this->lineNo + 1])) { |
|
302 | - $out[] = $m[2]; |
|
303 | - } |
|
304 | - $this->lineNo++; |
|
305 | - } |
|
306 | - return $out; |
|
307 | - } |
|
308 | - |
|
309 | - function indentLevel(int $indent):int |
|
310 | - { |
|
311 | - if (!count($this->indents)) { |
|
312 | - $this->indents = [0 => $indent]; |
|
313 | - // Key = indent level, Value = Depth in spaces |
|
314 | - return 0; |
|
315 | - } |
|
316 | - foreach ($this->indents as $k => $v) { |
|
317 | - if ($v == $indent) { |
|
318 | - $this->indents = array_slice($this->indents, 0, 1 + (int) $k ); |
|
319 | - return $k; |
|
320 | - } |
|
321 | - } |
|
322 | - $this->indents[] = $indent; |
|
323 | - return max(array_keys($this->indents)); |
|
324 | - } |
|
325 | - |
|
326 | - function getLineNo():int |
|
327 | - { |
|
328 | - return $this->lineNo; |
|
329 | - } |
|
330 | -} |
@@ -53,278 +53,3 @@ |
||
53 | 53 | */ |
54 | 54 | |
55 | 55 | const REGEX_PARSE_LINE = <<<'ENDREGEX' |
56 | - /^(\s*)(?:(?:([a-zA-Z0-9-]*)((?:[\.#!][\w\-\_]+)*)(\[(?:(?:\{\$[^\}]+\})?[^\\\]{]*?(?:\\.)*?(?:{[^\$])*?)+\])?)|([_\/]{1,3})|([\|:\$]\w+)|({?\$[^}]+}?)|)(?: (.*))?$/ |
|
57 | - ENDREGEX; |
|
58 | - |
|
59 | - /** |
|
60 | - * @var int Current Line Number |
|
61 | - */ |
|
62 | - protected int $lineNo = 0; |
|
63 | - /** |
|
64 | - * @var int Total Lines in File |
|
65 | - */ |
|
66 | - protected int $lineCount = 0; |
|
67 | - |
|
68 | - function __construct() |
|
69 | - { |
|
70 | - $this->init(); |
|
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * Clear Lines, and Line Number, so if output is |
|
75 | - * called, no output will be produced |
|
76 | - */ |
|
77 | - protected function init():void |
|
78 | - { |
|
79 | - $this->lines = []; |
|
80 | - $this->lineNo = 0; |
|
81 | - $this->lineCount = 0; |
|
82 | - $this->root = []; |
|
83 | - } |
|
84 | - |
|
85 | - protected function loadLines(string $s):void |
|
86 | - { |
|
87 | - $this->lines = explode("\n", str_replace("\r", '', $s)); |
|
88 | - $this->lineCount = count($this->lines); |
|
89 | - $this->lineNo = 0; |
|
90 | - } |
|
91 | - |
|
92 | - function parseFilter(ParseFilter $filter):void |
|
93 | - { |
|
94 | - foreach ($this->root as $k => $tag) { |
|
95 | - $this->root[$k] = $filter->filterTag($tag); |
|
96 | - } |
|
97 | - } |
|
98 | - |
|
99 | - function parseSnip(string $s):void |
|
100 | - { |
|
101 | - //save root tags |
|
102 | - /** @var Tag[] $roots */ |
|
103 | - $roots = $this->root; |
|
104 | - $this->root = []; |
|
105 | - $this->loadLines($s); |
|
106 | - $this->procLines(); |
|
107 | - $this->root = array_merge($roots, $this->root); |
|
108 | - } |
|
109 | - |
|
110 | - function applySnip():void |
|
111 | - { |
|
112 | - /** @var Tag\Snippet[] $fwdSnip */ |
|
113 | - $fwdSnip = []; |
|
114 | - /** @var Tag\Snippet[] $revSnip */ |
|
115 | - $revSnip = []; |
|
116 | - /** @var Tag[] $roots */ |
|
117 | - $roots = []; |
|
118 | - foreach ($this->root as $snip) { |
|
119 | - if ($snip instanceof Tag\Snippet) { |
|
120 | - if ($snip->getType() == 'append') { |
|
121 | - array_unshift($revSnip, $snip); |
|
122 | - } else { |
|
123 | - $fwdSnip[] = $snip; |
|
124 | - } |
|
125 | - } else { |
|
126 | - $roots[] = $snip; |
|
127 | - } |
|
128 | - } |
|
129 | - foreach ($fwdSnip as $snip) { |
|
130 | - foreach ($roots as $root) { |
|
131 | - $snip->apply($root); |
|
132 | - } |
|
133 | - } |
|
134 | - foreach ($revSnip as $snip) { |
|
135 | - foreach ($roots as $root) { |
|
136 | - $snip->apply($root); |
|
137 | - } |
|
138 | - } |
|
139 | - $this->root = $roots; |
|
140 | - } |
|
141 | - |
|
142 | - /** |
|
143 | - * Parse HAMLE template, from a string |
|
144 | - * @param string $s String to parse |
|
145 | - */ |
|
146 | - function str($s):void |
|
147 | - { |
|
148 | - $this->init(); |
|
149 | - $this->loadLines($s); |
|
150 | - $this->procLines(); |
|
151 | - } |
|
152 | - |
|
153 | - function procLines():void |
|
154 | - { |
|
155 | - /* @var $heir Tag[] Tag Heirachy Array */ |
|
156 | - $heir = []; |
|
157 | - while ($this->lineNo < $this->lineCount) { |
|
158 | - $line = $this->lines[$this->lineNo]; |
|
159 | - if (trim($line)) { |
|
160 | - if (preg_match(self::REGEX_PARSE_LINE, $line, $m)) { |
|
161 | - if (false !== strpos($m[1], "\t")) { |
|
162 | - throw new ParseError( |
|
163 | - 'Tabs are not supported in templates at this time', |
|
164 | - ); |
|
165 | - } |
|
166 | - $indent = strlen($m[1]); |
|
167 | - $tag = isset($m[2]) ? ($tag = $m[2]) : ''; |
|
168 | - $classid = isset($m[3]) ? $m[3] : ''; |
|
169 | - $params = str_replace( |
|
170 | - ['\[', '\]', '\\&'], |
|
171 | - ['[', ']', '%26'], |
|
172 | - isset($m[4]) ? $m[4] : '', |
|
173 | - ); |
|
174 | - $textcode = isset($m[5]) ? $m[5] : ''; |
|
175 | - $text = isset($m[8]) ? $m[8] : ''; |
|
176 | - $code = isset($m[6]) ? $m[6] : ''; |
|
177 | - $i = self::indentLevel($indent); |
|
178 | - unset($m[0]); |
|
179 | - switch (strlen($code) ? $code[0] : ($textcode ? $textcode : '')) { |
|
180 | - case '|': //Control Tag |
|
181 | - if ($code == '|snippet') { |
|
182 | - $hTag = new Tag\Snippet($text); |
|
183 | - } elseif ($code == '|form') { |
|
184 | - $hTag = new Tag\Form($text); |
|
185 | - } elseif ($code == '|formhint') { |
|
186 | - $hTag = new Tag\FormHint(); |
|
187 | - } elseif ($code == '|else') { |
|
188 | - $hTag = new Tag\Control(substr($code, 1), $heir[$i - 1]); |
|
189 | - $hTag->setVar($text); |
|
190 | - } else { |
|
191 | - $hTag = new Tag\Control(substr($code, 1)); |
|
192 | - $hTag->setVar($text); |
|
193 | - } |
|
194 | - break; |
|
195 | - case ':': //Filter Tag |
|
196 | - $hTag = new Tag\Filter(substr($code, 1)); |
|
197 | - $hTag->addContent($text, Text::TOKEN_CODE); |
|
198 | - foreach ($this->consumeBlock($indent) as $l) { |
|
199 | - $hTag->addContent($l, Text::TOKEN_CODE); |
|
200 | - } |
|
201 | - break; |
|
202 | - case '_': //String Tag |
|
203 | - case '__': //Unescape String Tag |
|
204 | - case '___': //Unescape String Tag (with unescaped vars) |
|
205 | - $hTag = new Tag\Text($textcode); |
|
206 | - $hTag->addContent($text); |
|
207 | - break; |
|
208 | - case '___': //Unescape String Tag |
|
209 | - $hTag = new Tag\Text($textcode); |
|
210 | - $hTag->addContent($text); |
|
211 | - break; |
|
212 | - case '/': // HTML Comment |
|
213 | - case '//': // Non Printed Comment |
|
214 | - $hTag = new Tag\Comment($textcode); |
|
215 | - $hTag->addContent($text); |
|
216 | - foreach ($this->consumeBlock($indent) as $l) { |
|
217 | - $hTag->addContent($l, Text::TOKEN_CODE); |
|
218 | - } |
|
219 | - break; |
|
220 | - default: |
|
221 | - $attr = []; |
|
222 | - if (isset($params[0]) && $params[0] == '[') { |
|
223 | - $param = substr($params, 1, -1); |
|
224 | - $param = str_replace(['+', '\\&'], ['%2B', '%26'], $param); |
|
225 | - $attr = $this->parseQueryString($param); |
|
226 | - } |
|
227 | - $class = []; |
|
228 | - $id = ''; |
|
229 | - $ref = ''; |
|
230 | - preg_match_all('/[#\.!][a-zA-Z0-9\-\_]+/m', $classid, $cid); |
|
231 | - if (isset($cid[0])) { |
|
232 | - foreach ($cid[0] as $s) { |
|
233 | - if ($s[0] == '#') { |
|
234 | - $id = substr($s, 1); |
|
235 | - } |
|
236 | - if ($s[0] == '.') { |
|
237 | - $class[] = substr($s, 1); |
|
238 | - } |
|
239 | - if ($s[0] == '!') { |
|
240 | - $ref = substr($s, 1); |
|
241 | - } |
|
242 | - } |
|
243 | - } |
|
244 | - if ($ref) { |
|
245 | - $hTag = new Tag\DynHtml($tag, $class, $attr, $id, $ref); |
|
246 | - } else { |
|
247 | - $hTag = new Tag\Html($tag, $class, $attr, $id); |
|
248 | - } |
|
249 | - $hTag->addContent($text); |
|
250 | - break; |
|
251 | - } |
|
252 | - $heir[$i] = $hTag; |
|
253 | - if ($i > 0) { |
|
254 | - $heir[$i - 1]->addChild($hTag); |
|
255 | - } else { |
|
256 | - $this->root[] = $hTag; |
|
257 | - } |
|
258 | - } else { |
|
259 | - throw new ParseError( |
|
260 | - "Unable to parse line {$this->lineNo}\n\"$line\"/" . |
|
261 | - preg_last_error(), |
|
262 | - ); |
|
263 | - } |
|
264 | - } |
|
265 | - $this->lineNo++; |
|
266 | - } |
|
267 | - } |
|
268 | - |
|
269 | - function parseQueryString(string $qs):array |
|
270 | - { |
|
271 | - $out = []; |
|
272 | - foreach (explode('&', $qs) as $s) { |
|
273 | - $kv = explode('=', $s, 2); |
|
274 | - $out[urldecode($kv[0])] = isset($kv[1]) ? urldecode($kv[1]) : null; |
|
275 | - } |
|
276 | - return $out; |
|
277 | - } |
|
278 | - |
|
279 | - function output(bool $minify = false):string |
|
280 | - { |
|
281 | - $out = "<?php\nuse Seufert\\Hamle;\n?>"; |
|
282 | - foreach ($this->root as $tag) { |
|
283 | - $out .= $tag->render(0, $minify); |
|
284 | - } |
|
285 | - return $out; |
|
286 | - } |
|
287 | - |
|
288 | - function consumeBlock(int $indent):array |
|
289 | - { |
|
290 | - $out = []; |
|
291 | - $m = []; |
|
292 | - while ( |
|
293 | - $this->lineNo + 1 < $this->lineCount && |
|
294 | - (!trim($this->lines[$this->lineNo + 1]) || |
|
295 | - preg_match( |
|
296 | - '/^(\s){' . $indent . '}((\s)+[^\s].*)$/', |
|
297 | - $this->lines[$this->lineNo + 1], |
|
298 | - $m, |
|
299 | - )) |
|
300 | - ) { |
|
301 | - if (trim($this->lines[$this->lineNo + 1])) { |
|
302 | - $out[] = $m[2]; |
|
303 | - } |
|
304 | - $this->lineNo++; |
|
305 | - } |
|
306 | - return $out; |
|
307 | - } |
|
308 | - |
|
309 | - function indentLevel(int $indent):int |
|
310 | - { |
|
311 | - if (!count($this->indents)) { |
|
312 | - $this->indents = [0 => $indent]; |
|
313 | - // Key = indent level, Value = Depth in spaces |
|
314 | - return 0; |
|
315 | - } |
|
316 | - foreach ($this->indents as $k => $v) { |
|
317 | - if ($v == $indent) { |
|
318 | - $this->indents = array_slice($this->indents, 0, 1 + (int) $k ); |
|
319 | - return $k; |
|
320 | - } |
|
321 | - } |
|
322 | - $this->indents[] = $indent; |
|
323 | - return max(array_keys($this->indents)); |
|
324 | - } |
|
325 | - |
|
326 | - function getLineNo():int |
|
327 | - { |
|
328 | - return $this->lineNo; |
|
329 | - } |
|
330 | -} |
@@ -53,278 +53,3 @@ |
||
53 | 53 | */ |
54 | 54 | |
55 | 55 | const REGEX_PARSE_LINE = <<<'ENDREGEX' |
56 | - /^(\s*)(?:(?:([a-zA-Z0-9-]*)((?:[\.#!][\w\-\_]+)*)(\[(?:(?:\{\$[^\}]+\})?[^\\\]{]*?(?:\\.)*?(?:{[^\$])*?)+\])?)|([_\/]{1,3})|([\|:\$]\w+)|({?\$[^}]+}?)|)(?: (.*))?$/ |
|
57 | - ENDREGEX; |
|
58 | - |
|
59 | - /** |
|
60 | - * @var int Current Line Number |
|
61 | - */ |
|
62 | - protected int $lineNo = 0; |
|
63 | - /** |
|
64 | - * @var int Total Lines in File |
|
65 | - */ |
|
66 | - protected int $lineCount = 0; |
|
67 | - |
|
68 | - function __construct() |
|
69 | - { |
|
70 | - $this->init(); |
|
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * Clear Lines, and Line Number, so if output is |
|
75 | - * called, no output will be produced |
|
76 | - */ |
|
77 | - protected function init():void |
|
78 | - { |
|
79 | - $this->lines = []; |
|
80 | - $this->lineNo = 0; |
|
81 | - $this->lineCount = 0; |
|
82 | - $this->root = []; |
|
83 | - } |
|
84 | - |
|
85 | - protected function loadLines(string $s):void |
|
86 | - { |
|
87 | - $this->lines = explode("\n", str_replace("\r", '', $s)); |
|
88 | - $this->lineCount = count($this->lines); |
|
89 | - $this->lineNo = 0; |
|
90 | - } |
|
91 | - |
|
92 | - function parseFilter(ParseFilter $filter):void |
|
93 | - { |
|
94 | - foreach ($this->root as $k => $tag) { |
|
95 | - $this->root[$k] = $filter->filterTag($tag); |
|
96 | - } |
|
97 | - } |
|
98 | - |
|
99 | - function parseSnip(string $s):void |
|
100 | - { |
|
101 | - //save root tags |
|
102 | - /** @var Tag[] $roots */ |
|
103 | - $roots = $this->root; |
|
104 | - $this->root = []; |
|
105 | - $this->loadLines($s); |
|
106 | - $this->procLines(); |
|
107 | - $this->root = array_merge($roots, $this->root); |
|
108 | - } |
|
109 | - |
|
110 | - function applySnip():void |
|
111 | - { |
|
112 | - /** @var Tag\Snippet[] $fwdSnip */ |
|
113 | - $fwdSnip = []; |
|
114 | - /** @var Tag\Snippet[] $revSnip */ |
|
115 | - $revSnip = []; |
|
116 | - /** @var Tag[] $roots */ |
|
117 | - $roots = []; |
|
118 | - foreach ($this->root as $snip) { |
|
119 | - if ($snip instanceof Tag\Snippet) { |
|
120 | - if ($snip->getType() == 'append') { |
|
121 | - array_unshift($revSnip, $snip); |
|
122 | - } else { |
|
123 | - $fwdSnip[] = $snip; |
|
124 | - } |
|
125 | - } else { |
|
126 | - $roots[] = $snip; |
|
127 | - } |
|
128 | - } |
|
129 | - foreach ($fwdSnip as $snip) { |
|
130 | - foreach ($roots as $root) { |
|
131 | - $snip->apply($root); |
|
132 | - } |
|
133 | - } |
|
134 | - foreach ($revSnip as $snip) { |
|
135 | - foreach ($roots as $root) { |
|
136 | - $snip->apply($root); |
|
137 | - } |
|
138 | - } |
|
139 | - $this->root = $roots; |
|
140 | - } |
|
141 | - |
|
142 | - /** |
|
143 | - * Parse HAMLE template, from a string |
|
144 | - * @param string $s String to parse |
|
145 | - */ |
|
146 | - function str($s):void |
|
147 | - { |
|
148 | - $this->init(); |
|
149 | - $this->loadLines($s); |
|
150 | - $this->procLines(); |
|
151 | - } |
|
152 | - |
|
153 | - function procLines():void |
|
154 | - { |
|
155 | - /* @var $heir Tag[] Tag Heirachy Array */ |
|
156 | - $heir = []; |
|
157 | - while ($this->lineNo < $this->lineCount) { |
|
158 | - $line = $this->lines[$this->lineNo]; |
|
159 | - if (trim($line)) { |
|
160 | - if (preg_match(self::REGEX_PARSE_LINE, $line, $m)) { |
|
161 | - if (false !== strpos($m[1], "\t")) { |
|
162 | - throw new ParseError( |
|
163 | - 'Tabs are not supported in templates at this time', |
|
164 | - ); |
|
165 | - } |
|
166 | - $indent = strlen($m[1]); |
|
167 | - $tag = isset($m[2]) ? ($tag = $m[2]) : ''; |
|
168 | - $classid = isset($m[3]) ? $m[3] : ''; |
|
169 | - $params = str_replace( |
|
170 | - ['\[', '\]', '\\&'], |
|
171 | - ['[', ']', '%26'], |
|
172 | - isset($m[4]) ? $m[4] : '', |
|
173 | - ); |
|
174 | - $textcode = isset($m[5]) ? $m[5] : ''; |
|
175 | - $text = isset($m[8]) ? $m[8] : ''; |
|
176 | - $code = isset($m[6]) ? $m[6] : ''; |
|
177 | - $i = self::indentLevel($indent); |
|
178 | - unset($m[0]); |
|
179 | - switch (strlen($code) ? $code[0] : ($textcode ? $textcode : '')) { |
|
180 | - case '|': //Control Tag |
|
181 | - if ($code == '|snippet') { |
|
182 | - $hTag = new Tag\Snippet($text); |
|
183 | - } elseif ($code == '|form') { |
|
184 | - $hTag = new Tag\Form($text); |
|
185 | - } elseif ($code == '|formhint') { |
|
186 | - $hTag = new Tag\FormHint(); |
|
187 | - } elseif ($code == '|else') { |
|
188 | - $hTag = new Tag\Control(substr($code, 1), $heir[$i - 1]); |
|
189 | - $hTag->setVar($text); |
|
190 | - } else { |
|
191 | - $hTag = new Tag\Control(substr($code, 1)); |
|
192 | - $hTag->setVar($text); |
|
193 | - } |
|
194 | - break; |
|
195 | - case ':': //Filter Tag |
|
196 | - $hTag = new Tag\Filter(substr($code, 1)); |
|
197 | - $hTag->addContent($text, Text::TOKEN_CODE); |
|
198 | - foreach ($this->consumeBlock($indent) as $l) { |
|
199 | - $hTag->addContent($l, Text::TOKEN_CODE); |
|
200 | - } |
|
201 | - break; |
|
202 | - case '_': //String Tag |
|
203 | - case '__': //Unescape String Tag |
|
204 | - case '___': //Unescape String Tag (with unescaped vars) |
|
205 | - $hTag = new Tag\Text($textcode); |
|
206 | - $hTag->addContent($text); |
|
207 | - break; |
|
208 | - case '___': //Unescape String Tag |
|
209 | - $hTag = new Tag\Text($textcode); |
|
210 | - $hTag->addContent($text); |
|
211 | - break; |
|
212 | - case '/': // HTML Comment |
|
213 | - case '//': // Non Printed Comment |
|
214 | - $hTag = new Tag\Comment($textcode); |
|
215 | - $hTag->addContent($text); |
|
216 | - foreach ($this->consumeBlock($indent) as $l) { |
|
217 | - $hTag->addContent($l, Text::TOKEN_CODE); |
|
218 | - } |
|
219 | - break; |
|
220 | - default: |
|
221 | - $attr = []; |
|
222 | - if (isset($params[0]) && $params[0] == '[') { |
|
223 | - $param = substr($params, 1, -1); |
|
224 | - $param = str_replace(['+', '\\&'], ['%2B', '%26'], $param); |
|
225 | - $attr = $this->parseQueryString($param); |
|
226 | - } |
|
227 | - $class = []; |
|
228 | - $id = ''; |
|
229 | - $ref = ''; |
|
230 | - preg_match_all('/[#\.!][a-zA-Z0-9\-\_]+/m', $classid, $cid); |
|
231 | - if (isset($cid[0])) { |
|
232 | - foreach ($cid[0] as $s) { |
|
233 | - if ($s[0] == '#') { |
|
234 | - $id = substr($s, 1); |
|
235 | - } |
|
236 | - if ($s[0] == '.') { |
|
237 | - $class[] = substr($s, 1); |
|
238 | - } |
|
239 | - if ($s[0] == '!') { |
|
240 | - $ref = substr($s, 1); |
|
241 | - } |
|
242 | - } |
|
243 | - } |
|
244 | - if ($ref) { |
|
245 | - $hTag = new Tag\DynHtml($tag, $class, $attr, $id, $ref); |
|
246 | - } else { |
|
247 | - $hTag = new Tag\Html($tag, $class, $attr, $id); |
|
248 | - } |
|
249 | - $hTag->addContent($text); |
|
250 | - break; |
|
251 | - } |
|
252 | - $heir[$i] = $hTag; |
|
253 | - if ($i > 0) { |
|
254 | - $heir[$i - 1]->addChild($hTag); |
|
255 | - } else { |
|
256 | - $this->root[] = $hTag; |
|
257 | - } |
|
258 | - } else { |
|
259 | - throw new ParseError( |
|
260 | - "Unable to parse line {$this->lineNo}\n\"$line\"/" . |
|
261 | - preg_last_error(), |
|
262 | - ); |
|
263 | - } |
|
264 | - } |
|
265 | - $this->lineNo++; |
|
266 | - } |
|
267 | - } |
|
268 | - |
|
269 | - function parseQueryString(string $qs):array |
|
270 | - { |
|
271 | - $out = []; |
|
272 | - foreach (explode('&', $qs) as $s) { |
|
273 | - $kv = explode('=', $s, 2); |
|
274 | - $out[urldecode($kv[0])] = isset($kv[1]) ? urldecode($kv[1]) : null; |
|
275 | - } |
|
276 | - return $out; |
|
277 | - } |
|
278 | - |
|
279 | - function output(bool $minify = false):string |
|
280 | - { |
|
281 | - $out = "<?php\nuse Seufert\\Hamle;\n?>"; |
|
282 | - foreach ($this->root as $tag) { |
|
283 | - $out .= $tag->render(0, $minify); |
|
284 | - } |
|
285 | - return $out; |
|
286 | - } |
|
287 | - |
|
288 | - function consumeBlock(int $indent):array |
|
289 | - { |
|
290 | - $out = []; |
|
291 | - $m = []; |
|
292 | - while ( |
|
293 | - $this->lineNo + 1 < $this->lineCount && |
|
294 | - (!trim($this->lines[$this->lineNo + 1]) || |
|
295 | - preg_match( |
|
296 | - '/^(\s){' . $indent . '}((\s)+[^\s].*)$/', |
|
297 | - $this->lines[$this->lineNo + 1], |
|
298 | - $m, |
|
299 | - )) |
|
300 | - ) { |
|
301 | - if (trim($this->lines[$this->lineNo + 1])) { |
|
302 | - $out[] = $m[2]; |
|
303 | - } |
|
304 | - $this->lineNo++; |
|
305 | - } |
|
306 | - return $out; |
|
307 | - } |
|
308 | - |
|
309 | - function indentLevel(int $indent):int |
|
310 | - { |
|
311 | - if (!count($this->indents)) { |
|
312 | - $this->indents = [0 => $indent]; |
|
313 | - // Key = indent level, Value = Depth in spaces |
|
314 | - return 0; |
|
315 | - } |
|
316 | - foreach ($this->indents as $k => $v) { |
|
317 | - if ($v == $indent) { |
|
318 | - $this->indents = array_slice($this->indents, 0, 1 + (int) $k ); |
|
319 | - return $k; |
|
320 | - } |
|
321 | - } |
|
322 | - $this->indents[] = $indent; |
|
323 | - return max(array_keys($this->indents)); |
|
324 | - } |
|
325 | - |
|
326 | - function getLineNo():int |
|
327 | - { |
|
328 | - return $this->lineNo; |
|
329 | - } |
|
330 | -} |
@@ -53,278 +53,3 @@ |
||
53 | 53 | */ |
54 | 54 | |
55 | 55 | const REGEX_PARSE_LINE = <<<'ENDREGEX' |
56 | - /^(\s*)(?:(?:([a-zA-Z0-9-]*)((?:[\.#!][\w\-\_]+)*)(\[(?:(?:\{\$[^\}]+\})?[^\\\]{]*?(?:\\.)*?(?:{[^\$])*?)+\])?)|([_\/]{1,3})|([\|:\$]\w+)|({?\$[^}]+}?)|)(?: (.*))?$/ |
|
57 | - ENDREGEX; |
|
58 | - |
|
59 | - /** |
|
60 | - * @var int Current Line Number |
|
61 | - */ |
|
62 | - protected int $lineNo = 0; |
|
63 | - /** |
|
64 | - * @var int Total Lines in File |
|
65 | - */ |
|
66 | - protected int $lineCount = 0; |
|
67 | - |
|
68 | - function __construct() |
|
69 | - { |
|
70 | - $this->init(); |
|
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * Clear Lines, and Line Number, so if output is |
|
75 | - * called, no output will be produced |
|
76 | - */ |
|
77 | - protected function init():void |
|
78 | - { |
|
79 | - $this->lines = []; |
|
80 | - $this->lineNo = 0; |
|
81 | - $this->lineCount = 0; |
|
82 | - $this->root = []; |
|
83 | - } |
|
84 | - |
|
85 | - protected function loadLines(string $s):void |
|
86 | - { |
|
87 | - $this->lines = explode("\n", str_replace("\r", '', $s)); |
|
88 | - $this->lineCount = count($this->lines); |
|
89 | - $this->lineNo = 0; |
|
90 | - } |
|
91 | - |
|
92 | - function parseFilter(ParseFilter $filter):void |
|
93 | - { |
|
94 | - foreach ($this->root as $k => $tag) { |
|
95 | - $this->root[$k] = $filter->filterTag($tag); |
|
96 | - } |
|
97 | - } |
|
98 | - |
|
99 | - function parseSnip(string $s):void |
|
100 | - { |
|
101 | - //save root tags |
|
102 | - /** @var Tag[] $roots */ |
|
103 | - $roots = $this->root; |
|
104 | - $this->root = []; |
|
105 | - $this->loadLines($s); |
|
106 | - $this->procLines(); |
|
107 | - $this->root = array_merge($roots, $this->root); |
|
108 | - } |
|
109 | - |
|
110 | - function applySnip():void |
|
111 | - { |
|
112 | - /** @var Tag\Snippet[] $fwdSnip */ |
|
113 | - $fwdSnip = []; |
|
114 | - /** @var Tag\Snippet[] $revSnip */ |
|
115 | - $revSnip = []; |
|
116 | - /** @var Tag[] $roots */ |
|
117 | - $roots = []; |
|
118 | - foreach ($this->root as $snip) { |
|
119 | - if ($snip instanceof Tag\Snippet) { |
|
120 | - if ($snip->getType() == 'append') { |
|
121 | - array_unshift($revSnip, $snip); |
|
122 | - } else { |
|
123 | - $fwdSnip[] = $snip; |
|
124 | - } |
|
125 | - } else { |
|
126 | - $roots[] = $snip; |
|
127 | - } |
|
128 | - } |
|
129 | - foreach ($fwdSnip as $snip) { |
|
130 | - foreach ($roots as $root) { |
|
131 | - $snip->apply($root); |
|
132 | - } |
|
133 | - } |
|
134 | - foreach ($revSnip as $snip) { |
|
135 | - foreach ($roots as $root) { |
|
136 | - $snip->apply($root); |
|
137 | - } |
|
138 | - } |
|
139 | - $this->root = $roots; |
|
140 | - } |
|
141 | - |
|
142 | - /** |
|
143 | - * Parse HAMLE template, from a string |
|
144 | - * @param string $s String to parse |
|
145 | - */ |
|
146 | - function str($s):void |
|
147 | - { |
|
148 | - $this->init(); |
|
149 | - $this->loadLines($s); |
|
150 | - $this->procLines(); |
|
151 | - } |
|
152 | - |
|
153 | - function procLines():void |
|
154 | - { |
|
155 | - /* @var $heir Tag[] Tag Heirachy Array */ |
|
156 | - $heir = []; |
|
157 | - while ($this->lineNo < $this->lineCount) { |
|
158 | - $line = $this->lines[$this->lineNo]; |
|
159 | - if (trim($line)) { |
|
160 | - if (preg_match(self::REGEX_PARSE_LINE, $line, $m)) { |
|
161 | - if (false !== strpos($m[1], "\t")) { |
|
162 | - throw new ParseError( |
|
163 | - 'Tabs are not supported in templates at this time', |
|
164 | - ); |
|
165 | - } |
|
166 | - $indent = strlen($m[1]); |
|
167 | - $tag = isset($m[2]) ? ($tag = $m[2]) : ''; |
|
168 | - $classid = isset($m[3]) ? $m[3] : ''; |
|
169 | - $params = str_replace( |
|
170 | - ['\[', '\]', '\\&'], |
|
171 | - ['[', ']', '%26'], |
|
172 | - isset($m[4]) ? $m[4] : '', |
|
173 | - ); |
|
174 | - $textcode = isset($m[5]) ? $m[5] : ''; |
|
175 | - $text = isset($m[8]) ? $m[8] : ''; |
|
176 | - $code = isset($m[6]) ? $m[6] : ''; |
|
177 | - $i = self::indentLevel($indent); |
|
178 | - unset($m[0]); |
|
179 | - switch (strlen($code) ? $code[0] : ($textcode ? $textcode : '')) { |
|
180 | - case '|': //Control Tag |
|
181 | - if ($code == '|snippet') { |
|
182 | - $hTag = new Tag\Snippet($text); |
|
183 | - } elseif ($code == '|form') { |
|
184 | - $hTag = new Tag\Form($text); |
|
185 | - } elseif ($code == '|formhint') { |
|
186 | - $hTag = new Tag\FormHint(); |
|
187 | - } elseif ($code == '|else') { |
|
188 | - $hTag = new Tag\Control(substr($code, 1), $heir[$i - 1]); |
|
189 | - $hTag->setVar($text); |
|
190 | - } else { |
|
191 | - $hTag = new Tag\Control(substr($code, 1)); |
|
192 | - $hTag->setVar($text); |
|
193 | - } |
|
194 | - break; |
|
195 | - case ':': //Filter Tag |
|
196 | - $hTag = new Tag\Filter(substr($code, 1)); |
|
197 | - $hTag->addContent($text, Text::TOKEN_CODE); |
|
198 | - foreach ($this->consumeBlock($indent) as $l) { |
|
199 | - $hTag->addContent($l, Text::TOKEN_CODE); |
|
200 | - } |
|
201 | - break; |
|
202 | - case '_': //String Tag |
|
203 | - case '__': //Unescape String Tag |
|
204 | - case '___': //Unescape String Tag (with unescaped vars) |
|
205 | - $hTag = new Tag\Text($textcode); |
|
206 | - $hTag->addContent($text); |
|
207 | - break; |
|
208 | - case '___': //Unescape String Tag |
|
209 | - $hTag = new Tag\Text($textcode); |
|
210 | - $hTag->addContent($text); |
|
211 | - break; |
|
212 | - case '/': // HTML Comment |
|
213 | - case '//': // Non Printed Comment |
|
214 | - $hTag = new Tag\Comment($textcode); |
|
215 | - $hTag->addContent($text); |
|
216 | - foreach ($this->consumeBlock($indent) as $l) { |
|
217 | - $hTag->addContent($l, Text::TOKEN_CODE); |
|
218 | - } |
|
219 | - break; |
|
220 | - default: |
|
221 | - $attr = []; |
|
222 | - if (isset($params[0]) && $params[0] == '[') { |
|
223 | - $param = substr($params, 1, -1); |
|
224 | - $param = str_replace(['+', '\\&'], ['%2B', '%26'], $param); |
|
225 | - $attr = $this->parseQueryString($param); |
|
226 | - } |
|
227 | - $class = []; |
|
228 | - $id = ''; |
|
229 | - $ref = ''; |
|
230 | - preg_match_all('/[#\.!][a-zA-Z0-9\-\_]+/m', $classid, $cid); |
|
231 | - if (isset($cid[0])) { |
|
232 | - foreach ($cid[0] as $s) { |
|
233 | - if ($s[0] == '#') { |
|
234 | - $id = substr($s, 1); |
|
235 | - } |
|
236 | - if ($s[0] == '.') { |
|
237 | - $class[] = substr($s, 1); |
|
238 | - } |
|
239 | - if ($s[0] == '!') { |
|
240 | - $ref = substr($s, 1); |
|
241 | - } |
|
242 | - } |
|
243 | - } |
|
244 | - if ($ref) { |
|
245 | - $hTag = new Tag\DynHtml($tag, $class, $attr, $id, $ref); |
|
246 | - } else { |
|
247 | - $hTag = new Tag\Html($tag, $class, $attr, $id); |
|
248 | - } |
|
249 | - $hTag->addContent($text); |
|
250 | - break; |
|
251 | - } |
|
252 | - $heir[$i] = $hTag; |
|
253 | - if ($i > 0) { |
|
254 | - $heir[$i - 1]->addChild($hTag); |
|
255 | - } else { |
|
256 | - $this->root[] = $hTag; |
|
257 | - } |
|
258 | - } else { |
|
259 | - throw new ParseError( |
|
260 | - "Unable to parse line {$this->lineNo}\n\"$line\"/" . |
|
261 | - preg_last_error(), |
|
262 | - ); |
|
263 | - } |
|
264 | - } |
|
265 | - $this->lineNo++; |
|
266 | - } |
|
267 | - } |
|
268 | - |
|
269 | - function parseQueryString(string $qs):array |
|
270 | - { |
|
271 | - $out = []; |
|
272 | - foreach (explode('&', $qs) as $s) { |
|
273 | - $kv = explode('=', $s, 2); |
|
274 | - $out[urldecode($kv[0])] = isset($kv[1]) ? urldecode($kv[1]) : null; |
|
275 | - } |
|
276 | - return $out; |
|
277 | - } |
|
278 | - |
|
279 | - function output(bool $minify = false):string |
|
280 | - { |
|
281 | - $out = "<?php\nuse Seufert\\Hamle;\n?>"; |
|
282 | - foreach ($this->root as $tag) { |
|
283 | - $out .= $tag->render(0, $minify); |
|
284 | - } |
|
285 | - return $out; |
|
286 | - } |
|
287 | - |
|
288 | - function consumeBlock(int $indent):array |
|
289 | - { |
|
290 | - $out = []; |
|
291 | - $m = []; |
|
292 | - while ( |
|
293 | - $this->lineNo + 1 < $this->lineCount && |
|
294 | - (!trim($this->lines[$this->lineNo + 1]) || |
|
295 | - preg_match( |
|
296 | - '/^(\s){' . $indent . '}((\s)+[^\s].*)$/', |
|
297 | - $this->lines[$this->lineNo + 1], |
|
298 | - $m, |
|
299 | - )) |
|
300 | - ) { |
|
301 | - if (trim($this->lines[$this->lineNo + 1])) { |
|
302 | - $out[] = $m[2]; |
|
303 | - } |
|
304 | - $this->lineNo++; |
|
305 | - } |
|
306 | - return $out; |
|
307 | - } |
|
308 | - |
|
309 | - function indentLevel(int $indent):int |
|
310 | - { |
|
311 | - if (!count($this->indents)) { |
|
312 | - $this->indents = [0 => $indent]; |
|
313 | - // Key = indent level, Value = Depth in spaces |
|
314 | - return 0; |
|
315 | - } |
|
316 | - foreach ($this->indents as $k => $v) { |
|
317 | - if ($v == $indent) { |
|
318 | - $this->indents = array_slice($this->indents, 0, 1 + (int) $k ); |
|
319 | - return $k; |
|
320 | - } |
|
321 | - } |
|
322 | - $this->indents[] = $indent; |
|
323 | - return max(array_keys($this->indents)); |
|
324 | - } |
|
325 | - |
|
326 | - function getLineNo():int |
|
327 | - { |
|
328 | - return $this->lineNo; |
|
329 | - } |
|
330 | -} |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | ]); |
71 | 71 | } catch (SyntaxError $e) { |
72 | 72 | throw new ParseError( |
73 | - 'Unable to parse:' . $s . "\n\n" . $e->getMessage(), |
|
73 | + 'Unable to parse:'.$s."\n\n".$e->getMessage(), |
|
74 | 74 | 0, |
75 | 75 | $e, |
76 | 76 | ); |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | self::varToCode($limit), |
142 | 142 | self::varToCode($offset), |
143 | 143 | ]; |
144 | - return 'Hamle\Run::modelTypeId(' . join(',', $opt) . ')'; |
|
144 | + return 'Hamle\Run::modelTypeId('.join(',', $opt).')'; |
|
145 | 145 | } |
146 | 146 | |
147 | 147 | function toHTML(bool $escape = false): string |
@@ -156,16 +156,16 @@ discard block |
||
156 | 156 | } |
157 | 157 | break; |
158 | 158 | case 'scopeName': |
159 | - $out .= '<?=' . self::renderScopeName($node) . '?>'; |
|
159 | + $out .= '<?='.self::renderScopeName($node).'?>'; |
|
160 | 160 | break; |
161 | 161 | case 'scopeThis': |
162 | - $out .= '<?=' . self::renderScopeThis($node) . '?>'; |
|
162 | + $out .= '<?='.self::renderScopeThis($node).'?>'; |
|
163 | 163 | break; |
164 | 164 | case 'expr': |
165 | - $out .= '<?=' . self::renderExpr($node) . '?>'; |
|
165 | + $out .= '<?='.self::renderExpr($node).'?>'; |
|
166 | 166 | break; |
167 | 167 | default: |
168 | - throw new \RuntimeException('Invalid Node:' . $node['type']); |
|
168 | + throw new \RuntimeException('Invalid Node:'.$node['type']); |
|
169 | 169 | } |
170 | 170 | } |
171 | 171 | return $out; |
@@ -194,7 +194,7 @@ discard block |
||
194 | 194 | $out[] = self::renderExpr($node); |
195 | 195 | break; |
196 | 196 | default: |
197 | - throw new \RuntimeException('Invalid Node:' . $node['type']); |
|
197 | + throw new \RuntimeException('Invalid Node:'.$node['type']); |
|
198 | 198 | } |
199 | 199 | } |
200 | 200 | return join('.', $out); |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | |
203 | 203 | function doEval(): mixed |
204 | 204 | { |
205 | - return eval('use Seufert\Hamle; return ' . $this->toPHP() . ';'); |
|
205 | + return eval('use Seufert\Hamle; return '.$this->toPHP().';'); |
|
206 | 206 | } |
207 | 207 | |
208 | 208 | static function varToCode(mixed $var): mixed |
@@ -210,9 +210,9 @@ discard block |
||
210 | 210 | if (is_array($var)) { |
211 | 211 | $code = []; |
212 | 212 | foreach ($var as $key => $value) { |
213 | - $code[] = self::varToCode($key) . '=>' . self::varToCode($value); |
|
213 | + $code[] = self::varToCode($key).'=>'.self::varToCode($value); |
|
214 | 214 | } |
215 | - return 'array(' . implode(',', $code) . ')'; //remove unnecessary coma |
|
215 | + return 'array('.implode(',', $code).')'; //remove unnecessary coma |
|
216 | 216 | } |
217 | 217 | if (is_bool($var)) { |
218 | 218 | return $var ? 'TRUE' : 'FALSE'; |
@@ -224,16 +224,16 @@ discard block |
||
224 | 224 | return $var->toPHP(); |
225 | 225 | } |
226 | 226 | if (strpos($var, "\n") !== false) { |
227 | - return '"' . |
|
227 | + return '"'. |
|
228 | 228 | str_replace( |
229 | 229 | ['\\', '$', '"', "\n"], |
230 | 230 | ['\\\\', '\$', '\\"', '\\n'], |
231 | 231 | $var, |
232 | - ) . |
|
232 | + ). |
|
233 | 233 | '"'; |
234 | 234 | } |
235 | - return "'" . |
|
236 | - str_replace(['\\', '$', "'"], ['\\\\', '$', "\\'"], $var) . |
|
235 | + return "'". |
|
236 | + str_replace(['\\', '$', "'"], ['\\\\', '$', "\\'"], $var). |
|
237 | 237 | "'"; |
238 | 238 | } |
239 | 239 |
@@ -92,8 +92,8 @@ discard block |
||
92 | 92 | } |
93 | 93 | if (!$baseModel instanceof Model) { |
94 | 94 | throw new Exception\Unsupported( |
95 | - 'Unsupported Model(' . |
|
96 | - get_class($baseModel) . |
|
95 | + 'Unsupported Model('. |
|
96 | + get_class($baseModel). |
|
97 | 97 | ') Type was passed, it must implement hamleModel', |
98 | 98 | ); |
99 | 99 | } |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | throw new Exception\NotFound("Unable to find HAMLE Template ($template)"); |
129 | 129 | } |
130 | 130 | $this->cacheFile = $this->setup->cachePath( |
131 | - str_replace('/', '-', $hamleFile) . '.php', |
|
131 | + str_replace('/', '-', $hamleFile).'.php', |
|
132 | 132 | ); |
133 | 133 | $this->setup->debugLog("Set cache file path to ({$this->cacheFile})"); |
134 | 134 | $cacheFileAge = is_file($this->cacheFile) ? filemtime($this->cacheFile) : 0; |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | function string(string $hamleString): void |
194 | 194 | { |
195 | 195 | $md5 = md5($hamleString); |
196 | - $stringId = substr($md5, 0, 12) . substr($md5, 24, 8); |
|
196 | + $stringId = substr($md5, 0, 12).substr($md5, 24, 8); |
|
197 | 197 | $this->cacheFile = $this->setup->cachePath("string.$stringId.hamle.php"); |
198 | 198 | if (!is_file($this->cacheFile)) { |
199 | 199 | $this->parse($hamleString); |
@@ -32,7 +32,7 @@ |
||
32 | 32 | static function fromParser( |
33 | 33 | array $chars, |
34 | 34 | ?Evaluated $expr = null, |
35 | - string|StringLit|StringConcat $rhs = null |
|
35 | + string | StringLit | StringConcat $rhs = null |
|
36 | 36 | ): self { |
37 | 37 | $o = []; |
38 | 38 | if ($chars) { |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | $this->filters = $filters; |
20 | 20 | } |
21 | 21 | |
22 | - static function for(string $rel, array $filters): self |
|
22 | + static function for (string $rel, array $filters): self |
|
23 | 23 | { |
24 | 24 | return new self( |
25 | 25 | $rel === '>' ? Hamle::REL_CHILD : Hamle::REL_PARENT, |
@@ -30,9 +30,9 @@ discard block |
||
30 | 30 | public function apply(string $out): string |
31 | 31 | { |
32 | 32 | $out = |
33 | - $out . |
|
34 | - "->hamleRel({$this->rel}," . |
|
35 | - Query::queryParams($this->filters, true) . |
|
33 | + $out. |
|
34 | + "->hamleRel({$this->rel},". |
|
35 | + Query::queryParams($this->filters, true). |
|
36 | 36 | ')'; |
37 | 37 | if ($this->chain) { |
38 | 38 | $out = $this->chain->apply($out); |
@@ -50,9 +50,9 @@ |
||
50 | 50 | function toPHP(): string |
51 | 51 | { |
52 | 52 | if (is_numeric($this->scope)) { |
53 | - return 'Hamle\\Scope::get(' . Text::varToCode($this->scope) . ')'; |
|
53 | + return 'Hamle\\Scope::get('.Text::varToCode($this->scope).')'; |
|
54 | 54 | } else { |
55 | - return 'Hamle\\Scope::getName(' . Text::varToCode($this->scope) . ')'; |
|
55 | + return 'Hamle\\Scope::getName('.Text::varToCode($this->scope).')'; |
|
56 | 56 | } |
57 | 57 | } |
58 | 58 |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | public function __construct($s) |
51 | 51 | { |
52 | 52 | $m = []; |
53 | - if (!preg_match('/^\$\((' . self::REGEX_FUNCSEL . '*)(.*)\)$/', $s, $m)) { |
|
53 | + if (!preg_match('/^\$\(('.self::REGEX_FUNCSEL.'*)(.*)\)$/', $s, $m)) { |
|
54 | 54 | throw new ParseError("Unable to read \$ func in '$s'"); |
55 | 55 | } |
56 | 56 | if (trim($m[2])) { |
@@ -137,31 +137,31 @@ discard block |
||
137 | 137 | */ |
138 | 138 | public function toPHP(): string |
139 | 139 | { |
140 | - $sub = $this->sub ? '->' . $this->sub->toPHP() : ''; |
|
140 | + $sub = $this->sub ? '->'.$this->sub->toPHP() : ''; |
|
141 | 141 | if ($this->scope instanceof Scope) { |
142 | - return $this->scope->toPHP() . $sub; |
|
142 | + return $this->scope->toPHP().$sub; |
|
143 | 143 | } elseif ($this->scope === true) { |
144 | 144 | return "Hamle\\Scope::get(0)$sub"; |
145 | 145 | } |
146 | 146 | $limit = |
147 | - Text::varToCode($this->sortlimit['sort']) . |
|
148 | - ',' . |
|
149 | - $this->sortlimit['limit'] . |
|
150 | - ',' . |
|
147 | + Text::varToCode($this->sortlimit['sort']). |
|
148 | + ','. |
|
149 | + $this->sortlimit['limit']. |
|
150 | + ','. |
|
151 | 151 | $this->sortlimit['offset']; |
152 | 152 | if (count($this->filt['tag'])) { |
153 | - return 'Hamle\\Run::modelTypeTags(' . |
|
154 | - Text::varToCode($this->filt['tag']) . |
|
153 | + return 'Hamle\\Run::modelTypeTags('. |
|
154 | + Text::varToCode($this->filt['tag']). |
|
155 | 155 | ",$limit)$sub"; |
156 | 156 | } |
157 | 157 | if (count($this->filt['id'])) { |
158 | 158 | if (isset($this->filt['id']['*']) && count($this->filt['id']['*']) == 1) { |
159 | - return 'Hamle\\Run::modelId(' . |
|
160 | - Text::varToCode(current($this->filt['id']['*'])) . |
|
159 | + return 'Hamle\\Run::modelId('. |
|
160 | + Text::varToCode(current($this->filt['id']['*'])). |
|
161 | 161 | ",$limit)$sub"; |
162 | 162 | } else { |
163 | - return 'Hamle\\Run::modelTypeId(' . |
|
164 | - Text::varToCode($this->filt['id']) . |
|
163 | + return 'Hamle\\Run::modelTypeId('. |
|
164 | + Text::varToCode($this->filt['id']). |
|
165 | 165 | ",$limit)$sub"; |
166 | 166 | } |
167 | 167 | } |
@@ -48,9 +48,9 @@ discard block |
||
48 | 48 | function toHTML(bool $escape = false): string |
49 | 49 | { |
50 | 50 | if ($escape) { |
51 | - return '<?=htmlspecialchars(' . $this->toPHP() . ')?>'; |
|
51 | + return '<?=htmlspecialchars('.$this->toPHP().')?>'; |
|
52 | 52 | } |
53 | - return '<?=' . $this->toPHP() . '?>'; |
|
53 | + return '<?='.$this->toPHP().'?>'; |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | function toPHP(): string |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | |
61 | 61 | function toPHPVar(): string |
62 | 62 | { |
63 | - return 'Hamle\\Scope::get()->hamleGet(' . Text::varToCode($this->var) . ')'; |
|
63 | + return 'Hamle\\Scope::get()->hamleGet('.Text::varToCode($this->var).')'; |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | function getOrCreateModel(Model $parent = null): Model |
@@ -64,9 +64,9 @@ discard block |
||
64 | 64 | function toHTML(bool $escape = false): string |
65 | 65 | { |
66 | 66 | if ($escape) { |
67 | - return '<?=htmlspecialchars(' . $this->toPHP() . ')?>'; |
|
67 | + return '<?=htmlspecialchars('.$this->toPHP().')?>'; |
|
68 | 68 | } |
69 | - return '<?=' . $this->toPHP() . '?>'; |
|
69 | + return '<?='.$this->toPHP().'?>'; |
|
70 | 70 | } |
71 | 71 | function toPHP(): string |
72 | 72 | { |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | foreach ($this->sel as $s) { |
81 | 81 | $sel[] = "hamleGet('$s')"; |
82 | 82 | } |
83 | - return $this->func->toPHP() . '->' . implode('->', $sel); |
|
83 | + return $this->func->toPHP().'->'.implode('->', $sel); |
|
84 | 84 | } else { |
85 | 85 | return $this->func->toPHP(); |
86 | 86 | } |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | return $this->func->getOrCreateModel($parent); |
96 | 96 | } |
97 | 97 | throw new RuntimeException( |
98 | - 'Unsupported func type encountered:' . |
|
98 | + 'Unsupported func type encountered:'. |
|
99 | 99 | ($this->func ? get_class($this->func) : 'Unknown'), |
100 | 100 | ); |
101 | 101 | } |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | $model = $this->getOrCreateModel(); |
115 | 115 | if (!$model instanceof WriteModel) { |
116 | 116 | throw new RuntimeException( |
117 | - 'Can only set values on WriteModel, got ' . get_class($model), |
|
117 | + 'Can only set values on WriteModel, got '.get_class($model), |
|
118 | 118 | ); |
119 | 119 | } |
120 | 120 | $model->hamleSet($this->sel[0], $value); |