@@ -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 |
@@ -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 | } |
@@ -47,23 +47,23 @@ discard block |
||
| 47 | 47 | |
| 48 | 48 | function __construct($s, Text $what) { |
| 49 | 49 | var_dump($s, $what); |
| 50 | - if(preg_match("/^([a-z_]+)(?:\\((?P<vars>.*)\\))?(?:\\|(?P<chained>.+?))?$/", $s, $m)) { |
|
| 50 | + if (preg_match("/^([a-z_]+)(?:\\((?P<vars>.*)\\))?(?:\\|(?P<chained>.+?))?$/", $s, $m)) { |
|
| 51 | 51 | $this->filter = $m[1]; |
| 52 | 52 | $this->vars = isset($m['vars']) && strlen($m['vars']) ? explode(',', $m['vars']) : []; |
| 53 | - foreach($this->vars as $k=>$v) |
|
| 54 | - $this->vars[$k] = str_replace(",",',',$v); |
|
| 55 | - if(isset($m['chained']) && strlen($m['chained'])) { |
|
| 56 | - $this->chained = new Filter($m['chained'],$what); |
|
| 53 | + foreach ($this->vars as $k=>$v) |
|
| 54 | + $this->vars[$k] = str_replace(",", ',', $v); |
|
| 55 | + if (isset($m['chained']) && strlen($m['chained'])) { |
|
| 56 | + $this->chained = new Filter($m['chained'], $what); |
|
| 57 | 57 | } |
| 58 | 58 | } else { |
| 59 | 59 | throw new ParseError("Unable to parse filter expression \"$s\""); |
| 60 | 60 | } |
| 61 | - if(method_exists(Filter::class, $this->filter)) { |
|
| 61 | + if (method_exists(Filter::class, $this->filter)) { |
|
| 62 | 62 | $this->filter = Filter::class.'::'.$this->filter; |
| 63 | - } elseif(in_array($this->filter, ['round', 'strtoupper', 'strtolower', 'ucfirst'])) { |
|
| 64 | - } elseif($this->filter === 'json') { |
|
| 63 | + } elseif (in_array($this->filter, ['round', 'strtoupper', 'strtolower', 'ucfirst'])) { |
|
| 64 | + } elseif ($this->filter === 'json') { |
|
| 65 | 65 | $this->filter = 'json_encode'; |
| 66 | - } elseif(self::$filterResolver && $filter = (self::$filterResolver)($this->filter)) { |
|
| 66 | + } elseif (self::$filterResolver && $filter = (self::$filterResolver)($this->filter)) { |
|
| 67 | 67 | $this->filter = $filter; |
| 68 | 68 | } else { |
| 69 | 69 | throw new ParseError("Unknown Filter Type \"{$this->filter}\""); |
@@ -72,24 +72,24 @@ discard block |
||
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | function toHTML($escape = false) { |
| 75 | - if($escape) |
|
| 76 | - return "<?=htmlspecialchars(" .$this->toPHP() . ")?>"; |
|
| 77 | - return "<?=" . $this->toPHP() . "?>"; |
|
| 75 | + if ($escape) |
|
| 76 | + return "<?=htmlspecialchars(".$this->toPHP().")?>"; |
|
| 77 | + return "<?=".$this->toPHP()."?>"; |
|
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | function toPHPpre() { |
| 81 | 81 | $pre = ''; |
| 82 | - if($this->chained) |
|
| 82 | + if ($this->chained) |
|
| 83 | 83 | $pre = $this->chained->toPHPpre(); |
| 84 | 84 | return "$pre{$this->filter}("; |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | function toPHPpost() { |
| 88 | 88 | $post = ''; |
| 89 | - if($this->chained) |
|
| 89 | + if ($this->chained) |
|
| 90 | 90 | $post = $this->chained->toPHPpost(); |
| 91 | 91 | $o = ''; |
| 92 | - foreach($this->vars as $v) |
|
| 92 | + foreach ($this->vars as $v) |
|
| 93 | 93 | $o .= ','.$this->varToCode($v); |
| 94 | 94 | return "$o)$post"; |
| 95 | 95 | } |
@@ -104,24 +104,24 @@ discard block |
||
| 104 | 104 | |
| 105 | 105 | static function itersplit($v, $sep = ",") { |
| 106 | 106 | $o = []; |
| 107 | - foreach(explode($sep, $v) as $k=>$i) { |
|
| 108 | - if($i) |
|
| 109 | - $o[] = ['v'=>trim($i), 'value'=>trim($i), 'k'=>$k,'key'=>$k]; |
|
| 107 | + foreach (explode($sep, $v) as $k=>$i) { |
|
| 108 | + if ($i) |
|
| 109 | + $o[] = ['v'=>trim($i), 'value'=>trim($i), 'k'=>$k, 'key'=>$k]; |
|
| 110 | 110 | } |
| 111 | 111 | return new WrapArray($o); |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | static function newlinebr($v) { |
| 115 | - return str_replace("\n","<br />\n",$v); |
|
| 115 | + return str_replace("\n", "<br />\n", $v); |
|
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | static function replace($v, $src, $dst) { |
| 119 | - return str_replace($src,$dst,$v); |
|
| 119 | + return str_replace($src, $dst, $v); |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | static function ascents($v) { |
| 123 | - $v = str_replace(['$',' ',','],'', $v); |
|
| 124 | - return (int) round($v * 100,0); |
|
| 123 | + $v = str_replace(['$', ' ', ','], '', $v); |
|
| 124 | + return (int) round($v * 100, 0); |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | } |
@@ -112,16 +112,16 @@ discard block |
||
| 112 | 112 | |
| 113 | 113 | function getValue() { |
| 114 | 114 | if (!is_null($this->setValue)) return $this->setValue; |
| 115 | - if (isset($_REQUEST[$this->form . "_" . $this->name])) { |
|
| 116 | - return $_REQUEST[$this->form . "_" . $this->name]; |
|
| 115 | + if (isset($_REQUEST[$this->form."_".$this->name])) { |
|
| 116 | + return $_REQUEST[$this->form."_".$this->name]; |
|
| 117 | 117 | } |
| 118 | 118 | return $this->opt['default']; |
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | function getInputAttStatic(&$atts, &$type, &$content) { |
| 122 | - $atts['id'] = $atts['name'] = $this->form . "_" . $this->name; |
|
| 122 | + $atts['id'] = $atts['name'] = $this->form."_".$this->name; |
|
| 123 | 123 | $atts['type'] = "text"; |
| 124 | - $atts['class'][] = str_replace(['Seufert\\','\\'],['','_'],get_class($this)); |
|
| 124 | + $atts['class'][] = str_replace(['Seufert\\', '\\'], ['', '_'], get_class($this)); |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | function getInputAttDynamic(&$atts, &$type, &$content) { |
@@ -139,8 +139,8 @@ discard block |
||
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | function getLabelAttStatic(&$atts, &$type, &$content) { |
| 142 | - $atts['class'][] = str_replace(['Seufert\\','\\'],['','_'],get_class($this)); |
|
| 143 | - $atts["for"] = $this->form . "_" . $this->name; |
|
| 142 | + $atts['class'][] = str_replace(['Seufert\\', '\\'], ['', '_'], get_class($this)); |
|
| 143 | + $atts["for"] = $this->form."_".$this->name; |
|
| 144 | 144 | $content = array($this->opt['label']); |
| 145 | 145 | } |
| 146 | 146 | |
@@ -148,7 +148,7 @@ discard block |
||
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | function getHintAttStatic(&$atts, &$type, &$content) { |
| 151 | - $atts['class'][] = str_replace(['Seufert\\','\\'],['','_'],get_class($this)); |
|
| 151 | + $atts['class'][] = str_replace(['Seufert\\', '\\'], ['', '_'], get_class($this)); |
|
| 152 | 152 | $atts['class'][] = "hamleFormHint"; |
| 153 | 153 | } |
| 154 | 154 | |
@@ -66,7 +66,9 @@ discard block |
||
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | function __call($name, $valarray) { |
| 69 | - if (count($valarray) < 1) return $this->__get($name); |
|
| 69 | + if (count($valarray) < 1) { |
|
| 70 | + return $this->__get($name); |
|
| 71 | + } |
|
| 70 | 72 | $val = count($valarray) == 1 ? current($valarray) : $valarray; |
| 71 | 73 | switch ($name) { |
| 72 | 74 | case "name": |
@@ -111,7 +113,9 @@ discard block |
||
| 111 | 113 | } |
| 112 | 114 | |
| 113 | 115 | function getValue() { |
| 114 | - if (!is_null($this->setValue)) return $this->setValue; |
|
| 116 | + if (!is_null($this->setValue)) { |
|
| 117 | + return $this->setValue; |
|
| 118 | + } |
|
| 115 | 119 | if (isset($_REQUEST[$this->form . "_" . $this->name])) { |
| 116 | 120 | return $_REQUEST[$this->form . "_" . $this->name]; |
| 117 | 121 | } |
@@ -130,12 +134,15 @@ discard block |
||
| 130 | 134 | if (!$this->valid) { |
| 131 | 135 | $atts['class'][] = "hamleFormError"; |
| 132 | 136 | } |
| 133 | - if ($this->opt["disabled"]) |
|
| 134 | - $atts['disabled'] = "disabled"; |
|
| 135 | - if ($this->opt['required']) |
|
| 136 | - $atts['required'] = "required"; |
|
| 137 | - if ($this->opt['help']) |
|
| 138 | - $atts['title'] = $this->opt['help']; |
|
| 137 | + if ($this->opt["disabled"]) { |
|
| 138 | + $atts['disabled'] = "disabled"; |
|
| 139 | + } |
|
| 140 | + if ($this->opt['required']) { |
|
| 141 | + $atts['required'] = "required"; |
|
| 142 | + } |
|
| 143 | + if ($this->opt['help']) { |
|
| 144 | + $atts['title'] = $this->opt['help']; |
|
| 145 | + } |
|
| 139 | 146 | } |
| 140 | 147 | |
| 141 | 148 | function getLabelAttStatic(&$atts, &$type, &$content) { |
@@ -173,10 +180,12 @@ discard block |
||
| 173 | 180 | function doProcess($submit) { |
| 174 | 181 | if ($submit) { |
| 175 | 182 | $value = $this->getValue(); |
| 176 | - if ($this->opt['required']) |
|
| 177 | - $this->valid = $this->valid && strlen($value); |
|
| 178 | - if ($this->opt['regex']) |
|
| 179 | - $this->valid = $this->valid && preg_match($this->opt['regex'], $value); |
|
| 183 | + if ($this->opt['required']) { |
|
| 184 | + $this->valid = $this->valid && strlen($value); |
|
| 185 | + } |
|
| 186 | + if ($this->opt['regex']) { |
|
| 187 | + $this->valid = $this->valid && preg_match($this->opt['regex'], $value); |
|
| 188 | + } |
|
| 180 | 189 | } |
| 181 | 190 | } |
| 182 | 191 | |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | const FIND_DOLLARVAR = 0x02; |
| 52 | 52 | const FIND_BARDOLLAR = 0x04; |
| 53 | 53 | |
| 54 | - const START_RULE_MAP = [self::TOKEN_HTML => 'HtmlInput', self::TOKEN_CODE => 'CodeInput',self::TOKEN_CONTROL => 'ControlInput']; |
|
| 54 | + const START_RULE_MAP = [self::TOKEN_HTML => 'HtmlInput', self::TOKEN_CODE => 'CodeInput', self::TOKEN_CONTROL => 'ControlInput']; |
|
| 55 | 55 | |
| 56 | 56 | protected $mode; |
| 57 | 57 | |
@@ -61,9 +61,9 @@ discard block |
||
| 61 | 61 | { |
| 62 | 62 | // var_dump($s); |
| 63 | 63 | $this->mode = $mode; |
| 64 | - $this->tree = (new Parser())->parse($s,['startRule' => self::START_RULE_MAP[$mode]]); |
|
| 64 | + $this->tree = (new Parser())->parse($s, ['startRule' => self::START_RULE_MAP[$mode]]); |
|
| 65 | 65 | // var_dump($this->tree); |
| 66 | - if(!$this->tree instanceof Doc) { |
|
| 66 | + if (!$this->tree instanceof Doc) { |
|
| 67 | 67 | $this->tree = new Doc(is_array($this->tree) ? $this->tree : [$this->tree]); |
| 68 | 68 | } |
| 69 | 69 | // $m = []; |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | { |
| 115 | 115 | $func = $filter['func']; |
| 116 | 116 | if (method_exists(Filter::class, $func)) { |
| 117 | - $func = Filter::class . '::' . $func; |
|
| 117 | + $func = Filter::class.'::'.$func; |
|
| 118 | 118 | } elseif (in_array($func, ['round', 'strtoupper', 'strtolower', 'ucfirst'])) { |
| 119 | 119 | } elseif ($func === 'json') { |
| 120 | 120 | $func = 'json_encode'; |
@@ -124,14 +124,14 @@ discard block |
||
| 124 | 124 | throw new ParseError("Unknown Filter Type \"{$func}\""); |
| 125 | 125 | } |
| 126 | 126 | $args = join(',', array_map(function($v) { |
| 127 | - if(is_array($v) && $v['type'] ?? false === 'expr') { |
|
| 127 | + if (is_array($v) && $v['type'] ?? false === 'expr') { |
|
| 128 | 128 | return self::renderExpr($v); |
| 129 | 129 | } else |
| 130 | 130 | return self::varToCode($v); |
| 131 | 131 | } , $filter['args'])); |
| 132 | - if(strlen($args)) $args = ','.$args; |
|
| 133 | - $o = "$func($o" . $args . ")"; |
|
| 134 | - if($filter['chain'] ?? false) { |
|
| 132 | + if (strlen($args)) $args = ','.$args; |
|
| 133 | + $o = "$func($o".$args.")"; |
|
| 134 | + if ($filter['chain'] ?? false) { |
|
| 135 | 135 | $o = self::addFilter($o, $filter['chain']); |
| 136 | 136 | } |
| 137 | 137 | return $o; |
@@ -139,21 +139,21 @@ discard block |
||
| 139 | 139 | |
| 140 | 140 | static function renderScopeThis($n) |
| 141 | 141 | { |
| 142 | - $o = 'Hamle\Scope::get()->hamleGet(' . self::varToCode($n['name']) . ')'; |
|
| 142 | + $o = 'Hamle\Scope::get()->hamleGet('.self::varToCode($n['name']).')'; |
|
| 143 | 143 | $o = self::addParams($o, $n['param'] ?? []); |
| 144 | 144 | return $o; |
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | static function renderScopeId($n) |
| 148 | 148 | { |
| 149 | - $o = 'Hamle\Scope::get(' . $n['id'] . ')'; |
|
| 149 | + $o = 'Hamle\Scope::get('.$n['id'].')'; |
|
| 150 | 150 | $o = self::addParams($o, $n['param'] ?? []); |
| 151 | 151 | return $o; |
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | static function renderScopeName($n) |
| 155 | 155 | { |
| 156 | - $o = 'Hamle\Scope::getName(' . self::varToCode($n['name']) . ')'; |
|
| 156 | + $o = 'Hamle\Scope::getName('.self::varToCode($n['name']).')'; |
|
| 157 | 157 | $o = self::addParams($o, $n['param'] ?? []); |
| 158 | 158 | return $o; |
| 159 | 159 | } |
@@ -161,7 +161,7 @@ discard block |
||
| 161 | 161 | static function addParams(string $o, array $params) |
| 162 | 162 | { |
| 163 | 163 | while ($params['type'] ?? null === 'sub') { |
| 164 | - $o .= '->hamleGet(' . self::varToCode($params['name']) . ')'; |
|
| 164 | + $o .= '->hamleGet('.self::varToCode($params['name']).')'; |
|
| 165 | 165 | $params = $params['params'] ?? []; |
| 166 | 166 | } |
| 167 | 167 | return $o; |
@@ -170,7 +170,7 @@ discard block |
||
| 170 | 170 | static function addRel(string $o, array $query, string $rel): string |
| 171 | 171 | { |
| 172 | 172 | $r = $rel === 'child' ? Hamle::REL_CHILD : Hamle::REL_PARENT; |
| 173 | - $o = $o . "->hamleRel(" . self::varToCode($r) . ',' . self::queryParams($query, true) . ')'; |
|
| 173 | + $o = $o."->hamleRel(".self::varToCode($r).','.self::queryParams($query, true).')'; |
|
| 174 | 174 | return $o; |
| 175 | 175 | } |
| 176 | 176 | |
@@ -230,7 +230,7 @@ discard block |
||
| 230 | 230 | self::varToCode($limit), |
| 231 | 231 | self::varToCode($offset) |
| 232 | 232 | ]; |
| 233 | - return 'Hamle\Run::modelTypeId(' . join(',', $opt) . ')'; |
|
| 233 | + return 'Hamle\Run::modelTypeId('.join(',', $opt).')'; |
|
| 234 | 234 | } |
| 235 | 235 | |
| 236 | 236 | static function renderQuery($n) |
@@ -249,7 +249,7 @@ discard block |
||
| 249 | 249 | } elseif ($id !== null) { |
| 250 | 250 | $o = self::queryId($n['query']); |
| 251 | 251 | } else { |
| 252 | - $o = 'Hamle\Run::modelTypeTags(' . self::queryParams($n['query']) . ')'; |
|
| 252 | + $o = 'Hamle\Run::modelTypeTags('.self::queryParams($n['query']).')'; |
|
| 253 | 253 | } |
| 254 | 254 | if ($n['sub'] ?? []) { |
| 255 | 255 | $o = self::addRel($o, $n['sub'], $n['rel']); |
@@ -276,7 +276,7 @@ discard block |
||
| 276 | 276 | $o = self::renderQuery($expr['body']); |
| 277 | 277 | break; |
| 278 | 278 | default: |
| 279 | - throw new \RuntimeException('Invalid Node: ' . $expr['body']['type']); |
|
| 279 | + throw new \RuntimeException('Invalid Node: '.$expr['body']['type']); |
|
| 280 | 280 | } |
| 281 | 281 | if ($expr['body']['filter'] ?? false) { |
| 282 | 282 | $o = self::addFilter($o, $expr['body']['filter']); |
@@ -295,16 +295,16 @@ discard block |
||
| 295 | 295 | $out .= $node['body']; |
| 296 | 296 | break; |
| 297 | 297 | case 'scopeName': |
| 298 | - $out .= '<?=' . self::renderScopeName($node) . '?>'; |
|
| 298 | + $out .= '<?='.self::renderScopeName($node).'?>'; |
|
| 299 | 299 | break; |
| 300 | 300 | case 'scopeThis': |
| 301 | - $out .= '<?=' . self::renderScopeThis($node) . '?>'; |
|
| 301 | + $out .= '<?='.self::renderScopeThis($node).'?>'; |
|
| 302 | 302 | break; |
| 303 | 303 | case 'expr': |
| 304 | - $out .= '<?=' . self::renderExpr($node) . "?>"; |
|
| 304 | + $out .= '<?='.self::renderExpr($node)."?>"; |
|
| 305 | 305 | break; |
| 306 | 306 | default: |
| 307 | - throw new \RuntimeException('Invalid Node:' . $node['type']); |
|
| 307 | + throw new \RuntimeException('Invalid Node:'.$node['type']); |
|
| 308 | 308 | } |
| 309 | 309 | } |
| 310 | 310 | return $out; |
@@ -332,7 +332,7 @@ discard block |
||
| 332 | 332 | $out [] = self::renderExpr($node); |
| 333 | 333 | break; |
| 334 | 334 | default: |
| 335 | - throw new \RuntimeException('Invalid Node:' . $node['type']); |
|
| 335 | + throw new \RuntimeException('Invalid Node:'.$node['type']); |
|
| 336 | 336 | } |
| 337 | 337 | } |
| 338 | 338 | return join('.', $out); |
@@ -340,7 +340,7 @@ discard block |
||
| 340 | 340 | |
| 341 | 341 | function doEval() |
| 342 | 342 | { |
| 343 | - return eval('use Seufert\Hamle; return ' . $this->toPHP() . ';'); |
|
| 343 | + return eval('use Seufert\Hamle; return '.$this->toPHP().';'); |
|
| 344 | 344 | } |
| 345 | 345 | |
| 346 | 346 | static function varToCode($var) |
@@ -348,9 +348,9 @@ discard block |
||
| 348 | 348 | if (is_array($var)) { |
| 349 | 349 | $code = []; |
| 350 | 350 | foreach ($var as $key => $value) { |
| 351 | - $code[] = self::varToCode($key) . '=>' . self::varToCode($value); |
|
| 351 | + $code[] = self::varToCode($key).'=>'.self::varToCode($value); |
|
| 352 | 352 | } |
| 353 | - return 'array(' . implode(',', $code) . ')'; //remove unnecessary coma |
|
| 353 | + return 'array('.implode(',', $code).')'; //remove unnecessary coma |
|
| 354 | 354 | } |
| 355 | 355 | if (is_bool($var)) { |
| 356 | 356 | return ($var ? 'TRUE' : 'FALSE'); |
@@ -361,7 +361,7 @@ discard block |
||
| 361 | 361 | if ($var instanceof Text) { |
| 362 | 362 | return $var->toPHP(); |
| 363 | 363 | } |
| 364 | - return "'" . str_replace(['$', "'"], ['$', "\\'"], $var) . "'"; |
|
| 364 | + return "'".str_replace(['$', "'"], ['$', "\\'"], $var)."'"; |
|
| 365 | 365 | } |
| 366 | 366 | |
| 367 | 367 | /** |
@@ -126,10 +126,13 @@ discard block |
||
| 126 | 126 | $args = join(',', array_map(function($v) { |
| 127 | 127 | if(is_array($v) && $v['type'] ?? false === 'expr') { |
| 128 | 128 | return self::renderExpr($v); |
| 129 | - } else |
|
| 130 | - return self::varToCode($v); |
|
| 129 | + } else { |
|
| 130 | + return self::varToCode($v); |
|
| 131 | + } |
|
| 131 | 132 | } , $filter['args'])); |
| 132 | - if(strlen($args)) $args = ','.$args; |
|
| 133 | + if(strlen($args)) { |
|
| 134 | + $args = ','.$args; |
|
| 135 | + } |
|
| 133 | 136 | $o = "$func($o" . $args . ")"; |
| 134 | 137 | if($filter['chain'] ?? false) { |
| 135 | 138 | $o = self::addFilter($o, $filter['chain']); |
@@ -202,8 +205,9 @@ discard block |
||
| 202 | 205 | self::varToCode($limit), |
| 203 | 206 | self::varToCode($offset) |
| 204 | 207 | ]; |
| 205 | - if ($addGroup) |
|
| 206 | - $opt[] = self::varToCode($group); |
|
| 208 | + if ($addGroup) { |
|
| 209 | + $opt[] = self::varToCode($group); |
|
| 210 | + } |
|
| 207 | 211 | return join(',', $opt); |
| 208 | 212 | } |
| 209 | 213 | |
@@ -239,10 +243,12 @@ discard block |
||
| 239 | 243 | $id = null; |
| 240 | 244 | $type = []; |
| 241 | 245 | foreach ($n['query'] ?? [] as $q) { |
| 242 | - if ($q['q'] === 'id') |
|
| 243 | - $id = $q['id'] ?? null; |
|
| 244 | - if ($q['q'] === 'type') |
|
| 245 | - $type = $q['id']; |
|
| 246 | + if ($q['q'] === 'id') { |
|
| 247 | + $id = $q['id'] ?? null; |
|
| 248 | + } |
|
| 249 | + if ($q['q'] === 'type') { |
|
| 250 | + $type = $q['id']; |
|
| 251 | + } |
|
| 246 | 252 | } |
| 247 | 253 | if ($n['query'] === null) { |
| 248 | 254 | $o = 'Hamle\Scope::get(0)'; |
@@ -291,8 +297,9 @@ discard block |
||
| 291 | 297 | foreach ($this->tree as $node) { |
| 292 | 298 | switch ($node['type']) { |
| 293 | 299 | case 'string': |
| 294 | - if ($node['body'] !== '') |
|
| 295 | - $out .= $node['body']; |
|
| 300 | + if ($node['body'] !== '') { |
|
| 301 | + $out .= $node['body']; |
|
| 302 | + } |
|
| 296 | 303 | break; |
| 297 | 304 | case 'scopeName': |
| 298 | 305 | $out .= '<?=' . self::renderScopeName($node) . '?>'; |
@@ -322,8 +329,9 @@ discard block |
||
| 322 | 329 | foreach ($this->tree as $node) { |
| 323 | 330 | switch ($node['type']) { |
| 324 | 331 | case 'string': |
| 325 | - if ($node['body'] !== '') |
|
| 326 | - $out[] = self::varToCode($node['body']); |
|
| 332 | + if ($node['body'] !== '') { |
|
| 333 | + $out[] = self::varToCode($node['body']); |
|
| 334 | + } |
|
| 327 | 335 | break; |
| 328 | 336 | case 'scopeThis': |
| 329 | 337 | $out[] = self::renderScopeThis($node); |
@@ -30,9 +30,9 @@ |
||
| 30 | 30 | |
| 31 | 31 | |
| 32 | 32 | public function toPHP():string { |
| 33 | - $o = "Hamle\\Scope::getName(" . Text::varToCode($this->name) . ")"; |
|
| 33 | + $o = "Hamle\\Scope::getName(".Text::varToCode($this->name).")"; |
|
| 34 | 34 | if ($this->immediate) $o = $this->immediate->apply($o); |
| 35 | - if($this->chain) $o = $this->chain->apply($o); |
|
| 35 | + if ($this->chain) $o = $this->chain->apply($o); |
|
| 36 | 36 | return $o; |
| 37 | 37 | } |
| 38 | 38 | |
@@ -31,8 +31,12 @@ |
||
| 31 | 31 | |
| 32 | 32 | public function toPHP():string { |
| 33 | 33 | $o = "Hamle\\Scope::getName(" . Text::varToCode($this->name) . ")"; |
| 34 | - if ($this->immediate) $o = $this->immediate->apply($o); |
|
| 35 | - if($this->chain) $o = $this->chain->apply($o); |
|
| 34 | + if ($this->immediate) { |
|
| 35 | + $o = $this->immediate->apply($o); |
|
| 36 | + } |
|
| 37 | + if($this->chain) { |
|
| 38 | + $o = $this->chain->apply($o); |
|
| 39 | + } |
|
| 36 | 40 | return $o; |
| 37 | 41 | } |
| 38 | 42 | |
@@ -23,8 +23,8 @@ |
||
| 23 | 23 | |
| 24 | 24 | public function apply(string $out): string |
| 25 | 25 | { |
| 26 | - $o = "{$out}->hamleGet(" . Text::varToCode($this->name) . ")"; |
|
| 27 | - if($this->chain) |
|
| 26 | + $o = "{$out}->hamleGet(".Text::varToCode($this->name).")"; |
|
| 27 | + if ($this->chain) |
|
| 28 | 28 | $o = $this->chain->apply($o); |
| 29 | 29 | return $o; |
| 30 | 30 | } |
@@ -24,8 +24,9 @@ |
||
| 24 | 24 | public function apply(string $out): string |
| 25 | 25 | { |
| 26 | 26 | $o = "{$out}->hamleGet(" . Text::varToCode($this->name) . ")"; |
| 27 | - if($this->chain) |
|
| 28 | - $o = $this->chain->apply($o); |
|
| 27 | + if($this->chain) { |
|
| 28 | + $o = $this->chain->apply($o); |
|
| 29 | + } |
|
| 29 | 30 | return $o; |
| 30 | 31 | } |
| 31 | 32 | } |
@@ -15,6 +15,6 @@ |
||
| 15 | 15 | |
| 16 | 16 | public function string(): string |
| 17 | 17 | { |
| 18 | - return (string)$this->int; |
|
| 18 | + return (string) $this->int; |
|
| 19 | 19 | } |
| 20 | 20 | } |
@@ -22,7 +22,7 @@ discard block |
||
| 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 (in_array($func, ['round', 'strtoupper', 'strtolower', 'ucfirst'])) { |
| 27 | 27 | $this->func = $func; |
| 28 | 28 | } elseif ($func === 'json') { |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | { |
| 39 | 39 | $args = array_map(fn($v) => $v instanceof Literal ? Text::varToCode($v->string()) : $v->toPHP(), $this->args); |
| 40 | 40 | array_unshift($args, $out); |
| 41 | - $o = "{$this->func}(" . join(',', $args) . ")"; |
|
| 41 | + $o = "{$this->func}(".join(',', $args).")"; |
|
| 42 | 42 | if ($this->chain) $o = $this->chain->apply($o); |
| 43 | 43 | return $o; |
| 44 | 44 | } |
@@ -39,7 +39,9 @@ |
||
| 39 | 39 | $args = array_map(fn($v) => $v instanceof Literal ? Text::varToCode($v->string()) : $v->toPHP(), $this->args); |
| 40 | 40 | array_unshift($args, $out); |
| 41 | 41 | $o = "{$this->func}(" . join(',', $args) . ")"; |
| 42 | - if ($this->chain) $o = $this->chain->apply($o); |
|
| 42 | + if ($this->chain) { |
|
| 43 | + $o = $this->chain->apply($o); |
|
| 44 | + } |
|
| 43 | 45 | return $o; |
| 44 | 46 | } |
| 45 | 47 | } |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | return join('.', $out); |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | - public function toHtml(bool $escVar = false,bool $escFixed = true): string |
|
| 38 | + public function toHtml(bool $escVar = false, bool $escFixed = true): string |
|
| 39 | 39 | { |
| 40 | 40 | $out = []; |
| 41 | 41 | if ($escVar) { |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | $code = false; |
| 54 | 54 | } |
| 55 | 55 | $s = $n->string(); |
| 56 | - if($escFixed) $s = htmlspecialchars($s); |
|
| 56 | + if ($escFixed) $s = htmlspecialchars($s); |
|
| 57 | 57 | $out[] = $s; |
| 58 | 58 | } else { |
| 59 | 59 | if (!$code) { |
@@ -53,7 +53,9 @@ discard block |
||
| 53 | 53 | $code = false; |
| 54 | 54 | } |
| 55 | 55 | $s = $n->string(); |
| 56 | - if($escFixed) $s = htmlspecialchars($s); |
|
| 56 | + if($escFixed) { |
|
| 57 | + $s = htmlspecialchars($s); |
|
| 58 | + } |
|
| 57 | 59 | $out[] = $s; |
| 58 | 60 | } else { |
| 59 | 61 | if (!$code) { |
@@ -63,7 +65,9 @@ discard block |
||
| 63 | 65 | $out[] = $n->toPHP(); |
| 64 | 66 | } |
| 65 | 67 | } |
| 66 | - if ($code) $out[] = $closeTag; |
|
| 68 | + if ($code) { |
|
| 69 | + $out[] = $closeTag; |
|
| 70 | + } |
|
| 67 | 71 | return join('', $out); |
| 68 | 72 | } |
| 69 | 73 | } |