Completed
Pull Request — master (#3)
by Chris
02:36
created
php/hamle/Setup.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -48,7 +48,7 @@
 block discarded – undo
48 48
     if (!is_dir($dir)) {
49 49
       mkdir($dir);
50 50
     }
51
-    return $dir . $f;
51
+    return $dir.$f;
52 52
   }
53 53
 
54 54
   /**
Please login to merge, or discard this patch.
php/hamle/Parse.php 5 patches
Indentation   -279 removed lines patch added patch discarded remove patch
@@ -54,282 +54,3 @@
 block discarded – undo
54 54
    */
55 55
 
56 56
   const REGEX_PARSE_LINE = <<<'ENDREGEX'
57
-  /^(\s*)(?:(?:([a-zA-Z0-9-]*)((?:[\.#!][\w\-\_]+)*)(\[(?:(?:\{\$[^\}]+\})?[^\\\]{]*?(?:\\.)*?(?:{[^\$])*?)+\])?)|([_\/]{1,3})|([\|:\$]\w+)|({?\$[^}]+}?)|)(?: (.*))?$/
58
-  ENDREGEX;
59
-
60
-  /**
61
-   * @var int Current Line Number
62
-   */
63
-  protected $lineNo;
64
-  /**
65
-   * @var int Total Lines in File
66
-   */
67
-  protected $lineCount;
68
-
69
-  function __construct()
70
-  {
71
-    $this->init();
72
-  }
73
-
74
-  /**
75
-   * Clear Lines, and Line Number, so if output is
76
-   * called, no output will be produced
77
-   */
78
-  protected function init()
79
-  {
80
-    $this->lines = [];
81
-    $this->lineNo = 0;
82
-    $this->lineCount = 0;
83
-    $this->root = [];
84
-  }
85
-
86
-  protected function loadLines($s)
87
-  {
88
-    $this->lines = explode("\n", str_replace("\r", '', $s));
89
-    $this->lineCount = count($this->lines);
90
-    $this->lineNo = 0;
91
-  }
92
-
93
-  function parseFilter(ParseFilter $filter)
94
-  {
95
-    foreach ($this->root as $k => $tag) {
96
-      $this->root[$k] = $filter->filterTag($tag);
97
-    }
98
-  }
99
-
100
-  function parseSnip($s)
101
-  {
102
-    //save root tags
103
-    /** @var Tag[] $roots */
104
-    $roots = $this->root;
105
-    $this->root = [];
106
-    $this->loadLines($s);
107
-    $this->procLines();
108
-    $this->root = array_merge($roots, $this->root);
109
-  }
110
-
111
-  function applySnip()
112
-  {
113
-    /** @var Tag\Snippet[] $fwdSnip */
114
-    $fwdSnip = [];
115
-    /** @var Tag\Snippet[] $revSnip */
116
-    $revSnip = [];
117
-    /** @var Tag[] $roots */
118
-    $roots = [];
119
-    foreach ($this->root as $snip) {
120
-      if ($snip instanceof Tag\Snippet) {
121
-        if ($snip->getType() == 'append') {
122
-          array_unshift($revSnip, $snip);
123
-        } else {
124
-          $fwdSnip[] = $snip;
125
-        }
126
-      } else {
127
-        $roots[] = $snip;
128
-      }
129
-    }
130
-    foreach ($fwdSnip as $snip) {
131
-      foreach ($roots as $root) {
132
-        $snip->apply($root);
133
-      };
134
-    }
135
-    foreach ($revSnip as $snip) {
136
-      foreach ($roots as $root) {
137
-        $snip->apply($root);
138
-      };
139
-    }
140
-    $this->root = $roots;
141
-  }
142
-
143
-  /**
144
-   * Parse HAMLE template, from a string
145
-   * @param string $s String to parse
146
-   */
147
-  function str($s)
148
-  {
149
-    $this->init();
150
-    $this->loadLines($s);
151
-    $this->procLines();
152
-  }
153
-
154
-  function procLines()
155
-  {
156
-    /* @var $heir Tag[] Tag Heirachy Array */
157
-    $heir = [];
158
-    while ($this->lineNo < $this->lineCount) {
159
-      $line = $this->lines[$this->lineNo];
160
-      if (trim($line)) {
161
-        if (preg_match(self::REGEX_PARSE_LINE, $line, $m)) {
162
-          if (false !== strpos($m[1], "\t")) {
163
-            throw new ParseError(
164
-              'Tabs are not supported in templates at this time',
165
-            );
166
-          }
167
-          $indent = strlen($m[1]);
168
-          $tag = isset($m[2]) ? ($tag = $m[2]) : '';
169
-          $classid = isset($m[3]) ? $m[3] : '';
170
-          $params = str_replace(
171
-            ['\[', '\]', '\\&'],
172
-            ['[', ']', '%26'],
173
-            isset($m[4]) ? $m[4] : '',
174
-          );
175
-          $textcode = isset($m[5]) ? $m[5] : '';
176
-          $text = isset($m[8]) ? $m[8] : '';
177
-          $code = isset($m[6]) ? $m[6] : '';
178
-          $i = self::indentLevel($indent);
179
-          unset($m[0]);
180
-          switch (strlen($code) ? $code[0] : ($textcode ? $textcode : '')) {
181
-            case '|': //Control Tag
182
-              if ($code == '|snippet') {
183
-                $hTag = new Tag\Snippet($text);
184
-              } elseif ($code == '|form') {
185
-                $hTag = new Tag\Form($text);
186
-              } elseif ($code == '|formhint') {
187
-                $hTag = new Tag\FormHint();
188
-              } elseif ($code == '|else') {
189
-                $hTag = new Tag\Control(substr($code, 1), $heir[$i - 1]);
190
-                $hTag->setVar($text);
191
-              } else {
192
-                $hTag = new Tag\Control(substr($code, 1));
193
-                $hTag->setVar($text);
194
-              }
195
-              break;
196
-            case ':': //Filter Tag
197
-              $hTag = new Tag\Filter(substr($code, 1));
198
-              $hTag->addContent($text, Text::TOKEN_CODE);
199
-              foreach ($this->consumeBlock($indent) as $l) {
200
-                $hTag->addContent($l, Text::TOKEN_CODE);
201
-              }
202
-              break;
203
-            case '_': //String Tag
204
-            case '__': //Unescape String Tag
205
-            case '___': //Unescape String Tag (with unescaped vars)
206
-              $hTag = new Tag\Text($textcode);
207
-              $hTag->addContent($text);
208
-              break;
209
-            case '___': //Unescape String Tag
210
-              $hTag = new Tag\Text($textcode);
211
-              $hTag->addContent($text);
212
-              break;
213
-            case '/': // HTML Comment
214
-            case '//': // Non Printed Comment
215
-              $hTag = new Tag\Comment($textcode);
216
-              $hTag->addContent($text);
217
-              foreach ($this->consumeBlock($indent) as $l) {
218
-                $hTag->addContent($l, Text::TOKEN_CODE);
219
-              }
220
-              break;
221
-            default:
222
-              $attr = [];
223
-              if (isset($params[0]) && $params[0] == '[') {
224
-                $param = substr($params, 1, -1);
225
-                $param = str_replace(['+', '\\&'], ['%2B', '%26'], $param);
226
-                //              parse_str($param, $attr);
227
-                $attr = $this->parseQueryString($param);
228
-              }
229
-              $class = [];
230
-              $id = '';
231
-              $ref = '';
232
-              preg_match_all('/[#\.!][a-zA-Z0-9\-\_]+/m', $classid, $cid);
233
-              if (isset($cid[0])) {
234
-                foreach ($cid[0] as $s) {
235
-                  if ($s[0] == '#') {
236
-                    $id = substr($s, 1);
237
-                  }
238
-                  if ($s[0] == '.') {
239
-                    $class[] = substr($s, 1);
240
-                  }
241
-                  if ($s[0] == '!') {
242
-                    $ref = substr($s, 1);
243
-                  }
244
-                };
245
-              }
246
-              if ($ref) {
247
-                $hTag = new Tag\DynHtml($tag, $class, $attr, $id, $ref);
248
-              } else {
249
-                $hTag = new Tag\Html($tag, $class, $attr, $id);
250
-              }
251
-              $hTag->addContent($text);
252
-              break;
253
-          }
254
-          $heir[$i] = $hTag;
255
-          if ($i > 0) {
256
-            $heir[$i - 1]->addChild($hTag);
257
-          } else {
258
-            $this->root[] = $hTag;
259
-          }
260
-        } else {
261
-          throw new ParseError(
262
-            "Unable to parse line {$this->lineNo}\n\"$line\"/" .
263
-              preg_last_error(),
264
-          );
265
-        }
266
-      }
267
-      $this->lineNo++;
268
-    }
269
-  }
270
-
271
-  function parseQueryString($qs)
272
-  {
273
-    $out = [];
274
-    foreach (explode('&', $qs) as $s) {
275
-      $kv = explode('=', $s, 2);
276
-      $out[urldecode($kv[0])] = isset($kv[1]) ? urldecode($kv[1]) : null;
277
-    }
278
-    return $out;
279
-  }
280
-
281
-  function output($minify = false)
282
-  {
283
-    $out = "<?php\nuse Seufert\\Hamle;\n?>";
284
-    foreach ($this->root as $tag) {
285
-      $out .= $tag->render(0, $minify);
286
-    }
287
-    return $out;
288
-  }
289
-
290
-  function consumeBlock($indent)
291
-  {
292
-    $out = [];
293
-    $m = [];
294
-    while (
295
-      $this->lineNo + 1 < $this->lineCount &&
296
-      (!trim($this->lines[$this->lineNo + 1]) ||
297
-        preg_match(
298
-          '/^(\s){' . $indent . '}((\s)+[^\s].*)$/',
299
-          $this->lines[$this->lineNo + 1],
300
-          $m,
301
-        ))
302
-    ) {
303
-      if (trim($this->lines[$this->lineNo + 1])) {
304
-        $out[] = $m[2];
305
-      }
306
-      $this->lineNo++;
307
-    }
308
-    return $out;
309
-  }
310
-
311
-  function indentLevel($indent)
312
-  {
313
-    if (!isset($this->indents)) {
314
-      $this->indents = [];
315
-    }
316
-    if (!count($this->indents)) {
317
-      $this->indents = [0 => $indent];
318
-      // Key = indent level, Value = Depth in spaces
319
-      return 0;
320
-    }
321
-    foreach ($this->indents as $k => $v) {
322
-      if ($v == $indent) {
323
-        $this->indents = array_slice($this->indents, 0, $k + 1);
324
-        return $k;
325
-      }
326
-    }
327
-    $this->indents[] = $indent;
328
-    return max(array_keys($this->indents));
329
-  }
330
-
331
-  function getLineNo()
332
-  {
333
-    return $this->lineNo;
334
-  }
335
-}
Please login to merge, or discard this patch.
Switch Indentation   -279 removed lines patch added patch discarded remove patch
@@ -54,282 +54,3 @@
 block discarded – undo
54 54
    */
55 55
 
56 56
   const REGEX_PARSE_LINE = <<<'ENDREGEX'
57
-  /^(\s*)(?:(?:([a-zA-Z0-9-]*)((?:[\.#!][\w\-\_]+)*)(\[(?:(?:\{\$[^\}]+\})?[^\\\]{]*?(?:\\.)*?(?:{[^\$])*?)+\])?)|([_\/]{1,3})|([\|:\$]\w+)|({?\$[^}]+}?)|)(?: (.*))?$/
58
-  ENDREGEX;
59
-
60
-  /**
61
-   * @var int Current Line Number
62
-   */
63
-  protected $lineNo;
64
-  /**
65
-   * @var int Total Lines in File
66
-   */
67
-  protected $lineCount;
68
-
69
-  function __construct()
70
-  {
71
-    $this->init();
72
-  }
73
-
74
-  /**
75
-   * Clear Lines, and Line Number, so if output is
76
-   * called, no output will be produced
77
-   */
78
-  protected function init()
79
-  {
80
-    $this->lines = [];
81
-    $this->lineNo = 0;
82
-    $this->lineCount = 0;
83
-    $this->root = [];
84
-  }
85
-
86
-  protected function loadLines($s)
87
-  {
88
-    $this->lines = explode("\n", str_replace("\r", '', $s));
89
-    $this->lineCount = count($this->lines);
90
-    $this->lineNo = 0;
91
-  }
92
-
93
-  function parseFilter(ParseFilter $filter)
94
-  {
95
-    foreach ($this->root as $k => $tag) {
96
-      $this->root[$k] = $filter->filterTag($tag);
97
-    }
98
-  }
99
-
100
-  function parseSnip($s)
101
-  {
102
-    //save root tags
103
-    /** @var Tag[] $roots */
104
-    $roots = $this->root;
105
-    $this->root = [];
106
-    $this->loadLines($s);
107
-    $this->procLines();
108
-    $this->root = array_merge($roots, $this->root);
109
-  }
110
-
111
-  function applySnip()
112
-  {
113
-    /** @var Tag\Snippet[] $fwdSnip */
114
-    $fwdSnip = [];
115
-    /** @var Tag\Snippet[] $revSnip */
116
-    $revSnip = [];
117
-    /** @var Tag[] $roots */
118
-    $roots = [];
119
-    foreach ($this->root as $snip) {
120
-      if ($snip instanceof Tag\Snippet) {
121
-        if ($snip->getType() == 'append') {
122
-          array_unshift($revSnip, $snip);
123
-        } else {
124
-          $fwdSnip[] = $snip;
125
-        }
126
-      } else {
127
-        $roots[] = $snip;
128
-      }
129
-    }
130
-    foreach ($fwdSnip as $snip) {
131
-      foreach ($roots as $root) {
132
-        $snip->apply($root);
133
-      };
134
-    }
135
-    foreach ($revSnip as $snip) {
136
-      foreach ($roots as $root) {
137
-        $snip->apply($root);
138
-      };
139
-    }
140
-    $this->root = $roots;
141
-  }
142
-
143
-  /**
144
-   * Parse HAMLE template, from a string
145
-   * @param string $s String to parse
146
-   */
147
-  function str($s)
148
-  {
149
-    $this->init();
150
-    $this->loadLines($s);
151
-    $this->procLines();
152
-  }
153
-
154
-  function procLines()
155
-  {
156
-    /* @var $heir Tag[] Tag Heirachy Array */
157
-    $heir = [];
158
-    while ($this->lineNo < $this->lineCount) {
159
-      $line = $this->lines[$this->lineNo];
160
-      if (trim($line)) {
161
-        if (preg_match(self::REGEX_PARSE_LINE, $line, $m)) {
162
-          if (false !== strpos($m[1], "\t")) {
163
-            throw new ParseError(
164
-              'Tabs are not supported in templates at this time',
165
-            );
166
-          }
167
-          $indent = strlen($m[1]);
168
-          $tag = isset($m[2]) ? ($tag = $m[2]) : '';
169
-          $classid = isset($m[3]) ? $m[3] : '';
170
-          $params = str_replace(
171
-            ['\[', '\]', '\\&'],
172
-            ['[', ']', '%26'],
173
-            isset($m[4]) ? $m[4] : '',
174
-          );
175
-          $textcode = isset($m[5]) ? $m[5] : '';
176
-          $text = isset($m[8]) ? $m[8] : '';
177
-          $code = isset($m[6]) ? $m[6] : '';
178
-          $i = self::indentLevel($indent);
179
-          unset($m[0]);
180
-          switch (strlen($code) ? $code[0] : ($textcode ? $textcode : '')) {
181
-            case '|': //Control Tag
182
-              if ($code == '|snippet') {
183
-                $hTag = new Tag\Snippet($text);
184
-              } elseif ($code == '|form') {
185
-                $hTag = new Tag\Form($text);
186
-              } elseif ($code == '|formhint') {
187
-                $hTag = new Tag\FormHint();
188
-              } elseif ($code == '|else') {
189
-                $hTag = new Tag\Control(substr($code, 1), $heir[$i - 1]);
190
-                $hTag->setVar($text);
191
-              } else {
192
-                $hTag = new Tag\Control(substr($code, 1));
193
-                $hTag->setVar($text);
194
-              }
195
-              break;
196
-            case ':': //Filter Tag
197
-              $hTag = new Tag\Filter(substr($code, 1));
198
-              $hTag->addContent($text, Text::TOKEN_CODE);
199
-              foreach ($this->consumeBlock($indent) as $l) {
200
-                $hTag->addContent($l, Text::TOKEN_CODE);
201
-              }
202
-              break;
203
-            case '_': //String Tag
204
-            case '__': //Unescape String Tag
205
-            case '___': //Unescape String Tag (with unescaped vars)
206
-              $hTag = new Tag\Text($textcode);
207
-              $hTag->addContent($text);
208
-              break;
209
-            case '___': //Unescape String Tag
210
-              $hTag = new Tag\Text($textcode);
211
-              $hTag->addContent($text);
212
-              break;
213
-            case '/': // HTML Comment
214
-            case '//': // Non Printed Comment
215
-              $hTag = new Tag\Comment($textcode);
216
-              $hTag->addContent($text);
217
-              foreach ($this->consumeBlock($indent) as $l) {
218
-                $hTag->addContent($l, Text::TOKEN_CODE);
219
-              }
220
-              break;
221
-            default:
222
-              $attr = [];
223
-              if (isset($params[0]) && $params[0] == '[') {
224
-                $param = substr($params, 1, -1);
225
-                $param = str_replace(['+', '\\&'], ['%2B', '%26'], $param);
226
-                //              parse_str($param, $attr);
227
-                $attr = $this->parseQueryString($param);
228
-              }
229
-              $class = [];
230
-              $id = '';
231
-              $ref = '';
232
-              preg_match_all('/[#\.!][a-zA-Z0-9\-\_]+/m', $classid, $cid);
233
-              if (isset($cid[0])) {
234
-                foreach ($cid[0] as $s) {
235
-                  if ($s[0] == '#') {
236
-                    $id = substr($s, 1);
237
-                  }
238
-                  if ($s[0] == '.') {
239
-                    $class[] = substr($s, 1);
240
-                  }
241
-                  if ($s[0] == '!') {
242
-                    $ref = substr($s, 1);
243
-                  }
244
-                };
245
-              }
246
-              if ($ref) {
247
-                $hTag = new Tag\DynHtml($tag, $class, $attr, $id, $ref);
248
-              } else {
249
-                $hTag = new Tag\Html($tag, $class, $attr, $id);
250
-              }
251
-              $hTag->addContent($text);
252
-              break;
253
-          }
254
-          $heir[$i] = $hTag;
255
-          if ($i > 0) {
256
-            $heir[$i - 1]->addChild($hTag);
257
-          } else {
258
-            $this->root[] = $hTag;
259
-          }
260
-        } else {
261
-          throw new ParseError(
262
-            "Unable to parse line {$this->lineNo}\n\"$line\"/" .
263
-              preg_last_error(),
264
-          );
265
-        }
266
-      }
267
-      $this->lineNo++;
268
-    }
269
-  }
270
-
271
-  function parseQueryString($qs)
272
-  {
273
-    $out = [];
274
-    foreach (explode('&', $qs) as $s) {
275
-      $kv = explode('=', $s, 2);
276
-      $out[urldecode($kv[0])] = isset($kv[1]) ? urldecode($kv[1]) : null;
277
-    }
278
-    return $out;
279
-  }
280
-
281
-  function output($minify = false)
282
-  {
283
-    $out = "<?php\nuse Seufert\\Hamle;\n?>";
284
-    foreach ($this->root as $tag) {
285
-      $out .= $tag->render(0, $minify);
286
-    }
287
-    return $out;
288
-  }
289
-
290
-  function consumeBlock($indent)
291
-  {
292
-    $out = [];
293
-    $m = [];
294
-    while (
295
-      $this->lineNo + 1 < $this->lineCount &&
296
-      (!trim($this->lines[$this->lineNo + 1]) ||
297
-        preg_match(
298
-          '/^(\s){' . $indent . '}((\s)+[^\s].*)$/',
299
-          $this->lines[$this->lineNo + 1],
300
-          $m,
301
-        ))
302
-    ) {
303
-      if (trim($this->lines[$this->lineNo + 1])) {
304
-        $out[] = $m[2];
305
-      }
306
-      $this->lineNo++;
307
-    }
308
-    return $out;
309
-  }
310
-
311
-  function indentLevel($indent)
312
-  {
313
-    if (!isset($this->indents)) {
314
-      $this->indents = [];
315
-    }
316
-    if (!count($this->indents)) {
317
-      $this->indents = [0 => $indent];
318
-      // Key = indent level, Value = Depth in spaces
319
-      return 0;
320
-    }
321
-    foreach ($this->indents as $k => $v) {
322
-      if ($v == $indent) {
323
-        $this->indents = array_slice($this->indents, 0, $k + 1);
324
-        return $k;
325
-      }
326
-    }
327
-    $this->indents[] = $indent;
328
-    return max(array_keys($this->indents));
329
-  }
330
-
331
-  function getLineNo()
332
-  {
333
-    return $this->lineNo;
334
-  }
335
-}
Please login to merge, or discard this patch.
Spacing   -279 removed lines patch added patch discarded remove patch
@@ -54,282 +54,3 @@
 block discarded – undo
54 54
    */
55 55
 
56 56
   const REGEX_PARSE_LINE = <<<'ENDREGEX'
57
-  /^(\s*)(?:(?:([a-zA-Z0-9-]*)((?:[\.#!][\w\-\_]+)*)(\[(?:(?:\{\$[^\}]+\})?[^\\\]{]*?(?:\\.)*?(?:{[^\$])*?)+\])?)|([_\/]{1,3})|([\|:\$]\w+)|({?\$[^}]+}?)|)(?: (.*))?$/
58
-  ENDREGEX;
59
-
60
-  /**
61
-   * @var int Current Line Number
62
-   */
63
-  protected $lineNo;
64
-  /**
65
-   * @var int Total Lines in File
66
-   */
67
-  protected $lineCount;
68
-
69
-  function __construct()
70
-  {
71
-    $this->init();
72
-  }
73
-
74
-  /**
75
-   * Clear Lines, and Line Number, so if output is
76
-   * called, no output will be produced
77
-   */
78
-  protected function init()
79
-  {
80
-    $this->lines = [];
81
-    $this->lineNo = 0;
82
-    $this->lineCount = 0;
83
-    $this->root = [];
84
-  }
85
-
86
-  protected function loadLines($s)
87
-  {
88
-    $this->lines = explode("\n", str_replace("\r", '', $s));
89
-    $this->lineCount = count($this->lines);
90
-    $this->lineNo = 0;
91
-  }
92
-
93
-  function parseFilter(ParseFilter $filter)
94
-  {
95
-    foreach ($this->root as $k => $tag) {
96
-      $this->root[$k] = $filter->filterTag($tag);
97
-    }
98
-  }
99
-
100
-  function parseSnip($s)
101
-  {
102
-    //save root tags
103
-    /** @var Tag[] $roots */
104
-    $roots = $this->root;
105
-    $this->root = [];
106
-    $this->loadLines($s);
107
-    $this->procLines();
108
-    $this->root = array_merge($roots, $this->root);
109
-  }
110
-
111
-  function applySnip()
112
-  {
113
-    /** @var Tag\Snippet[] $fwdSnip */
114
-    $fwdSnip = [];
115
-    /** @var Tag\Snippet[] $revSnip */
116
-    $revSnip = [];
117
-    /** @var Tag[] $roots */
118
-    $roots = [];
119
-    foreach ($this->root as $snip) {
120
-      if ($snip instanceof Tag\Snippet) {
121
-        if ($snip->getType() == 'append') {
122
-          array_unshift($revSnip, $snip);
123
-        } else {
124
-          $fwdSnip[] = $snip;
125
-        }
126
-      } else {
127
-        $roots[] = $snip;
128
-      }
129
-    }
130
-    foreach ($fwdSnip as $snip) {
131
-      foreach ($roots as $root) {
132
-        $snip->apply($root);
133
-      };
134
-    }
135
-    foreach ($revSnip as $snip) {
136
-      foreach ($roots as $root) {
137
-        $snip->apply($root);
138
-      };
139
-    }
140
-    $this->root = $roots;
141
-  }
142
-
143
-  /**
144
-   * Parse HAMLE template, from a string
145
-   * @param string $s String to parse
146
-   */
147
-  function str($s)
148
-  {
149
-    $this->init();
150
-    $this->loadLines($s);
151
-    $this->procLines();
152
-  }
153
-
154
-  function procLines()
155
-  {
156
-    /* @var $heir Tag[] Tag Heirachy Array */
157
-    $heir = [];
158
-    while ($this->lineNo < $this->lineCount) {
159
-      $line = $this->lines[$this->lineNo];
160
-      if (trim($line)) {
161
-        if (preg_match(self::REGEX_PARSE_LINE, $line, $m)) {
162
-          if (false !== strpos($m[1], "\t")) {
163
-            throw new ParseError(
164
-              'Tabs are not supported in templates at this time',
165
-            );
166
-          }
167
-          $indent = strlen($m[1]);
168
-          $tag = isset($m[2]) ? ($tag = $m[2]) : '';
169
-          $classid = isset($m[3]) ? $m[3] : '';
170
-          $params = str_replace(
171
-            ['\[', '\]', '\\&'],
172
-            ['[', ']', '%26'],
173
-            isset($m[4]) ? $m[4] : '',
174
-          );
175
-          $textcode = isset($m[5]) ? $m[5] : '';
176
-          $text = isset($m[8]) ? $m[8] : '';
177
-          $code = isset($m[6]) ? $m[6] : '';
178
-          $i = self::indentLevel($indent);
179
-          unset($m[0]);
180
-          switch (strlen($code) ? $code[0] : ($textcode ? $textcode : '')) {
181
-            case '|': //Control Tag
182
-              if ($code == '|snippet') {
183
-                $hTag = new Tag\Snippet($text);
184
-              } elseif ($code == '|form') {
185
-                $hTag = new Tag\Form($text);
186
-              } elseif ($code == '|formhint') {
187
-                $hTag = new Tag\FormHint();
188
-              } elseif ($code == '|else') {
189
-                $hTag = new Tag\Control(substr($code, 1), $heir[$i - 1]);
190
-                $hTag->setVar($text);
191
-              } else {
192
-                $hTag = new Tag\Control(substr($code, 1));
193
-                $hTag->setVar($text);
194
-              }
195
-              break;
196
-            case ':': //Filter Tag
197
-              $hTag = new Tag\Filter(substr($code, 1));
198
-              $hTag->addContent($text, Text::TOKEN_CODE);
199
-              foreach ($this->consumeBlock($indent) as $l) {
200
-                $hTag->addContent($l, Text::TOKEN_CODE);
201
-              }
202
-              break;
203
-            case '_': //String Tag
204
-            case '__': //Unescape String Tag
205
-            case '___': //Unescape String Tag (with unescaped vars)
206
-              $hTag = new Tag\Text($textcode);
207
-              $hTag->addContent($text);
208
-              break;
209
-            case '___': //Unescape String Tag
210
-              $hTag = new Tag\Text($textcode);
211
-              $hTag->addContent($text);
212
-              break;
213
-            case '/': // HTML Comment
214
-            case '//': // Non Printed Comment
215
-              $hTag = new Tag\Comment($textcode);
216
-              $hTag->addContent($text);
217
-              foreach ($this->consumeBlock($indent) as $l) {
218
-                $hTag->addContent($l, Text::TOKEN_CODE);
219
-              }
220
-              break;
221
-            default:
222
-              $attr = [];
223
-              if (isset($params[0]) && $params[0] == '[') {
224
-                $param = substr($params, 1, -1);
225
-                $param = str_replace(['+', '\\&'], ['%2B', '%26'], $param);
226
-                //              parse_str($param, $attr);
227
-                $attr = $this->parseQueryString($param);
228
-              }
229
-              $class = [];
230
-              $id = '';
231
-              $ref = '';
232
-              preg_match_all('/[#\.!][a-zA-Z0-9\-\_]+/m', $classid, $cid);
233
-              if (isset($cid[0])) {
234
-                foreach ($cid[0] as $s) {
235
-                  if ($s[0] == '#') {
236
-                    $id = substr($s, 1);
237
-                  }
238
-                  if ($s[0] == '.') {
239
-                    $class[] = substr($s, 1);
240
-                  }
241
-                  if ($s[0] == '!') {
242
-                    $ref = substr($s, 1);
243
-                  }
244
-                };
245
-              }
246
-              if ($ref) {
247
-                $hTag = new Tag\DynHtml($tag, $class, $attr, $id, $ref);
248
-              } else {
249
-                $hTag = new Tag\Html($tag, $class, $attr, $id);
250
-              }
251
-              $hTag->addContent($text);
252
-              break;
253
-          }
254
-          $heir[$i] = $hTag;
255
-          if ($i > 0) {
256
-            $heir[$i - 1]->addChild($hTag);
257
-          } else {
258
-            $this->root[] = $hTag;
259
-          }
260
-        } else {
261
-          throw new ParseError(
262
-            "Unable to parse line {$this->lineNo}\n\"$line\"/" .
263
-              preg_last_error(),
264
-          );
265
-        }
266
-      }
267
-      $this->lineNo++;
268
-    }
269
-  }
270
-
271
-  function parseQueryString($qs)
272
-  {
273
-    $out = [];
274
-    foreach (explode('&', $qs) as $s) {
275
-      $kv = explode('=', $s, 2);
276
-      $out[urldecode($kv[0])] = isset($kv[1]) ? urldecode($kv[1]) : null;
277
-    }
278
-    return $out;
279
-  }
280
-
281
-  function output($minify = false)
282
-  {
283
-    $out = "<?php\nuse Seufert\\Hamle;\n?>";
284
-    foreach ($this->root as $tag) {
285
-      $out .= $tag->render(0, $minify);
286
-    }
287
-    return $out;
288
-  }
289
-
290
-  function consumeBlock($indent)
291
-  {
292
-    $out = [];
293
-    $m = [];
294
-    while (
295
-      $this->lineNo + 1 < $this->lineCount &&
296
-      (!trim($this->lines[$this->lineNo + 1]) ||
297
-        preg_match(
298
-          '/^(\s){' . $indent . '}((\s)+[^\s].*)$/',
299
-          $this->lines[$this->lineNo + 1],
300
-          $m,
301
-        ))
302
-    ) {
303
-      if (trim($this->lines[$this->lineNo + 1])) {
304
-        $out[] = $m[2];
305
-      }
306
-      $this->lineNo++;
307
-    }
308
-    return $out;
309
-  }
310
-
311
-  function indentLevel($indent)
312
-  {
313
-    if (!isset($this->indents)) {
314
-      $this->indents = [];
315
-    }
316
-    if (!count($this->indents)) {
317
-      $this->indents = [0 => $indent];
318
-      // Key = indent level, Value = Depth in spaces
319
-      return 0;
320
-    }
321
-    foreach ($this->indents as $k => $v) {
322
-      if ($v == $indent) {
323
-        $this->indents = array_slice($this->indents, 0, $k + 1);
324
-        return $k;
325
-      }
326
-    }
327
-    $this->indents[] = $indent;
328
-    return max(array_keys($this->indents));
329
-  }
330
-
331
-  function getLineNo()
332
-  {
333
-    return $this->lineNo;
334
-  }
335
-}
Please login to merge, or discard this patch.
Braces   -279 removed lines patch added patch discarded remove patch
@@ -54,282 +54,3 @@
 block discarded – undo
54 54
    */
55 55
 
56 56
   const REGEX_PARSE_LINE = <<<'ENDREGEX'
57
-  /^(\s*)(?:(?:([a-zA-Z0-9-]*)((?:[\.#!][\w\-\_]+)*)(\[(?:(?:\{\$[^\}]+\})?[^\\\]{]*?(?:\\.)*?(?:{[^\$])*?)+\])?)|([_\/]{1,3})|([\|:\$]\w+)|({?\$[^}]+}?)|)(?: (.*))?$/
58
-  ENDREGEX;
59
-
60
-  /**
61
-   * @var int Current Line Number
62
-   */
63
-  protected $lineNo;
64
-  /**
65
-   * @var int Total Lines in File
66
-   */
67
-  protected $lineCount;
68
-
69
-  function __construct()
70
-  {
71
-    $this->init();
72
-  }
73
-
74
-  /**
75
-   * Clear Lines, and Line Number, so if output is
76
-   * called, no output will be produced
77
-   */
78
-  protected function init()
79
-  {
80
-    $this->lines = [];
81
-    $this->lineNo = 0;
82
-    $this->lineCount = 0;
83
-    $this->root = [];
84
-  }
85
-
86
-  protected function loadLines($s)
87
-  {
88
-    $this->lines = explode("\n", str_replace("\r", '', $s));
89
-    $this->lineCount = count($this->lines);
90
-    $this->lineNo = 0;
91
-  }
92
-
93
-  function parseFilter(ParseFilter $filter)
94
-  {
95
-    foreach ($this->root as $k => $tag) {
96
-      $this->root[$k] = $filter->filterTag($tag);
97
-    }
98
-  }
99
-
100
-  function parseSnip($s)
101
-  {
102
-    //save root tags
103
-    /** @var Tag[] $roots */
104
-    $roots = $this->root;
105
-    $this->root = [];
106
-    $this->loadLines($s);
107
-    $this->procLines();
108
-    $this->root = array_merge($roots, $this->root);
109
-  }
110
-
111
-  function applySnip()
112
-  {
113
-    /** @var Tag\Snippet[] $fwdSnip */
114
-    $fwdSnip = [];
115
-    /** @var Tag\Snippet[] $revSnip */
116
-    $revSnip = [];
117
-    /** @var Tag[] $roots */
118
-    $roots = [];
119
-    foreach ($this->root as $snip) {
120
-      if ($snip instanceof Tag\Snippet) {
121
-        if ($snip->getType() == 'append') {
122
-          array_unshift($revSnip, $snip);
123
-        } else {
124
-          $fwdSnip[] = $snip;
125
-        }
126
-      } else {
127
-        $roots[] = $snip;
128
-      }
129
-    }
130
-    foreach ($fwdSnip as $snip) {
131
-      foreach ($roots as $root) {
132
-        $snip->apply($root);
133
-      };
134
-    }
135
-    foreach ($revSnip as $snip) {
136
-      foreach ($roots as $root) {
137
-        $snip->apply($root);
138
-      };
139
-    }
140
-    $this->root = $roots;
141
-  }
142
-
143
-  /**
144
-   * Parse HAMLE template, from a string
145
-   * @param string $s String to parse
146
-   */
147
-  function str($s)
148
-  {
149
-    $this->init();
150
-    $this->loadLines($s);
151
-    $this->procLines();
152
-  }
153
-
154
-  function procLines()
155
-  {
156
-    /* @var $heir Tag[] Tag Heirachy Array */
157
-    $heir = [];
158
-    while ($this->lineNo < $this->lineCount) {
159
-      $line = $this->lines[$this->lineNo];
160
-      if (trim($line)) {
161
-        if (preg_match(self::REGEX_PARSE_LINE, $line, $m)) {
162
-          if (false !== strpos($m[1], "\t")) {
163
-            throw new ParseError(
164
-              'Tabs are not supported in templates at this time',
165
-            );
166
-          }
167
-          $indent = strlen($m[1]);
168
-          $tag = isset($m[2]) ? ($tag = $m[2]) : '';
169
-          $classid = isset($m[3]) ? $m[3] : '';
170
-          $params = str_replace(
171
-            ['\[', '\]', '\\&'],
172
-            ['[', ']', '%26'],
173
-            isset($m[4]) ? $m[4] : '',
174
-          );
175
-          $textcode = isset($m[5]) ? $m[5] : '';
176
-          $text = isset($m[8]) ? $m[8] : '';
177
-          $code = isset($m[6]) ? $m[6] : '';
178
-          $i = self::indentLevel($indent);
179
-          unset($m[0]);
180
-          switch (strlen($code) ? $code[0] : ($textcode ? $textcode : '')) {
181
-            case '|': //Control Tag
182
-              if ($code == '|snippet') {
183
-                $hTag = new Tag\Snippet($text);
184
-              } elseif ($code == '|form') {
185
-                $hTag = new Tag\Form($text);
186
-              } elseif ($code == '|formhint') {
187
-                $hTag = new Tag\FormHint();
188
-              } elseif ($code == '|else') {
189
-                $hTag = new Tag\Control(substr($code, 1), $heir[$i - 1]);
190
-                $hTag->setVar($text);
191
-              } else {
192
-                $hTag = new Tag\Control(substr($code, 1));
193
-                $hTag->setVar($text);
194
-              }
195
-              break;
196
-            case ':': //Filter Tag
197
-              $hTag = new Tag\Filter(substr($code, 1));
198
-              $hTag->addContent($text, Text::TOKEN_CODE);
199
-              foreach ($this->consumeBlock($indent) as $l) {
200
-                $hTag->addContent($l, Text::TOKEN_CODE);
201
-              }
202
-              break;
203
-            case '_': //String Tag
204
-            case '__': //Unescape String Tag
205
-            case '___': //Unescape String Tag (with unescaped vars)
206
-              $hTag = new Tag\Text($textcode);
207
-              $hTag->addContent($text);
208
-              break;
209
-            case '___': //Unescape String Tag
210
-              $hTag = new Tag\Text($textcode);
211
-              $hTag->addContent($text);
212
-              break;
213
-            case '/': // HTML Comment
214
-            case '//': // Non Printed Comment
215
-              $hTag = new Tag\Comment($textcode);
216
-              $hTag->addContent($text);
217
-              foreach ($this->consumeBlock($indent) as $l) {
218
-                $hTag->addContent($l, Text::TOKEN_CODE);
219
-              }
220
-              break;
221
-            default:
222
-              $attr = [];
223
-              if (isset($params[0]) && $params[0] == '[') {
224
-                $param = substr($params, 1, -1);
225
-                $param = str_replace(['+', '\\&'], ['%2B', '%26'], $param);
226
-                //              parse_str($param, $attr);
227
-                $attr = $this->parseQueryString($param);
228
-              }
229
-              $class = [];
230
-              $id = '';
231
-              $ref = '';
232
-              preg_match_all('/[#\.!][a-zA-Z0-9\-\_]+/m', $classid, $cid);
233
-              if (isset($cid[0])) {
234
-                foreach ($cid[0] as $s) {
235
-                  if ($s[0] == '#') {
236
-                    $id = substr($s, 1);
237
-                  }
238
-                  if ($s[0] == '.') {
239
-                    $class[] = substr($s, 1);
240
-                  }
241
-                  if ($s[0] == '!') {
242
-                    $ref = substr($s, 1);
243
-                  }
244
-                };
245
-              }
246
-              if ($ref) {
247
-                $hTag = new Tag\DynHtml($tag, $class, $attr, $id, $ref);
248
-              } else {
249
-                $hTag = new Tag\Html($tag, $class, $attr, $id);
250
-              }
251
-              $hTag->addContent($text);
252
-              break;
253
-          }
254
-          $heir[$i] = $hTag;
255
-          if ($i > 0) {
256
-            $heir[$i - 1]->addChild($hTag);
257
-          } else {
258
-            $this->root[] = $hTag;
259
-          }
260
-        } else {
261
-          throw new ParseError(
262
-            "Unable to parse line {$this->lineNo}\n\"$line\"/" .
263
-              preg_last_error(),
264
-          );
265
-        }
266
-      }
267
-      $this->lineNo++;
268
-    }
269
-  }
270
-
271
-  function parseQueryString($qs)
272
-  {
273
-    $out = [];
274
-    foreach (explode('&', $qs) as $s) {
275
-      $kv = explode('=', $s, 2);
276
-      $out[urldecode($kv[0])] = isset($kv[1]) ? urldecode($kv[1]) : null;
277
-    }
278
-    return $out;
279
-  }
280
-
281
-  function output($minify = false)
282
-  {
283
-    $out = "<?php\nuse Seufert\\Hamle;\n?>";
284
-    foreach ($this->root as $tag) {
285
-      $out .= $tag->render(0, $minify);
286
-    }
287
-    return $out;
288
-  }
289
-
290
-  function consumeBlock($indent)
291
-  {
292
-    $out = [];
293
-    $m = [];
294
-    while (
295
-      $this->lineNo + 1 < $this->lineCount &&
296
-      (!trim($this->lines[$this->lineNo + 1]) ||
297
-        preg_match(
298
-          '/^(\s){' . $indent . '}((\s)+[^\s].*)$/',
299
-          $this->lines[$this->lineNo + 1],
300
-          $m,
301
-        ))
302
-    ) {
303
-      if (trim($this->lines[$this->lineNo + 1])) {
304
-        $out[] = $m[2];
305
-      }
306
-      $this->lineNo++;
307
-    }
308
-    return $out;
309
-  }
310
-
311
-  function indentLevel($indent)
312
-  {
313
-    if (!isset($this->indents)) {
314
-      $this->indents = [];
315
-    }
316
-    if (!count($this->indents)) {
317
-      $this->indents = [0 => $indent];
318
-      // Key = indent level, Value = Depth in spaces
319
-      return 0;
320
-    }
321
-    foreach ($this->indents as $k => $v) {
322
-      if ($v == $indent) {
323
-        $this->indents = array_slice($this->indents, 0, $k + 1);
324
-        return $k;
325
-      }
326
-    }
327
-    $this->indents[] = $indent;
328
-    return max(array_keys($this->indents));
329
-  }
330
-
331
-  function getLineNo()
332
-  {
333
-    return $this->lineNo;
334
-  }
335
-}
Please login to merge, or discard this patch.
Upper-Lower-Casing   -279 removed lines patch added patch discarded remove patch
@@ -54,282 +54,3 @@
 block discarded – undo
54 54
    */
55 55
 
56 56
   const REGEX_PARSE_LINE = <<<'ENDREGEX'
57
-  /^(\s*)(?:(?:([a-zA-Z0-9-]*)((?:[\.#!][\w\-\_]+)*)(\[(?:(?:\{\$[^\}]+\})?[^\\\]{]*?(?:\\.)*?(?:{[^\$])*?)+\])?)|([_\/]{1,3})|([\|:\$]\w+)|({?\$[^}]+}?)|)(?: (.*))?$/
58
-  ENDREGEX;
59
-
60
-  /**
61
-   * @var int Current Line Number
62
-   */
63
-  protected $lineNo;
64
-  /**
65
-   * @var int Total Lines in File
66
-   */
67
-  protected $lineCount;
68
-
69
-  function __construct()
70
-  {
71
-    $this->init();
72
-  }
73
-
74
-  /**
75
-   * Clear Lines, and Line Number, so if output is
76
-   * called, no output will be produced
77
-   */
78
-  protected function init()
79
-  {
80
-    $this->lines = [];
81
-    $this->lineNo = 0;
82
-    $this->lineCount = 0;
83
-    $this->root = [];
84
-  }
85
-
86
-  protected function loadLines($s)
87
-  {
88
-    $this->lines = explode("\n", str_replace("\r", '', $s));
89
-    $this->lineCount = count($this->lines);
90
-    $this->lineNo = 0;
91
-  }
92
-
93
-  function parseFilter(ParseFilter $filter)
94
-  {
95
-    foreach ($this->root as $k => $tag) {
96
-      $this->root[$k] = $filter->filterTag($tag);
97
-    }
98
-  }
99
-
100
-  function parseSnip($s)
101
-  {
102
-    //save root tags
103
-    /** @var Tag[] $roots */
104
-    $roots = $this->root;
105
-    $this->root = [];
106
-    $this->loadLines($s);
107
-    $this->procLines();
108
-    $this->root = array_merge($roots, $this->root);
109
-  }
110
-
111
-  function applySnip()
112
-  {
113
-    /** @var Tag\Snippet[] $fwdSnip */
114
-    $fwdSnip = [];
115
-    /** @var Tag\Snippet[] $revSnip */
116
-    $revSnip = [];
117
-    /** @var Tag[] $roots */
118
-    $roots = [];
119
-    foreach ($this->root as $snip) {
120
-      if ($snip instanceof Tag\Snippet) {
121
-        if ($snip->getType() == 'append') {
122
-          array_unshift($revSnip, $snip);
123
-        } else {
124
-          $fwdSnip[] = $snip;
125
-        }
126
-      } else {
127
-        $roots[] = $snip;
128
-      }
129
-    }
130
-    foreach ($fwdSnip as $snip) {
131
-      foreach ($roots as $root) {
132
-        $snip->apply($root);
133
-      };
134
-    }
135
-    foreach ($revSnip as $snip) {
136
-      foreach ($roots as $root) {
137
-        $snip->apply($root);
138
-      };
139
-    }
140
-    $this->root = $roots;
141
-  }
142
-
143
-  /**
144
-   * Parse HAMLE template, from a string
145
-   * @param string $s String to parse
146
-   */
147
-  function str($s)
148
-  {
149
-    $this->init();
150
-    $this->loadLines($s);
151
-    $this->procLines();
152
-  }
153
-
154
-  function procLines()
155
-  {
156
-    /* @var $heir Tag[] Tag Heirachy Array */
157
-    $heir = [];
158
-    while ($this->lineNo < $this->lineCount) {
159
-      $line = $this->lines[$this->lineNo];
160
-      if (trim($line)) {
161
-        if (preg_match(self::REGEX_PARSE_LINE, $line, $m)) {
162
-          if (false !== strpos($m[1], "\t")) {
163
-            throw new ParseError(
164
-              'Tabs are not supported in templates at this time',
165
-            );
166
-          }
167
-          $indent = strlen($m[1]);
168
-          $tag = isset($m[2]) ? ($tag = $m[2]) : '';
169
-          $classid = isset($m[3]) ? $m[3] : '';
170
-          $params = str_replace(
171
-            ['\[', '\]', '\\&'],
172
-            ['[', ']', '%26'],
173
-            isset($m[4]) ? $m[4] : '',
174
-          );
175
-          $textcode = isset($m[5]) ? $m[5] : '';
176
-          $text = isset($m[8]) ? $m[8] : '';
177
-          $code = isset($m[6]) ? $m[6] : '';
178
-          $i = self::indentLevel($indent);
179
-          unset($m[0]);
180
-          switch (strlen($code) ? $code[0] : ($textcode ? $textcode : '')) {
181
-            case '|': //Control Tag
182
-              if ($code == '|snippet') {
183
-                $hTag = new Tag\Snippet($text);
184
-              } elseif ($code == '|form') {
185
-                $hTag = new Tag\Form($text);
186
-              } elseif ($code == '|formhint') {
187
-                $hTag = new Tag\FormHint();
188
-              } elseif ($code == '|else') {
189
-                $hTag = new Tag\Control(substr($code, 1), $heir[$i - 1]);
190
-                $hTag->setVar($text);
191
-              } else {
192
-                $hTag = new Tag\Control(substr($code, 1));
193
-                $hTag->setVar($text);
194
-              }
195
-              break;
196
-            case ':': //Filter Tag
197
-              $hTag = new Tag\Filter(substr($code, 1));
198
-              $hTag->addContent($text, Text::TOKEN_CODE);
199
-              foreach ($this->consumeBlock($indent) as $l) {
200
-                $hTag->addContent($l, Text::TOKEN_CODE);
201
-              }
202
-              break;
203
-            case '_': //String Tag
204
-            case '__': //Unescape String Tag
205
-            case '___': //Unescape String Tag (with unescaped vars)
206
-              $hTag = new Tag\Text($textcode);
207
-              $hTag->addContent($text);
208
-              break;
209
-            case '___': //Unescape String Tag
210
-              $hTag = new Tag\Text($textcode);
211
-              $hTag->addContent($text);
212
-              break;
213
-            case '/': // HTML Comment
214
-            case '//': // Non Printed Comment
215
-              $hTag = new Tag\Comment($textcode);
216
-              $hTag->addContent($text);
217
-              foreach ($this->consumeBlock($indent) as $l) {
218
-                $hTag->addContent($l, Text::TOKEN_CODE);
219
-              }
220
-              break;
221
-            default:
222
-              $attr = [];
223
-              if (isset($params[0]) && $params[0] == '[') {
224
-                $param = substr($params, 1, -1);
225
-                $param = str_replace(['+', '\\&'], ['%2B', '%26'], $param);
226
-                //              parse_str($param, $attr);
227
-                $attr = $this->parseQueryString($param);
228
-              }
229
-              $class = [];
230
-              $id = '';
231
-              $ref = '';
232
-              preg_match_all('/[#\.!][a-zA-Z0-9\-\_]+/m', $classid, $cid);
233
-              if (isset($cid[0])) {
234
-                foreach ($cid[0] as $s) {
235
-                  if ($s[0] == '#') {
236
-                    $id = substr($s, 1);
237
-                  }
238
-                  if ($s[0] == '.') {
239
-                    $class[] = substr($s, 1);
240
-                  }
241
-                  if ($s[0] == '!') {
242
-                    $ref = substr($s, 1);
243
-                  }
244
-                };
245
-              }
246
-              if ($ref) {
247
-                $hTag = new Tag\DynHtml($tag, $class, $attr, $id, $ref);
248
-              } else {
249
-                $hTag = new Tag\Html($tag, $class, $attr, $id);
250
-              }
251
-              $hTag->addContent($text);
252
-              break;
253
-          }
254
-          $heir[$i] = $hTag;
255
-          if ($i > 0) {
256
-            $heir[$i - 1]->addChild($hTag);
257
-          } else {
258
-            $this->root[] = $hTag;
259
-          }
260
-        } else {
261
-          throw new ParseError(
262
-            "Unable to parse line {$this->lineNo}\n\"$line\"/" .
263
-              preg_last_error(),
264
-          );
265
-        }
266
-      }
267
-      $this->lineNo++;
268
-    }
269
-  }
270
-
271
-  function parseQueryString($qs)
272
-  {
273
-    $out = [];
274
-    foreach (explode('&', $qs) as $s) {
275
-      $kv = explode('=', $s, 2);
276
-      $out[urldecode($kv[0])] = isset($kv[1]) ? urldecode($kv[1]) : null;
277
-    }
278
-    return $out;
279
-  }
280
-
281
-  function output($minify = false)
282
-  {
283
-    $out = "<?php\nuse Seufert\\Hamle;\n?>";
284
-    foreach ($this->root as $tag) {
285
-      $out .= $tag->render(0, $minify);
286
-    }
287
-    return $out;
288
-  }
289
-
290
-  function consumeBlock($indent)
291
-  {
292
-    $out = [];
293
-    $m = [];
294
-    while (
295
-      $this->lineNo + 1 < $this->lineCount &&
296
-      (!trim($this->lines[$this->lineNo + 1]) ||
297
-        preg_match(
298
-          '/^(\s){' . $indent . '}((\s)+[^\s].*)$/',
299
-          $this->lines[$this->lineNo + 1],
300
-          $m,
301
-        ))
302
-    ) {
303
-      if (trim($this->lines[$this->lineNo + 1])) {
304
-        $out[] = $m[2];
305
-      }
306
-      $this->lineNo++;
307
-    }
308
-    return $out;
309
-  }
310
-
311
-  function indentLevel($indent)
312
-  {
313
-    if (!isset($this->indents)) {
314
-      $this->indents = [];
315
-    }
316
-    if (!count($this->indents)) {
317
-      $this->indents = [0 => $indent];
318
-      // Key = indent level, Value = Depth in spaces
319
-      return 0;
320
-    }
321
-    foreach ($this->indents as $k => $v) {
322
-      if ($v == $indent) {
323
-        $this->indents = array_slice($this->indents, 0, $k + 1);
324
-        return $k;
325
-      }
326
-    }
327
-    $this->indents[] = $indent;
328
-    return max(array_keys($this->indents));
329
-  }
330
-
331
-  function getLineNo()
332
-  {
333
-    return $this->lineNo;
334
-  }
335
-}
Please login to merge, or discard this patch.
php/hamle/Text.php 1 patch
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
   {
123 123
     $func = $filter['func'];
124 124
     if (method_exists(Filter::class, $func)) {
125
-      $func = Filter::class . '::' . $func;
125
+      $func = Filter::class.'::'.$func;
126 126
     } elseif (
127 127
       in_array($func, ['round', 'strtoupper', 'strtolower', 'ucfirst'])
128 128
     ) {
@@ -138,7 +138,7 @@  discard block
 block discarded – undo
138 138
     }
139 139
     $args = join(
140 140
       ',',
141
-      array_map(function ($v) {
141
+      array_map(function($v) {
142 142
         if (is_array($v) && $v['type'] ?? false === 'expr') {
143 143
           return self::renderExpr($v);
144 144
         } else {
@@ -147,9 +147,9 @@  discard block
 block discarded – undo
147 147
       }, $filter['args']),
148 148
     );
149 149
     if (strlen($args)) {
150
-      $args = ',' . $args;
150
+      $args = ','.$args;
151 151
     }
152
-    $o = "$func($o" . $args . ')';
152
+    $o = "$func($o".$args.')';
153 153
     if ($filter['chain'] ?? false) {
154 154
       $o = self::addFilter($o, $filter['chain']);
155 155
     }
@@ -158,21 +158,21 @@  discard block
 block discarded – undo
158 158
 
159 159
   static function renderScopeThis($n)
160 160
   {
161
-    $o = 'Hamle\Scope::get()->hamleGet(' . self::varToCode($n['name']) . ')';
161
+    $o = 'Hamle\Scope::get()->hamleGet('.self::varToCode($n['name']).')';
162 162
     $o = self::addParams($o, $n['param'] ?? []);
163 163
     return $o;
164 164
   }
165 165
 
166 166
   static function renderScopeId($n)
167 167
   {
168
-    $o = 'Hamle\Scope::get(' . $n['id'] . ')';
168
+    $o = 'Hamle\Scope::get('.$n['id'].')';
169 169
     $o = self::addParams($o, $n['param'] ?? []);
170 170
     return $o;
171 171
   }
172 172
 
173 173
   static function renderScopeName($n)
174 174
   {
175
-    $o = 'Hamle\Scope::getName(' . self::varToCode($n['name']) . ')';
175
+    $o = 'Hamle\Scope::getName('.self::varToCode($n['name']).')';
176 176
     $o = self::addParams($o, $n['param'] ?? []);
177 177
     return $o;
178 178
   }
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
   static function addParams(string $o, array $params)
181 181
   {
182 182
     while ($params['type'] ?? null === 'sub') {
183
-      $o .= '->hamleGet(' . self::varToCode($params['name']) . ')';
183
+      $o .= '->hamleGet('.self::varToCode($params['name']).')';
184 184
       $params = $params['params'] ?? [];
185 185
     }
186 186
     return $o;
@@ -190,11 +190,11 @@  discard block
 block discarded – undo
190 190
   {
191 191
     $r = $rel === 'child' ? Hamle::REL_CHILD : Hamle::REL_PARENT;
192 192
     $o =
193
-      $o .
194
-      '->hamleRel(' .
195
-      self::varToCode($r) .
196
-      ',' .
197
-      self::queryParams($query, true) .
193
+      $o.
194
+      '->hamleRel('.
195
+      self::varToCode($r).
196
+      ','.
197
+      self::queryParams($query, true).
198 198
       ')';
199 199
     return $o;
200 200
   }
@@ -256,7 +256,7 @@  discard block
 block discarded – undo
256 256
       self::varToCode($limit),
257 257
       self::varToCode($offset),
258 258
     ];
259
-    return 'Hamle\Run::modelTypeId(' . join(',', $opt) . ')';
259
+    return 'Hamle\Run::modelTypeId('.join(',', $opt).')';
260 260
   }
261 261
 
262 262
   static function renderQuery($n)
@@ -277,7 +277,7 @@  discard block
 block discarded – undo
277 277
     } elseif ($id !== null) {
278 278
       $o = self::queryId($n['query']);
279 279
     } else {
280
-      $o = 'Hamle\Run::modelTypeTags(' . self::queryParams($n['query']) . ')';
280
+      $o = 'Hamle\Run::modelTypeTags('.self::queryParams($n['query']).')';
281 281
     }
282 282
     if ($n['sub'] ?? []) {
283 283
       $o = self::addRel($o, $n['sub'], $n['rel']);
@@ -304,7 +304,7 @@  discard block
 block discarded – undo
304 304
         $o = self::renderQuery($expr['body']);
305 305
         break;
306 306
       default:
307
-        throw new \RuntimeException('Invalid Node: ' . $expr['body']['type']);
307
+        throw new \RuntimeException('Invalid Node: '.$expr['body']['type']);
308 308
     }
309 309
     if ($expr['body']['filter'] ?? false) {
310 310
       $o = self::addFilter($o, $expr['body']['filter']);
@@ -324,16 +324,16 @@  discard block
 block discarded – undo
324 324
           }
325 325
           break;
326 326
         case 'scopeName':
327
-          $out .= '<?=' . self::renderScopeName($node) . '?>';
327
+          $out .= '<?='.self::renderScopeName($node).'?>';
328 328
           break;
329 329
         case 'scopeThis':
330
-          $out .= '<?=' . self::renderScopeThis($node) . '?>';
330
+          $out .= '<?='.self::renderScopeThis($node).'?>';
331 331
           break;
332 332
         case 'expr':
333
-          $out .= '<?=' . self::renderExpr($node) . '?>';
333
+          $out .= '<?='.self::renderExpr($node).'?>';
334 334
           break;
335 335
         default:
336
-          throw new \RuntimeException('Invalid Node:' . $node['type']);
336
+          throw new \RuntimeException('Invalid Node:'.$node['type']);
337 337
       }
338 338
     }
339 339
     return $out;
@@ -362,7 +362,7 @@  discard block
 block discarded – undo
362 362
           $out[] = self::renderExpr($node);
363 363
           break;
364 364
         default:
365
-          throw new \RuntimeException('Invalid Node:' . $node['type']);
365
+          throw new \RuntimeException('Invalid Node:'.$node['type']);
366 366
       }
367 367
     }
368 368
     return join('.', $out);
@@ -370,7 +370,7 @@  discard block
 block discarded – undo
370 370
 
371 371
   function doEval()
372 372
   {
373
-    return eval('use Seufert\Hamle; return ' . $this->toPHP() . ';');
373
+    return eval('use Seufert\Hamle; return '.$this->toPHP().';');
374 374
   }
375 375
 
376 376
   static function varToCode($var)
@@ -378,9 +378,9 @@  discard block
 block discarded – undo
378 378
     if (is_array($var)) {
379 379
       $code = [];
380 380
       foreach ($var as $key => $value) {
381
-        $code[] = self::varToCode($key) . '=>' . self::varToCode($value);
381
+        $code[] = self::varToCode($key).'=>'.self::varToCode($value);
382 382
       }
383
-      return 'array(' . implode(',', $code) . ')'; //remove unnecessary coma
383
+      return 'array('.implode(',', $code).')'; //remove unnecessary coma
384 384
     }
385 385
     if (is_bool($var)) {
386 386
       return $var ? 'TRUE' : 'FALSE';
@@ -391,7 +391,7 @@  discard block
 block discarded – undo
391 391
     if ($var instanceof Text) {
392 392
       return $var->toPHP();
393 393
     }
394
-    return "'" . str_replace(['$', "'"], ['$', "\\'"], $var) . "'";
394
+    return "'".str_replace(['$', "'"], ['$', "\\'"], $var)."'";
395 395
   }
396 396
 
397 397
   /**
Please login to merge, or discard this patch.
php/hamle/Field/Button.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -37,6 +37,6 @@
 block discarded – undo
37 37
 
38 38
   function isClicked()
39 39
   {
40
-    return isset($_REQUEST[$this->form . '_' . $this->name]);
40
+    return isset($_REQUEST[$this->form.'_'.$this->name]);
41 41
   }
42 42
 }
Please login to merge, or discard this patch.
php/hamle/Field/Checkbox.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -49,8 +49,8 @@
 block discarded – undo
49 49
     if (!is_null($this->setValue)) {
50 50
       return $this->setValue;
51 51
     }
52
-    if (isset($_REQUEST[$this->form . '__submit'])) {
53
-      return isset($_REQUEST[$this->form . '_' . $this->name]);
52
+    if (isset($_REQUEST[$this->form.'__submit'])) {
53
+      return isset($_REQUEST[$this->form.'_'.$this->name]);
54 54
     }
55 55
     return $this->opt['default'];
56 56
   }
Please login to merge, or discard this patch.
php/hamle/TextNode/ScopeName.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -33,7 +33,7 @@
 block discarded – undo
33 33
 
34 34
   public function toPHP(): string
35 35
   {
36
-    $o = 'Hamle\\Scope::getName(' . Text::varToCode($this->name) . ')';
36
+    $o = 'Hamle\\Scope::getName('.Text::varToCode($this->name).')';
37 37
     if ($this->immediate) {
38 38
       $o = $this->immediate->apply($o);
39 39
     }
Please login to merge, or discard this patch.
php/hamle/TextNode/ModelParam.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@
 block discarded – undo
20 20
 
21 21
   public function apply(string $out): string
22 22
   {
23
-    $o = "{$out}->hamleGet(" . Text::varToCode($this->name) . ')';
23
+    $o = "{$out}->hamleGet(".Text::varToCode($this->name).')';
24 24
     if ($this->chain) {
25 25
       $o = $this->chain->apply($o);
26 26
     }
Please login to merge, or discard this patch.
php/hamle/TextNode/FilterFunc.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
     $this->chain = $chain;
23 23
     $this->args = $args;
24 24
     if (method_exists(Filter::class, $func)) {
25
-      $this->func = Filter::class . '::' . $func;
25
+      $this->func = Filter::class.'::'.$func;
26 26
     } elseif (
27 27
       in_array($func, ['round', 'strtoupper', 'strtolower', 'ucfirst'])
28 28
     ) {
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
       $this->args,
49 49
     );
50 50
     array_unshift($args, $out);
51
-    $o = "{$this->func}(" . join(',', $args) . ')';
51
+    $o = "{$this->func}(".join(',', $args).')';
52 52
     if ($this->chain) {
53 53
       $o = $this->chain->apply($o);
54 54
     }
Please login to merge, or discard this patch.
php/hamle/TextNode/RelQuery.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
     $this->filters = $filters;
21 21
   }
22 22
 
23
-  static function for(string $rel, array $filters)
23
+  static function for (string $rel, array $filters)
24 24
   {
25 25
     return new self(
26 26
       $rel === '>' ? Hamle::REL_CHILD : Hamle::REL_PARENT,
@@ -31,9 +31,9 @@  discard block
 block discarded – undo
31 31
   public function apply(string $s): string
32 32
   {
33 33
     $s =
34
-      $s .
35
-      "->hamleRel({$this->rel}," .
36
-      Query::queryParams($this->filters, true) .
34
+      $s.
35
+      "->hamleRel({$this->rel},".
36
+      Query::queryParams($this->filters, true).
37 37
       ')';
38 38
     if ($this->chain) {
39 39
       $s = $this->chain->apply($s);
Please login to merge, or discard this patch.