@@ -37,9 +37,9 @@ discard block |
||
37 | 37 | protected $filter; |
38 | 38 | |
39 | 39 | function __construct($s) { |
40 | - if(FALSE !== $pos = strpos($s,'|')) { |
|
41 | - $this->filter = new Filter(substr($s, $pos+1), $this); |
|
42 | - $s = substr($s,0,$pos); |
|
40 | + if (FALSE !== $pos = strpos($s, '|')) { |
|
41 | + $this->filter = new Filter(substr($s, $pos + 1), $this); |
|
42 | + $s = substr($s, 0, $pos); |
|
43 | 43 | } |
44 | 44 | $s = preg_split("/-[>!]/", $s); |
45 | 45 | // if(count($s) == 1) $s = explode("-!",$s[0]); |
@@ -55,27 +55,27 @@ discard block |
||
55 | 55 | } |
56 | 56 | |
57 | 57 | function toHTML($escape = false) { |
58 | - if($escape) |
|
59 | - return "<?=htmlspecialchars(" .$this->toPHP() . ")?>"; |
|
60 | - return "<?=" . $this->toPHP() . "?>"; |
|
58 | + if ($escape) |
|
59 | + return "<?=htmlspecialchars(".$this->toPHP().")?>"; |
|
60 | + return "<?=".$this->toPHP()."?>"; |
|
61 | 61 | } |
62 | 62 | function toPHP() { |
63 | - return $this->filter?$this->filter->toPHP():$this->toPHPVar(); |
|
63 | + return $this->filter ? $this->filter->toPHP() : $this->toPHPVar(); |
|
64 | 64 | } |
65 | 65 | function toPHPVar() { |
66 | 66 | if ($this->sel) { |
67 | 67 | $sel = array(); |
68 | 68 | foreach ($this->sel as $s) |
69 | 69 | $sel[] = "hamleGet('$s')"; |
70 | - return $this->func->toPHP() . "->" . implode('->', $sel); |
|
70 | + return $this->func->toPHP()."->".implode('->', $sel); |
|
71 | 71 | } else |
72 | 72 | return $this->func->toPHP(); |
73 | 73 | } |
74 | 74 | |
75 | 75 | function getOrCreateModel(Model $parent = null) { |
76 | - if($this->func instanceof Text\Scope) |
|
76 | + if ($this->func instanceof Text\Scope) |
|
77 | 77 | return $this->func->getOrCreateModel($parent); |
78 | - if($this->func instanceof Text\Func) |
|
78 | + if ($this->func instanceof Text\Func) |
|
79 | 79 | return $this->func->getOrCreateModel($parent); |
80 | 80 | throw new RuntimeException('Unsupported func type encountered:'.get_class($this->func)); |
81 | 81 | } |
@@ -85,10 +85,10 @@ discard block |
||
85 | 85 | * @return WriteModel |
86 | 86 | */ |
87 | 87 | function setValue($value) { |
88 | - if(!$this->sel || count($this->sel) != 1) |
|
88 | + if (!$this->sel || count($this->sel) != 1) |
|
89 | 89 | throw new RuntimeException('Can only set values, when one var name is present'); |
90 | 90 | $model = $this->getOrCreateModel(); |
91 | - if(!$model instanceof WriteModel) |
|
91 | + if (!$model instanceof WriteModel) |
|
92 | 92 | throw new RuntimeException('Can only set values on WriteModel, got '.get_class($model)); |
93 | 93 | $model->hamleSet($this->sel[0], $value); |
94 | 94 | return $model; |
@@ -43,20 +43,24 @@ discard block |
||
43 | 43 | } |
44 | 44 | $s = preg_split("/-[>!]/", $s); |
45 | 45 | // if(count($s) == 1) $s = explode("-!",$s[0]); |
46 | - if (!$s[0]) throw new ParseError("Unable to parse Complex Expression"); |
|
47 | - if ($s[0][1] === '(') |
|
48 | - $this->func = new Text\Func($s[0]); |
|
49 | - elseif ($s[0][1] === '[') |
|
50 | - $this->func = new Text\Scope($s[0]); |
|
51 | - else |
|
52 | - $this->func = new SimpleVar($s[0]); |
|
46 | + if (!$s[0]) { |
|
47 | + throw new ParseError("Unable to parse Complex Expression"); |
|
48 | + } |
|
49 | + if ($s[0][1] === '(') { |
|
50 | + $this->func = new Text\Func($s[0]); |
|
51 | + } elseif ($s[0][1] === '[') { |
|
52 | + $this->func = new Text\Scope($s[0]); |
|
53 | + } else { |
|
54 | + $this->func = new SimpleVar($s[0]); |
|
55 | + } |
|
53 | 56 | array_shift($s); |
54 | 57 | $this->sel = $s; |
55 | 58 | } |
56 | 59 | |
57 | 60 | function toHTML($escape = false) { |
58 | - if($escape) |
|
59 | - return "<?=htmlspecialchars(" .$this->toPHP() . ")?>"; |
|
61 | + if($escape) { |
|
62 | + return "<?=htmlspecialchars(" .$this->toPHP() . ")?>"; |
|
63 | + } |
|
60 | 64 | return "<?=" . $this->toPHP() . "?>"; |
61 | 65 | } |
62 | 66 | function toPHP() { |
@@ -65,18 +69,22 @@ discard block |
||
65 | 69 | function toPHPVar() { |
66 | 70 | if ($this->sel) { |
67 | 71 | $sel = array(); |
68 | - foreach ($this->sel as $s) |
|
69 | - $sel[] = "hamleGet('$s')"; |
|
72 | + foreach ($this->sel as $s) { |
|
73 | + $sel[] = "hamleGet('$s')"; |
|
74 | + } |
|
70 | 75 | return $this->func->toPHP() . "->" . implode('->', $sel); |
71 | - } else |
|
72 | - return $this->func->toPHP(); |
|
76 | + } else { |
|
77 | + return $this->func->toPHP(); |
|
78 | + } |
|
73 | 79 | } |
74 | 80 | |
75 | 81 | function getOrCreateModel(Model $parent = null) { |
76 | - if($this->func instanceof Text\Scope) |
|
77 | - return $this->func->getOrCreateModel($parent); |
|
78 | - if($this->func instanceof Text\Func) |
|
79 | - return $this->func->getOrCreateModel($parent); |
|
82 | + if($this->func instanceof Text\Scope) { |
|
83 | + return $this->func->getOrCreateModel($parent); |
|
84 | + } |
|
85 | + if($this->func instanceof Text\Func) { |
|
86 | + return $this->func->getOrCreateModel($parent); |
|
87 | + } |
|
80 | 88 | throw new RuntimeException('Unsupported func type encountered:'.get_class($this->func)); |
81 | 89 | } |
82 | 90 | |
@@ -85,11 +93,13 @@ discard block |
||
85 | 93 | * @return WriteModel |
86 | 94 | */ |
87 | 95 | function setValue($value) { |
88 | - if(!$this->sel || count($this->sel) != 1) |
|
89 | - throw new RuntimeException('Can only set values, when one var name is present'); |
|
96 | + if(!$this->sel || count($this->sel) != 1) { |
|
97 | + throw new RuntimeException('Can only set values, when one var name is present'); |
|
98 | + } |
|
90 | 99 | $model = $this->getOrCreateModel(); |
91 | - if(!$model instanceof WriteModel) |
|
92 | - throw new RuntimeException('Can only set values on WriteModel, got '.get_class($model)); |
|
100 | + if(!$model instanceof WriteModel) { |
|
101 | + throw new RuntimeException('Can only set values on WriteModel, got '.get_class($model)); |
|
102 | + } |
|
93 | 103 | $model->hamleSet($this->sel[0], $value); |
94 | 104 | return $model; |
95 | 105 | } |
@@ -45,8 +45,9 @@ |
||
45 | 45 | if ($this->escape) { |
46 | 46 | $parse = new H\Text($s, $strtype); |
47 | 47 | $this->content[] = $parse->toHTML($this->escapeVars); |
48 | - } else |
|
49 | - $this->content[] = $s; |
|
48 | + } else { |
|
49 | + $this->content[] = $s; |
|
50 | + } |
|
50 | 51 | } |
51 | 52 | } |
52 | 53 |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | self::$namedScopes[$name] = $model; |
28 | 28 | else |
29 | 29 | self::$scopes[] = $model; |
30 | - if(self::$scopeHook) { |
|
30 | + if (self::$scopeHook) { |
|
31 | 31 | (self::$scopeHook)($model); |
32 | 32 | } |
33 | 33 | } |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | self::$namedScopes[$name]->rewind(); |
74 | 74 | return self::$namedScopes[$name]; |
75 | 75 | } else |
76 | - if(self::$returnZeroOnNoScope) |
|
76 | + if (self::$returnZeroOnNoScope) |
|
77 | 77 | return new Model\Zero(); |
78 | 78 | throw new RunTime("Unable to find scope ($name)"); |
79 | 79 | } |
@@ -21,12 +21,14 @@ discard block |
||
21 | 21 | static $scopeHook; |
22 | 22 | |
23 | 23 | static function add($model, $name = null) { |
24 | - if (!$model instanceOf Model) |
|
25 | - throw new Unsupported("Unsupported Model (".get_class($model)."), Needs to implement hamleModel Interface"); |
|
26 | - if ($name) |
|
27 | - self::$namedScopes[$name] = $model; |
|
28 | - else |
|
29 | - self::$scopes[] = $model; |
|
24 | + if (!$model instanceOf Model) { |
|
25 | + throw new Unsupported("Unsupported Model (".get_class($model)."), Needs to implement hamleModel Interface"); |
|
26 | + } |
|
27 | + if ($name) { |
|
28 | + self::$namedScopes[$name] = $model; |
|
29 | + } else { |
|
30 | + self::$scopes[] = $model; |
|
31 | + } |
|
30 | 32 | if(self::$scopeHook) { |
31 | 33 | (self::$scopeHook)($model); |
32 | 34 | } |
@@ -47,15 +49,21 @@ discard block |
||
47 | 49 | */ |
48 | 50 | static function get($id = 0) { |
49 | 51 | if (0 == $id) { |
50 | - if ($scope = end(self::$scopes)) |
|
51 | - return $scope; |
|
52 | + if ($scope = end(self::$scopes)) { |
|
53 | + return $scope; |
|
54 | + } |
|
52 | 55 | throw new OutOfScope("Unable to find Scope ($id)"); |
53 | 56 | } |
54 | 57 | $key = $id - 1; |
55 | - if ($id < 0) $key = count(self::$scopes) + $id - 1; |
|
56 | - if ($id == 0) $key = count(self::$scopes) - 1; |
|
57 | - if (!isset(self::$scopes[$key])) |
|
58 | - throw new OutOfScope("Unable to find Scope ($id) or $key"); |
|
58 | + if ($id < 0) { |
|
59 | + $key = count(self::$scopes) + $id - 1; |
|
60 | + } |
|
61 | + if ($id == 0) { |
|
62 | + $key = count(self::$scopes) - 1; |
|
63 | + } |
|
64 | + if (!isset(self::$scopes[$key])) { |
|
65 | + throw new OutOfScope("Unable to find Scope ($id) or $key"); |
|
66 | + } |
|
59 | 67 | return self::$scopes[$key]; |
60 | 68 | } |
61 | 69 | |
@@ -73,8 +81,9 @@ discard block |
||
73 | 81 | self::$namedScopes[$name]->rewind(); |
74 | 82 | return self::$namedScopes[$name]; |
75 | 83 | } else |
76 | - if(self::$returnZeroOnNoScope) |
|
77 | - return new Model\Zero(); |
|
84 | + if(self::$returnZeroOnNoScope) { |
|
85 | + return new Model\Zero(); |
|
86 | + } |
|
78 | 87 | throw new RunTime("Unable to find scope ($name)"); |
79 | 88 | } |
80 | 89 |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | $i = self::indentLevel($indent); |
157 | 157 | unset($m[0]); |
158 | 158 | switch (strlen($code) ? $code[0] : ($textcode ? $textcode : "")) { |
159 | - case "|": //Control Tag |
|
159 | + case "|" : //Control Tag |
|
160 | 160 | if ($code == "|snippet") |
161 | 161 | $hTag = new Tag\Snippet($text); |
162 | 162 | elseif ($code == "|form") |
@@ -196,7 +196,7 @@ discard block |
||
196 | 196 | break; |
197 | 197 | default: |
198 | 198 | $attr = array(); |
199 | - if(isset($params[0]) && $params[0] == "[") { |
|
199 | + if (isset($params[0]) && $params[0] == "[") { |
|
200 | 200 | $param = substr($params, 1, -1); |
201 | 201 | $param = str_replace(['+', '\\&'], ['%2B', '%26'], $param); |
202 | 202 | // parse_str($param, $attr); |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | if ($s[0] == ".") $class[] = substr($s, 1); |
210 | 210 | if ($s[0] == "!") $ref = substr($s, 1); |
211 | 211 | } |
212 | - if($ref) |
|
212 | + if ($ref) |
|
213 | 213 | $hTag = new Tag\DynHtml($tag, $class, $attr, $id, $ref); |
214 | 214 | else |
215 | 215 | $hTag = new Tag\Html($tag, $class, $attr, $id); |
@@ -222,16 +222,16 @@ discard block |
||
222 | 222 | else |
223 | 223 | $this->root[] = $hTag; |
224 | 224 | } else |
225 | - throw new ParseError("Unable to parse line {$this->lineNo}\n\"$line\"/" . preg_last_error()); |
|
225 | + throw new ParseError("Unable to parse line {$this->lineNo}\n\"$line\"/".preg_last_error()); |
|
226 | 226 | $this->lineNo++; |
227 | 227 | } |
228 | 228 | } |
229 | 229 | |
230 | 230 | function parseQueryString($qs) { |
231 | 231 | $out = []; |
232 | - foreach(explode('&',$qs) as $s) { |
|
233 | - $kv = explode('=',$s,2); |
|
234 | - $out[urldecode($kv[0])] = isset($kv[1])?urldecode($kv[1]):null; |
|
232 | + foreach (explode('&', $qs) as $s) { |
|
233 | + $kv = explode('=', $s, 2); |
|
234 | + $out[urldecode($kv[0])] = isset($kv[1]) ?urldecode($kv[1]) : null; |
|
235 | 235 | } |
236 | 236 | return $out; |
237 | 237 | } |
@@ -249,7 +249,7 @@ discard block |
||
249 | 249 | $m = array(); |
250 | 250 | while ($this->lineNo + 1 < $this->lineCount && |
251 | 251 | (!trim($this->lines[$this->lineNo + 1]) || |
252 | - preg_match('/^(\s){' . $indent . '}((\s)+[^\s].*)$/', |
|
252 | + preg_match('/^(\s){'.$indent.'}((\s)+[^\s].*)$/', |
|
253 | 253 | $this->lines[$this->lineNo + 1], $m))) { |
254 | 254 | if (trim($this->lines[$this->lineNo + 1])) |
255 | 255 | $out[] = $m[2]; |
@@ -109,22 +109,25 @@ discard block |
||
109 | 109 | $revSnip = array(); |
110 | 110 | /** @var Tag[] $roots */ |
111 | 111 | $roots = array(); |
112 | - foreach ($this->root as $snip) |
|
113 | - if ($snip instanceOf Tag\Snippet) { |
|
112 | + foreach ($this->root as $snip) { |
|
113 | + if ($snip instanceOf Tag\Snippet) { |
|
114 | 114 | if ($snip->getType() == "append") { |
115 | 115 | array_unshift($revSnip, $snip); |
116 | + } |
|
116 | 117 | } else { |
117 | 118 | $fwdSnip[] = $snip; |
118 | 119 | } |
119 | 120 | } else { |
120 | 121 | $roots[] = $snip; |
121 | 122 | } |
122 | - foreach ($fwdSnip as $snip) |
|
123 | - foreach ($roots as $root) |
|
123 | + foreach ($fwdSnip as $snip) { |
|
124 | + foreach ($roots as $root) |
|
124 | 125 | $snip->apply($root); |
125 | - foreach ($revSnip as $snip) |
|
126 | - foreach ($roots as $root) |
|
126 | + } |
|
127 | + foreach ($revSnip as $snip) { |
|
128 | + foreach ($roots as $root) |
|
127 | 129 | $snip->apply($root); |
130 | + } |
|
128 | 131 | $this->root = $roots; |
129 | 132 | } |
130 | 133 | |
@@ -143,9 +146,11 @@ discard block |
||
143 | 146 | $heir = array(); |
144 | 147 | while ($this->lineNo < $this->lineCount) { |
145 | 148 | $line = $this->lines[$this->lineNo]; |
146 | - if (trim($line)) if (preg_match(self::REGEX_PARSE_LINE, $line, $m)) { |
|
149 | + if (trim($line)) { |
|
150 | + if (preg_match(self::REGEX_PARSE_LINE, $line, $m)) { |
|
147 | 151 | if (FALSE !== strpos($m[1], "\t")) |
148 | 152 | throw new ParseError("Tabs are not supported in templates at this time"); |
153 | + } |
|
149 | 154 | $indent = strlen($m[1]); |
150 | 155 | $tag = isset($m[2]) ? $tag = $m[2] : ""; |
151 | 156 | $classid = isset($m[3]) ? $m[3] : ""; |
@@ -157,13 +162,13 @@ discard block |
||
157 | 162 | unset($m[0]); |
158 | 163 | switch (strlen($code) ? $code[0] : ($textcode ? $textcode : "")) { |
159 | 164 | case "|": //Control Tag |
160 | - if ($code == "|snippet") |
|
161 | - $hTag = new Tag\Snippet($text); |
|
162 | - elseif ($code == "|form") |
|
163 | - $hTag = new Tag\Form($text); |
|
164 | - elseif ($code == "|formhint") |
|
165 | - $hTag = new Tag\FormHint(); |
|
166 | - elseif ($code == "|else") { |
|
165 | + if ($code == "|snippet") { |
|
166 | + $hTag = new Tag\Snippet($text); |
|
167 | + } elseif ($code == "|form") { |
|
168 | + $hTag = new Tag\Form($text); |
|
169 | + } elseif ($code == "|formhint") { |
|
170 | + $hTag = new Tag\FormHint(); |
|
171 | + } elseif ($code == "|else") { |
|
167 | 172 | $hTag = new Tag\Control(substr($code, 1), $heir[$i - 1]); |
168 | 173 | $hTag->setVar($text); |
169 | 174 | } else { |
@@ -174,8 +179,9 @@ discard block |
||
174 | 179 | case ":": //Filter Tag |
175 | 180 | $hTag = new Tag\Filter(substr($code, 1)); |
176 | 181 | $hTag->addContent($text, Text::TOKEN_CODE); |
177 | - foreach ($this->consumeBlock($indent) as $l) |
|
178 | - $hTag->addContent($l, Text::TOKEN_CODE); |
|
182 | + foreach ($this->consumeBlock($indent) as $l) { |
|
183 | + $hTag->addContent($l, Text::TOKEN_CODE); |
|
184 | + } |
|
179 | 185 | break; |
180 | 186 | case "_": //String Tag |
181 | 187 | case "__": //Unescape String Tag |
@@ -191,8 +197,9 @@ discard block |
||
191 | 197 | case "//": // Non Printed Comment |
192 | 198 | $hTag = new Tag\Comment($textcode); |
193 | 199 | $hTag->addContent($text); |
194 | - foreach ($this->consumeBlock($indent) as $l) |
|
195 | - $hTag->addContent($l, Text::TOKEN_CODE); |
|
200 | + foreach ($this->consumeBlock($indent) as $l) { |
|
201 | + $hTag->addContent($l, Text::TOKEN_CODE); |
|
202 | + } |
|
196 | 203 | break; |
197 | 204 | default: |
198 | 205 | $attr = array(); |
@@ -204,25 +211,34 @@ discard block |
||
204 | 211 | } |
205 | 212 | $class = array(); $id = ""; $ref = ""; |
206 | 213 | preg_match_all('/[#\.!][a-zA-Z0-9\-\_]+/m', $classid, $cid); |
207 | - if (isset($cid[0])) foreach ($cid[0] as $s) { |
|
214 | + if (isset($cid[0])) { |
|
215 | + foreach ($cid[0] as $s) { |
|
208 | 216 | if ($s[0] == "#") $id = substr($s, 1); |
209 | - if ($s[0] == ".") $class[] = substr($s, 1); |
|
210 | - if ($s[0] == "!") $ref = substr($s, 1); |
|
211 | 217 | } |
212 | - if($ref) |
|
213 | - $hTag = new Tag\DynHtml($tag, $class, $attr, $id, $ref); |
|
214 | - else |
|
215 | - $hTag = new Tag\Html($tag, $class, $attr, $id); |
|
218 | + if ($s[0] == ".") { |
|
219 | + $class[] = substr($s, 1); |
|
220 | + } |
|
221 | + if ($s[0] == "!") { |
|
222 | + $ref = substr($s, 1); |
|
223 | + } |
|
224 | + } |
|
225 | + if($ref) { |
|
226 | + $hTag = new Tag\DynHtml($tag, $class, $attr, $id, $ref); |
|
227 | + } else { |
|
228 | + $hTag = new Tag\Html($tag, $class, $attr, $id); |
|
229 | + } |
|
216 | 230 | $hTag->addContent($text); |
217 | 231 | break; |
218 | 232 | } |
219 | 233 | $heir[$i] = $hTag; |
220 | - if ($i > 0) |
|
221 | - $heir[$i - 1]->addChild($hTag); |
|
222 | - else |
|
223 | - $this->root[] = $hTag; |
|
224 | - } else |
|
225 | - throw new ParseError("Unable to parse line {$this->lineNo}\n\"$line\"/" . preg_last_error()); |
|
234 | + if ($i > 0) { |
|
235 | + $heir[$i - 1]->addChild($hTag); |
|
236 | + } else { |
|
237 | + $this->root[] = $hTag; |
|
238 | + } |
|
239 | + } else { |
|
240 | + throw new ParseError("Unable to parse line {$this->lineNo}\n\"$line\"/" . preg_last_error()); |
|
241 | + } |
|
226 | 242 | $this->lineNo++; |
227 | 243 | } |
228 | 244 | } |
@@ -238,8 +254,9 @@ discard block |
||
238 | 254 | |
239 | 255 | function output($minify = false) { |
240 | 256 | $out = "<?php\nuse Seufert\\Hamle;\n?>"; |
241 | - foreach ($this->root as $tag) |
|
242 | - $out .= $tag->render(0, $minify); |
|
257 | + foreach ($this->root as $tag) { |
|
258 | + $out .= $tag->render(0, $minify); |
|
259 | + } |
|
243 | 260 | return $out; |
244 | 261 | |
245 | 262 | } |
@@ -251,15 +268,18 @@ discard block |
||
251 | 268 | (!trim($this->lines[$this->lineNo + 1]) || |
252 | 269 | preg_match('/^(\s){' . $indent . '}((\s)+[^\s].*)$/', |
253 | 270 | $this->lines[$this->lineNo + 1], $m))) { |
254 | - if (trim($this->lines[$this->lineNo + 1])) |
|
255 | - $out[] = $m[2]; |
|
271 | + if (trim($this->lines[$this->lineNo + 1])) { |
|
272 | + $out[] = $m[2]; |
|
273 | + } |
|
256 | 274 | $this->lineNo++; |
257 | 275 | } |
258 | 276 | return $out; |
259 | 277 | } |
260 | 278 | |
261 | 279 | function indentLevel($indent) { |
262 | - if (!isset($this->indents)) $this->indents = array(); |
|
280 | + if (!isset($this->indents)) { |
|
281 | + $this->indents = array(); |
|
282 | + } |
|
263 | 283 | if (!count($this->indents)) { |
264 | 284 | $this->indents = array(0 => $indent); |
265 | 285 | // Key = indent level, Value = Depth in spaces |
@@ -46,23 +46,23 @@ discard block |
||
46 | 46 | static $filterResolver = null; |
47 | 47 | |
48 | 48 | function __construct($s, Text $what) { |
49 | - if(preg_match("/^([a-z_]+)(?:\\((?P<vars>.*)\\))?(?:\\|(?P<chained>.+?))?$/", $s, $m)) { |
|
49 | + if (preg_match("/^([a-z_]+)(?:\\((?P<vars>.*)\\))?(?:\\|(?P<chained>.+?))?$/", $s, $m)) { |
|
50 | 50 | $this->filter = $m[1]; |
51 | 51 | $this->vars = isset($m['vars']) && strlen($m['vars']) ? explode(',', $m['vars']) : []; |
52 | - foreach($this->vars as $k=>$v) |
|
53 | - $this->vars[$k] = str_replace(",",',',$v); |
|
54 | - if(isset($m['chained']) && strlen($m['chained'])) { |
|
55 | - $this->chained = new Filter($m['chained'],$what); |
|
52 | + foreach ($this->vars as $k=>$v) |
|
53 | + $this->vars[$k] = str_replace(",", ',', $v); |
|
54 | + if (isset($m['chained']) && strlen($m['chained'])) { |
|
55 | + $this->chained = new Filter($m['chained'], $what); |
|
56 | 56 | } |
57 | 57 | } else { |
58 | 58 | throw new ParseError("Unable to parse filter expression \"$s\""); |
59 | 59 | } |
60 | - if(method_exists(Filter::class, $this->filter)) { |
|
60 | + if (method_exists(Filter::class, $this->filter)) { |
|
61 | 61 | $this->filter = Filter::class.'::'.$this->filter; |
62 | - } elseif(in_array($this->filter, ['round', 'strtoupper', 'strtolower', 'ucfirst'])) { |
|
63 | - } elseif($this->filter === 'json') { |
|
62 | + } elseif (in_array($this->filter, ['round', 'strtoupper', 'strtolower', 'ucfirst'])) { |
|
63 | + } elseif ($this->filter === 'json') { |
|
64 | 64 | $this->filter = 'json_encode'; |
65 | - } elseif(self::$filterResolver && $filter = (self::$filterResolver)($this->filter)) { |
|
65 | + } elseif (self::$filterResolver && $filter = (self::$filterResolver)($this->filter)) { |
|
66 | 66 | $this->filter = $filter; |
67 | 67 | } else { |
68 | 68 | throw new ParseError("Unknown Filter Type \"{$this->filter}\""); |
@@ -71,24 +71,24 @@ discard block |
||
71 | 71 | } |
72 | 72 | |
73 | 73 | function toHTML($escape = false) { |
74 | - if($escape) |
|
75 | - return "<?=htmlspecialchars(" .$this->toPHP() . ")?>"; |
|
76 | - return "<?=" . $this->toPHP() . "?>"; |
|
74 | + if ($escape) |
|
75 | + return "<?=htmlspecialchars(".$this->toPHP().")?>"; |
|
76 | + return "<?=".$this->toPHP()."?>"; |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | function toPHPpre() { |
80 | 80 | $pre = ''; |
81 | - if($this->chained) |
|
81 | + if ($this->chained) |
|
82 | 82 | $pre = $this->chained->toPHPpre(); |
83 | 83 | return "$pre{$this->filter}("; |
84 | 84 | } |
85 | 85 | |
86 | 86 | function toPHPpost() { |
87 | 87 | $post = ''; |
88 | - if($this->chained) |
|
88 | + if ($this->chained) |
|
89 | 89 | $post = $this->chained->toPHPpost(); |
90 | 90 | $o = ''; |
91 | - foreach($this->vars as $v) |
|
91 | + foreach ($this->vars as $v) |
|
92 | 92 | $o .= ','.$this->varToCode($v); |
93 | 93 | return "$o)$post"; |
94 | 94 | } |
@@ -103,24 +103,24 @@ discard block |
||
103 | 103 | |
104 | 104 | static function itersplit($v, $sep = ",") { |
105 | 105 | $o = []; |
106 | - foreach(explode($sep, $v) as $k=>$i) { |
|
107 | - if($i) |
|
108 | - $o[] = ['v'=>trim($i), 'value'=>trim($i), 'k'=>$k,'key'=>$k]; |
|
106 | + foreach (explode($sep, $v) as $k=>$i) { |
|
107 | + if ($i) |
|
108 | + $o[] = ['v'=>trim($i), 'value'=>trim($i), 'k'=>$k, 'key'=>$k]; |
|
109 | 109 | } |
110 | 110 | return new WrapArray($o); |
111 | 111 | } |
112 | 112 | |
113 | 113 | static function newlinebr($v) { |
114 | - return str_replace("\n","<br />\n",$v); |
|
114 | + return str_replace("\n", "<br />\n", $v); |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | static function replace($v, $src, $dst) { |
118 | - return str_replace($src,$dst,$v); |
|
118 | + return str_replace($src, $dst, $v); |
|
119 | 119 | } |
120 | 120 | |
121 | 121 | static function ascents($v) { |
122 | - $v = str_replace(['$',' ',','],'', $v); |
|
123 | - return (int) round($v * 100,0); |
|
122 | + $v = str_replace(['$', ' ', ','], '', $v); |
|
123 | + return (int) round($v * 100, 0); |
|
124 | 124 | } |
125 | 125 | |
126 | 126 | } |
@@ -49,8 +49,9 @@ discard block |
||
49 | 49 | if(preg_match("/^([a-z_]+)(?:\\((?P<vars>.*)\\))?(?:\\|(?P<chained>.+?))?$/", $s, $m)) { |
50 | 50 | $this->filter = $m[1]; |
51 | 51 | $this->vars = isset($m['vars']) && strlen($m['vars']) ? explode(',', $m['vars']) : []; |
52 | - foreach($this->vars as $k=>$v) |
|
53 | - $this->vars[$k] = str_replace(",",',',$v); |
|
52 | + foreach($this->vars as $k=>$v) { |
|
53 | + $this->vars[$k] = str_replace(",",',',$v); |
|
54 | + } |
|
54 | 55 | if(isset($m['chained']) && strlen($m['chained'])) { |
55 | 56 | $this->chained = new Filter($m['chained'],$what); |
56 | 57 | } |
@@ -71,25 +72,29 @@ discard block |
||
71 | 72 | } |
72 | 73 | |
73 | 74 | function toHTML($escape = false) { |
74 | - if($escape) |
|
75 | - return "<?=htmlspecialchars(" .$this->toPHP() . ")?>"; |
|
75 | + if($escape) { |
|
76 | + return "<?=htmlspecialchars(" .$this->toPHP() . ")?>"; |
|
77 | + } |
|
76 | 78 | return "<?=" . $this->toPHP() . "?>"; |
77 | 79 | } |
78 | 80 | |
79 | 81 | function toPHPpre() { |
80 | 82 | $pre = ''; |
81 | - if($this->chained) |
|
82 | - $pre = $this->chained->toPHPpre(); |
|
83 | + if($this->chained) { |
|
84 | + $pre = $this->chained->toPHPpre(); |
|
85 | + } |
|
83 | 86 | return "$pre{$this->filter}("; |
84 | 87 | } |
85 | 88 | |
86 | 89 | function toPHPpost() { |
87 | 90 | $post = ''; |
88 | - if($this->chained) |
|
89 | - $post = $this->chained->toPHPpost(); |
|
91 | + if($this->chained) { |
|
92 | + $post = $this->chained->toPHPpost(); |
|
93 | + } |
|
90 | 94 | $o = ''; |
91 | - foreach($this->vars as $v) |
|
92 | - $o .= ','.$this->varToCode($v); |
|
95 | + foreach($this->vars as $v) { |
|
96 | + $o .= ','.$this->varToCode($v); |
|
97 | + } |
|
93 | 98 | return "$o)$post"; |
94 | 99 | } |
95 | 100 | |
@@ -104,8 +109,9 @@ discard block |
||
104 | 109 | static function itersplit($v, $sep = ",") { |
105 | 110 | $o = []; |
106 | 111 | foreach(explode($sep, $v) as $k=>$i) { |
107 | - if($i) |
|
108 | - $o[] = ['v'=>trim($i), 'value'=>trim($i), 'k'=>$k,'key'=>$k]; |
|
112 | + if($i) { |
|
113 | + $o[] = ['v'=>trim($i), 'value'=>trim($i), 'k'=>$k,'key'=>$k]; |
|
114 | + } |
|
109 | 115 | } |
110 | 116 | return new WrapArray($o); |
111 | 117 | } |