@@ -43,6 +43,6 @@ |
||
| 43 | 43 | |
| 44 | 44 | static function filterText($s) |
| 45 | 45 | { |
| 46 | - return "/*<![CDATA[*/\n" . $s . '/*]]>*/'; |
|
| 46 | + return "/*<![CDATA[*/\n".$s.'/*]]>*/'; |
|
| 47 | 47 | } |
| 48 | 48 | } |
@@ -54,281 +54,3 @@ |
||
| 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 | - $attr = $this->parseQueryString($param); |
|
| 227 | - } |
|
| 228 | - $class = []; |
|
| 229 | - $id = ''; |
|
| 230 | - $ref = ''; |
|
| 231 | - preg_match_all('/[#\.!][a-zA-Z0-9\-\_]+/m', $classid, $cid); |
|
| 232 | - if (isset($cid[0])) { |
|
| 233 | - foreach ($cid[0] as $s) { |
|
| 234 | - if ($s[0] == '#') { |
|
| 235 | - $id = substr($s, 1); |
|
| 236 | - } |
|
| 237 | - if ($s[0] == '.') { |
|
| 238 | - $class[] = substr($s, 1); |
|
| 239 | - } |
|
| 240 | - if ($s[0] == '!') { |
|
| 241 | - $ref = substr($s, 1); |
|
| 242 | - } |
|
| 243 | - } |
|
| 244 | - } |
|
| 245 | - if ($ref) { |
|
| 246 | - $hTag = new Tag\DynHtml($tag, $class, $attr, $id, $ref); |
|
| 247 | - } else { |
|
| 248 | - $hTag = new Tag\Html($tag, $class, $attr, $id); |
|
| 249 | - } |
|
| 250 | - $hTag->addContent($text); |
|
| 251 | - break; |
|
| 252 | - } |
|
| 253 | - $heir[$i] = $hTag; |
|
| 254 | - if ($i > 0) { |
|
| 255 | - $heir[$i - 1]->addChild($hTag); |
|
| 256 | - } else { |
|
| 257 | - $this->root[] = $hTag; |
|
| 258 | - } |
|
| 259 | - } else { |
|
| 260 | - throw new ParseError( |
|
| 261 | - "Unable to parse line {$this->lineNo}\n\"$line\"/" . |
|
| 262 | - preg_last_error(), |
|
| 263 | - ); |
|
| 264 | - } |
|
| 265 | - } |
|
| 266 | - $this->lineNo++; |
|
| 267 | - } |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - function parseQueryString($qs) |
|
| 271 | - { |
|
| 272 | - $out = []; |
|
| 273 | - foreach (explode('&', $qs) as $s) { |
|
| 274 | - $kv = explode('=', $s, 2); |
|
| 275 | - $out[urldecode($kv[0])] = isset($kv[1]) ? urldecode($kv[1]) : null; |
|
| 276 | - } |
|
| 277 | - return $out; |
|
| 278 | - } |
|
| 279 | - |
|
| 280 | - function output($minify = false) |
|
| 281 | - { |
|
| 282 | - $out = "<?php\nuse Seufert\\Hamle;\n?>"; |
|
| 283 | - foreach ($this->root as $tag) { |
|
| 284 | - $out .= $tag->render(0, $minify); |
|
| 285 | - } |
|
| 286 | - return $out; |
|
| 287 | - } |
|
| 288 | - |
|
| 289 | - function consumeBlock($indent) |
|
| 290 | - { |
|
| 291 | - $out = []; |
|
| 292 | - $m = []; |
|
| 293 | - while ( |
|
| 294 | - $this->lineNo + 1 < $this->lineCount && |
|
| 295 | - (!trim($this->lines[$this->lineNo + 1]) || |
|
| 296 | - preg_match( |
|
| 297 | - '/^(\s){' . $indent . '}((\s)+[^\s].*)$/', |
|
| 298 | - $this->lines[$this->lineNo + 1], |
|
| 299 | - $m, |
|
| 300 | - )) |
|
| 301 | - ) { |
|
| 302 | - if (trim($this->lines[$this->lineNo + 1])) { |
|
| 303 | - $out[] = $m[2]; |
|
| 304 | - } |
|
| 305 | - $this->lineNo++; |
|
| 306 | - } |
|
| 307 | - return $out; |
|
| 308 | - } |
|
| 309 | - |
|
| 310 | - function indentLevel($indent) |
|
| 311 | - { |
|
| 312 | - if (!isset($this->indents)) { |
|
| 313 | - $this->indents = []; |
|
| 314 | - } |
|
| 315 | - if (!count($this->indents)) { |
|
| 316 | - $this->indents = [0 => $indent]; |
|
| 317 | - // Key = indent level, Value = Depth in spaces |
|
| 318 | - return 0; |
|
| 319 | - } |
|
| 320 | - foreach ($this->indents as $k => $v) { |
|
| 321 | - if ($v == $indent) { |
|
| 322 | - $this->indents = array_slice($this->indents, 0, $k + 1); |
|
| 323 | - return $k; |
|
| 324 | - } |
|
| 325 | - } |
|
| 326 | - $this->indents[] = $indent; |
|
| 327 | - return max(array_keys($this->indents)); |
|
| 328 | - } |
|
| 329 | - |
|
| 330 | - function getLineNo() |
|
| 331 | - { |
|
| 332 | - return $this->lineNo; |
|
| 333 | - } |
|
| 334 | -} |
|
@@ -54,281 +54,3 @@ |
||
| 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 | - $attr = $this->parseQueryString($param); |
|
| 227 | - } |
|
| 228 | - $class = []; |
|
| 229 | - $id = ''; |
|
| 230 | - $ref = ''; |
|
| 231 | - preg_match_all('/[#\.!][a-zA-Z0-9\-\_]+/m', $classid, $cid); |
|
| 232 | - if (isset($cid[0])) { |
|
| 233 | - foreach ($cid[0] as $s) { |
|
| 234 | - if ($s[0] == '#') { |
|
| 235 | - $id = substr($s, 1); |
|
| 236 | - } |
|
| 237 | - if ($s[0] == '.') { |
|
| 238 | - $class[] = substr($s, 1); |
|
| 239 | - } |
|
| 240 | - if ($s[0] == '!') { |
|
| 241 | - $ref = substr($s, 1); |
|
| 242 | - } |
|
| 243 | - } |
|
| 244 | - } |
|
| 245 | - if ($ref) { |
|
| 246 | - $hTag = new Tag\DynHtml($tag, $class, $attr, $id, $ref); |
|
| 247 | - } else { |
|
| 248 | - $hTag = new Tag\Html($tag, $class, $attr, $id); |
|
| 249 | - } |
|
| 250 | - $hTag->addContent($text); |
|
| 251 | - break; |
|
| 252 | - } |
|
| 253 | - $heir[$i] = $hTag; |
|
| 254 | - if ($i > 0) { |
|
| 255 | - $heir[$i - 1]->addChild($hTag); |
|
| 256 | - } else { |
|
| 257 | - $this->root[] = $hTag; |
|
| 258 | - } |
|
| 259 | - } else { |
|
| 260 | - throw new ParseError( |
|
| 261 | - "Unable to parse line {$this->lineNo}\n\"$line\"/" . |
|
| 262 | - preg_last_error(), |
|
| 263 | - ); |
|
| 264 | - } |
|
| 265 | - } |
|
| 266 | - $this->lineNo++; |
|
| 267 | - } |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - function parseQueryString($qs) |
|
| 271 | - { |
|
| 272 | - $out = []; |
|
| 273 | - foreach (explode('&', $qs) as $s) { |
|
| 274 | - $kv = explode('=', $s, 2); |
|
| 275 | - $out[urldecode($kv[0])] = isset($kv[1]) ? urldecode($kv[1]) : null; |
|
| 276 | - } |
|
| 277 | - return $out; |
|
| 278 | - } |
|
| 279 | - |
|
| 280 | - function output($minify = false) |
|
| 281 | - { |
|
| 282 | - $out = "<?php\nuse Seufert\\Hamle;\n?>"; |
|
| 283 | - foreach ($this->root as $tag) { |
|
| 284 | - $out .= $tag->render(0, $minify); |
|
| 285 | - } |
|
| 286 | - return $out; |
|
| 287 | - } |
|
| 288 | - |
|
| 289 | - function consumeBlock($indent) |
|
| 290 | - { |
|
| 291 | - $out = []; |
|
| 292 | - $m = []; |
|
| 293 | - while ( |
|
| 294 | - $this->lineNo + 1 < $this->lineCount && |
|
| 295 | - (!trim($this->lines[$this->lineNo + 1]) || |
|
| 296 | - preg_match( |
|
| 297 | - '/^(\s){' . $indent . '}((\s)+[^\s].*)$/', |
|
| 298 | - $this->lines[$this->lineNo + 1], |
|
| 299 | - $m, |
|
| 300 | - )) |
|
| 301 | - ) { |
|
| 302 | - if (trim($this->lines[$this->lineNo + 1])) { |
|
| 303 | - $out[] = $m[2]; |
|
| 304 | - } |
|
| 305 | - $this->lineNo++; |
|
| 306 | - } |
|
| 307 | - return $out; |
|
| 308 | - } |
|
| 309 | - |
|
| 310 | - function indentLevel($indent) |
|
| 311 | - { |
|
| 312 | - if (!isset($this->indents)) { |
|
| 313 | - $this->indents = []; |
|
| 314 | - } |
|
| 315 | - if (!count($this->indents)) { |
|
| 316 | - $this->indents = [0 => $indent]; |
|
| 317 | - // Key = indent level, Value = Depth in spaces |
|
| 318 | - return 0; |
|
| 319 | - } |
|
| 320 | - foreach ($this->indents as $k => $v) { |
|
| 321 | - if ($v == $indent) { |
|
| 322 | - $this->indents = array_slice($this->indents, 0, $k + 1); |
|
| 323 | - return $k; |
|
| 324 | - } |
|
| 325 | - } |
|
| 326 | - $this->indents[] = $indent; |
|
| 327 | - return max(array_keys($this->indents)); |
|
| 328 | - } |
|
| 329 | - |
|
| 330 | - function getLineNo() |
|
| 331 | - { |
|
| 332 | - return $this->lineNo; |
|
| 333 | - } |
|
| 334 | -} |
|
@@ -54,281 +54,3 @@ |
||
| 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 | - $attr = $this->parseQueryString($param); |
|
| 227 | - } |
|
| 228 | - $class = []; |
|
| 229 | - $id = ''; |
|
| 230 | - $ref = ''; |
|
| 231 | - preg_match_all('/[#\.!][a-zA-Z0-9\-\_]+/m', $classid, $cid); |
|
| 232 | - if (isset($cid[0])) { |
|
| 233 | - foreach ($cid[0] as $s) { |
|
| 234 | - if ($s[0] == '#') { |
|
| 235 | - $id = substr($s, 1); |
|
| 236 | - } |
|
| 237 | - if ($s[0] == '.') { |
|
| 238 | - $class[] = substr($s, 1); |
|
| 239 | - } |
|
| 240 | - if ($s[0] == '!') { |
|
| 241 | - $ref = substr($s, 1); |
|
| 242 | - } |
|
| 243 | - } |
|
| 244 | - } |
|
| 245 | - if ($ref) { |
|
| 246 | - $hTag = new Tag\DynHtml($tag, $class, $attr, $id, $ref); |
|
| 247 | - } else { |
|
| 248 | - $hTag = new Tag\Html($tag, $class, $attr, $id); |
|
| 249 | - } |
|
| 250 | - $hTag->addContent($text); |
|
| 251 | - break; |
|
| 252 | - } |
|
| 253 | - $heir[$i] = $hTag; |
|
| 254 | - if ($i > 0) { |
|
| 255 | - $heir[$i - 1]->addChild($hTag); |
|
| 256 | - } else { |
|
| 257 | - $this->root[] = $hTag; |
|
| 258 | - } |
|
| 259 | - } else { |
|
| 260 | - throw new ParseError( |
|
| 261 | - "Unable to parse line {$this->lineNo}\n\"$line\"/" . |
|
| 262 | - preg_last_error(), |
|
| 263 | - ); |
|
| 264 | - } |
|
| 265 | - } |
|
| 266 | - $this->lineNo++; |
|
| 267 | - } |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - function parseQueryString($qs) |
|
| 271 | - { |
|
| 272 | - $out = []; |
|
| 273 | - foreach (explode('&', $qs) as $s) { |
|
| 274 | - $kv = explode('=', $s, 2); |
|
| 275 | - $out[urldecode($kv[0])] = isset($kv[1]) ? urldecode($kv[1]) : null; |
|
| 276 | - } |
|
| 277 | - return $out; |
|
| 278 | - } |
|
| 279 | - |
|
| 280 | - function output($minify = false) |
|
| 281 | - { |
|
| 282 | - $out = "<?php\nuse Seufert\\Hamle;\n?>"; |
|
| 283 | - foreach ($this->root as $tag) { |
|
| 284 | - $out .= $tag->render(0, $minify); |
|
| 285 | - } |
|
| 286 | - return $out; |
|
| 287 | - } |
|
| 288 | - |
|
| 289 | - function consumeBlock($indent) |
|
| 290 | - { |
|
| 291 | - $out = []; |
|
| 292 | - $m = []; |
|
| 293 | - while ( |
|
| 294 | - $this->lineNo + 1 < $this->lineCount && |
|
| 295 | - (!trim($this->lines[$this->lineNo + 1]) || |
|
| 296 | - preg_match( |
|
| 297 | - '/^(\s){' . $indent . '}((\s)+[^\s].*)$/', |
|
| 298 | - $this->lines[$this->lineNo + 1], |
|
| 299 | - $m, |
|
| 300 | - )) |
|
| 301 | - ) { |
|
| 302 | - if (trim($this->lines[$this->lineNo + 1])) { |
|
| 303 | - $out[] = $m[2]; |
|
| 304 | - } |
|
| 305 | - $this->lineNo++; |
|
| 306 | - } |
|
| 307 | - return $out; |
|
| 308 | - } |
|
| 309 | - |
|
| 310 | - function indentLevel($indent) |
|
| 311 | - { |
|
| 312 | - if (!isset($this->indents)) { |
|
| 313 | - $this->indents = []; |
|
| 314 | - } |
|
| 315 | - if (!count($this->indents)) { |
|
| 316 | - $this->indents = [0 => $indent]; |
|
| 317 | - // Key = indent level, Value = Depth in spaces |
|
| 318 | - return 0; |
|
| 319 | - } |
|
| 320 | - foreach ($this->indents as $k => $v) { |
|
| 321 | - if ($v == $indent) { |
|
| 322 | - $this->indents = array_slice($this->indents, 0, $k + 1); |
|
| 323 | - return $k; |
|
| 324 | - } |
|
| 325 | - } |
|
| 326 | - $this->indents[] = $indent; |
|
| 327 | - return max(array_keys($this->indents)); |
|
| 328 | - } |
|
| 329 | - |
|
| 330 | - function getLineNo() |
|
| 331 | - { |
|
| 332 | - return $this->lineNo; |
|
| 333 | - } |
|
| 334 | -} |
|
@@ -54,281 +54,3 @@ |
||
| 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 | - $attr = $this->parseQueryString($param); |
|
| 227 | - } |
|
| 228 | - $class = []; |
|
| 229 | - $id = ''; |
|
| 230 | - $ref = ''; |
|
| 231 | - preg_match_all('/[#\.!][a-zA-Z0-9\-\_]+/m', $classid, $cid); |
|
| 232 | - if (isset($cid[0])) { |
|
| 233 | - foreach ($cid[0] as $s) { |
|
| 234 | - if ($s[0] == '#') { |
|
| 235 | - $id = substr($s, 1); |
|
| 236 | - } |
|
| 237 | - if ($s[0] == '.') { |
|
| 238 | - $class[] = substr($s, 1); |
|
| 239 | - } |
|
| 240 | - if ($s[0] == '!') { |
|
| 241 | - $ref = substr($s, 1); |
|
| 242 | - } |
|
| 243 | - } |
|
| 244 | - } |
|
| 245 | - if ($ref) { |
|
| 246 | - $hTag = new Tag\DynHtml($tag, $class, $attr, $id, $ref); |
|
| 247 | - } else { |
|
| 248 | - $hTag = new Tag\Html($tag, $class, $attr, $id); |
|
| 249 | - } |
|
| 250 | - $hTag->addContent($text); |
|
| 251 | - break; |
|
| 252 | - } |
|
| 253 | - $heir[$i] = $hTag; |
|
| 254 | - if ($i > 0) { |
|
| 255 | - $heir[$i - 1]->addChild($hTag); |
|
| 256 | - } else { |
|
| 257 | - $this->root[] = $hTag; |
|
| 258 | - } |
|
| 259 | - } else { |
|
| 260 | - throw new ParseError( |
|
| 261 | - "Unable to parse line {$this->lineNo}\n\"$line\"/" . |
|
| 262 | - preg_last_error(), |
|
| 263 | - ); |
|
| 264 | - } |
|
| 265 | - } |
|
| 266 | - $this->lineNo++; |
|
| 267 | - } |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - function parseQueryString($qs) |
|
| 271 | - { |
|
| 272 | - $out = []; |
|
| 273 | - foreach (explode('&', $qs) as $s) { |
|
| 274 | - $kv = explode('=', $s, 2); |
|
| 275 | - $out[urldecode($kv[0])] = isset($kv[1]) ? urldecode($kv[1]) : null; |
|
| 276 | - } |
|
| 277 | - return $out; |
|
| 278 | - } |
|
| 279 | - |
|
| 280 | - function output($minify = false) |
|
| 281 | - { |
|
| 282 | - $out = "<?php\nuse Seufert\\Hamle;\n?>"; |
|
| 283 | - foreach ($this->root as $tag) { |
|
| 284 | - $out .= $tag->render(0, $minify); |
|
| 285 | - } |
|
| 286 | - return $out; |
|
| 287 | - } |
|
| 288 | - |
|
| 289 | - function consumeBlock($indent) |
|
| 290 | - { |
|
| 291 | - $out = []; |
|
| 292 | - $m = []; |
|
| 293 | - while ( |
|
| 294 | - $this->lineNo + 1 < $this->lineCount && |
|
| 295 | - (!trim($this->lines[$this->lineNo + 1]) || |
|
| 296 | - preg_match( |
|
| 297 | - '/^(\s){' . $indent . '}((\s)+[^\s].*)$/', |
|
| 298 | - $this->lines[$this->lineNo + 1], |
|
| 299 | - $m, |
|
| 300 | - )) |
|
| 301 | - ) { |
|
| 302 | - if (trim($this->lines[$this->lineNo + 1])) { |
|
| 303 | - $out[] = $m[2]; |
|
| 304 | - } |
|
| 305 | - $this->lineNo++; |
|
| 306 | - } |
|
| 307 | - return $out; |
|
| 308 | - } |
|
| 309 | - |
|
| 310 | - function indentLevel($indent) |
|
| 311 | - { |
|
| 312 | - if (!isset($this->indents)) { |
|
| 313 | - $this->indents = []; |
|
| 314 | - } |
|
| 315 | - if (!count($this->indents)) { |
|
| 316 | - $this->indents = [0 => $indent]; |
|
| 317 | - // Key = indent level, Value = Depth in spaces |
|
| 318 | - return 0; |
|
| 319 | - } |
|
| 320 | - foreach ($this->indents as $k => $v) { |
|
| 321 | - if ($v == $indent) { |
|
| 322 | - $this->indents = array_slice($this->indents, 0, $k + 1); |
|
| 323 | - return $k; |
|
| 324 | - } |
|
| 325 | - } |
|
| 326 | - $this->indents[] = $indent; |
|
| 327 | - return max(array_keys($this->indents)); |
|
| 328 | - } |
|
| 329 | - |
|
| 330 | - function getLineNo() |
|
| 331 | - { |
|
| 332 | - return $this->lineNo; |
|
| 333 | - } |
|
| 334 | -} |
|
@@ -54,281 +54,3 @@ |
||
| 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 | - $attr = $this->parseQueryString($param); |
|
| 227 | - } |
|
| 228 | - $class = []; |
|
| 229 | - $id = ''; |
|
| 230 | - $ref = ''; |
|
| 231 | - preg_match_all('/[#\.!][a-zA-Z0-9\-\_]+/m', $classid, $cid); |
|
| 232 | - if (isset($cid[0])) { |
|
| 233 | - foreach ($cid[0] as $s) { |
|
| 234 | - if ($s[0] == '#') { |
|
| 235 | - $id = substr($s, 1); |
|
| 236 | - } |
|
| 237 | - if ($s[0] == '.') { |
|
| 238 | - $class[] = substr($s, 1); |
|
| 239 | - } |
|
| 240 | - if ($s[0] == '!') { |
|
| 241 | - $ref = substr($s, 1); |
|
| 242 | - } |
|
| 243 | - } |
|
| 244 | - } |
|
| 245 | - if ($ref) { |
|
| 246 | - $hTag = new Tag\DynHtml($tag, $class, $attr, $id, $ref); |
|
| 247 | - } else { |
|
| 248 | - $hTag = new Tag\Html($tag, $class, $attr, $id); |
|
| 249 | - } |
|
| 250 | - $hTag->addContent($text); |
|
| 251 | - break; |
|
| 252 | - } |
|
| 253 | - $heir[$i] = $hTag; |
|
| 254 | - if ($i > 0) { |
|
| 255 | - $heir[$i - 1]->addChild($hTag); |
|
| 256 | - } else { |
|
| 257 | - $this->root[] = $hTag; |
|
| 258 | - } |
|
| 259 | - } else { |
|
| 260 | - throw new ParseError( |
|
| 261 | - "Unable to parse line {$this->lineNo}\n\"$line\"/" . |
|
| 262 | - preg_last_error(), |
|
| 263 | - ); |
|
| 264 | - } |
|
| 265 | - } |
|
| 266 | - $this->lineNo++; |
|
| 267 | - } |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - function parseQueryString($qs) |
|
| 271 | - { |
|
| 272 | - $out = []; |
|
| 273 | - foreach (explode('&', $qs) as $s) { |
|
| 274 | - $kv = explode('=', $s, 2); |
|
| 275 | - $out[urldecode($kv[0])] = isset($kv[1]) ? urldecode($kv[1]) : null; |
|
| 276 | - } |
|
| 277 | - return $out; |
|
| 278 | - } |
|
| 279 | - |
|
| 280 | - function output($minify = false) |
|
| 281 | - { |
|
| 282 | - $out = "<?php\nuse Seufert\\Hamle;\n?>"; |
|
| 283 | - foreach ($this->root as $tag) { |
|
| 284 | - $out .= $tag->render(0, $minify); |
|
| 285 | - } |
|
| 286 | - return $out; |
|
| 287 | - } |
|
| 288 | - |
|
| 289 | - function consumeBlock($indent) |
|
| 290 | - { |
|
| 291 | - $out = []; |
|
| 292 | - $m = []; |
|
| 293 | - while ( |
|
| 294 | - $this->lineNo + 1 < $this->lineCount && |
|
| 295 | - (!trim($this->lines[$this->lineNo + 1]) || |
|
| 296 | - preg_match( |
|
| 297 | - '/^(\s){' . $indent . '}((\s)+[^\s].*)$/', |
|
| 298 | - $this->lines[$this->lineNo + 1], |
|
| 299 | - $m, |
|
| 300 | - )) |
|
| 301 | - ) { |
|
| 302 | - if (trim($this->lines[$this->lineNo + 1])) { |
|
| 303 | - $out[] = $m[2]; |
|
| 304 | - } |
|
| 305 | - $this->lineNo++; |
|
| 306 | - } |
|
| 307 | - return $out; |
|
| 308 | - } |
|
| 309 | - |
|
| 310 | - function indentLevel($indent) |
|
| 311 | - { |
|
| 312 | - if (!isset($this->indents)) { |
|
| 313 | - $this->indents = []; |
|
| 314 | - } |
|
| 315 | - if (!count($this->indents)) { |
|
| 316 | - $this->indents = [0 => $indent]; |
|
| 317 | - // Key = indent level, Value = Depth in spaces |
|
| 318 | - return 0; |
|
| 319 | - } |
|
| 320 | - foreach ($this->indents as $k => $v) { |
|
| 321 | - if ($v == $indent) { |
|
| 322 | - $this->indents = array_slice($this->indents, 0, $k + 1); |
|
| 323 | - return $k; |
|
| 324 | - } |
|
| 325 | - } |
|
| 326 | - $this->indents[] = $indent; |
|
| 327 | - return max(array_keys($this->indents)); |
|
| 328 | - } |
|
| 329 | - |
|
| 330 | - function getLineNo() |
|
| 331 | - { |
|
| 332 | - return $this->lineNo; |
|
| 333 | - } |
|
| 334 | -} |
|
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | throw new ParseError("Unable to parse filter expression \"$s\""); |
| 67 | 67 | } |
| 68 | 68 | if (method_exists(Filter::class, $this->filter)) { |
| 69 | - $this->filter = Filter::class . '::' . $this->filter; |
|
| 69 | + $this->filter = Filter::class.'::'.$this->filter; |
|
| 70 | 70 | } elseif ( |
| 71 | 71 | in_array($this->filter, ['round', 'strtoupper', 'strtolower', 'ucfirst']) |
| 72 | 72 | ) { |
@@ -86,9 +86,9 @@ discard block |
||
| 86 | 86 | function toHTML($escape = false) |
| 87 | 87 | { |
| 88 | 88 | if ($escape) { |
| 89 | - return '<?=htmlspecialchars(' . $this->toPHP() . ')?>'; |
|
| 89 | + return '<?=htmlspecialchars('.$this->toPHP().')?>'; |
|
| 90 | 90 | } |
| 91 | - return '<?=' . $this->toPHP() . '?>'; |
|
| 91 | + return '<?='.$this->toPHP().'?>'; |
|
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | function toPHPpre() |
@@ -108,14 +108,14 @@ discard block |
||
| 108 | 108 | } |
| 109 | 109 | $o = ''; |
| 110 | 110 | foreach ($this->vars as $v) { |
| 111 | - $o .= ',' . $this->varToCode($v); |
|
| 111 | + $o .= ','.$this->varToCode($v); |
|
| 112 | 112 | } |
| 113 | 113 | return "$o)$post"; |
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | function toPHP() |
| 117 | 117 | { |
| 118 | - return $this->toPHPpre() . $this->what->toPHPVar() . $this->toPHPpost(); |
|
| 118 | + return $this->toPHPpre().$this->what->toPHPVar().$this->toPHPpost(); |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | static function itersplit($v, $sep = ',') |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | ]); |
| 73 | 73 | } catch (SyntaxError $e) { |
| 74 | 74 | throw new ParseError( |
| 75 | - 'Unable to parse:' . $s . "\n\n" . $e->getMessage(), |
|
| 75 | + 'Unable to parse:'.$s."\n\n".$e->getMessage(), |
|
| 76 | 76 | 0, |
| 77 | 77 | $e, |
| 78 | 78 | ); |
@@ -143,7 +143,7 @@ discard block |
||
| 143 | 143 | self::varToCode($limit), |
| 144 | 144 | self::varToCode($offset), |
| 145 | 145 | ]; |
| 146 | - return 'Hamle\Run::modelTypeId(' . join(',', $opt) . ')'; |
|
| 146 | + return 'Hamle\Run::modelTypeId('.join(',', $opt).')'; |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | function toHTML($escape = false) |
@@ -158,16 +158,16 @@ discard block |
||
| 158 | 158 | } |
| 159 | 159 | break; |
| 160 | 160 | case 'scopeName': |
| 161 | - $out .= '<?=' . self::renderScopeName($node) . '?>'; |
|
| 161 | + $out .= '<?='.self::renderScopeName($node).'?>'; |
|
| 162 | 162 | break; |
| 163 | 163 | case 'scopeThis': |
| 164 | - $out .= '<?=' . self::renderScopeThis($node) . '?>'; |
|
| 164 | + $out .= '<?='.self::renderScopeThis($node).'?>'; |
|
| 165 | 165 | break; |
| 166 | 166 | case 'expr': |
| 167 | - $out .= '<?=' . self::renderExpr($node) . '?>'; |
|
| 167 | + $out .= '<?='.self::renderExpr($node).'?>'; |
|
| 168 | 168 | break; |
| 169 | 169 | default: |
| 170 | - throw new \RuntimeException('Invalid Node:' . $node['type']); |
|
| 170 | + throw new \RuntimeException('Invalid Node:'.$node['type']); |
|
| 171 | 171 | } |
| 172 | 172 | } |
| 173 | 173 | return $out; |
@@ -196,7 +196,7 @@ discard block |
||
| 196 | 196 | $out[] = self::renderExpr($node); |
| 197 | 197 | break; |
| 198 | 198 | default: |
| 199 | - throw new \RuntimeException('Invalid Node:' . $node['type']); |
|
| 199 | + throw new \RuntimeException('Invalid Node:'.$node['type']); |
|
| 200 | 200 | } |
| 201 | 201 | } |
| 202 | 202 | return join('.', $out); |
@@ -204,7 +204,7 @@ discard block |
||
| 204 | 204 | |
| 205 | 205 | function doEval() |
| 206 | 206 | { |
| 207 | - return eval('use Seufert\Hamle; return ' . $this->toPHP() . ';'); |
|
| 207 | + return eval('use Seufert\Hamle; return '.$this->toPHP().';'); |
|
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | static function varToCode($var) |
@@ -212,9 +212,9 @@ discard block |
||
| 212 | 212 | if (is_array($var)) { |
| 213 | 213 | $code = []; |
| 214 | 214 | foreach ($var as $key => $value) { |
| 215 | - $code[] = self::varToCode($key) . '=>' . self::varToCode($value); |
|
| 215 | + $code[] = self::varToCode($key).'=>'.self::varToCode($value); |
|
| 216 | 216 | } |
| 217 | - return 'array(' . implode(',', $code) . ')'; //remove unnecessary coma |
|
| 217 | + return 'array('.implode(',', $code).')'; //remove unnecessary coma |
|
| 218 | 218 | } |
| 219 | 219 | if (is_bool($var)) { |
| 220 | 220 | return $var ? 'TRUE' : 'FALSE'; |
@@ -226,16 +226,16 @@ discard block |
||
| 226 | 226 | return $var->toPHP(); |
| 227 | 227 | } |
| 228 | 228 | if (strpos($var, "\n") !== false) { |
| 229 | - return '"' . |
|
| 229 | + return '"'. |
|
| 230 | 230 | str_replace( |
| 231 | 231 | ['\\', '$', '"', "\n"], |
| 232 | 232 | ['\\\\', '\$', '\\"', '\\n'], |
| 233 | 233 | $var, |
| 234 | - ) . |
|
| 234 | + ). |
|
| 235 | 235 | '"'; |
| 236 | 236 | } |
| 237 | - return "'" . |
|
| 238 | - str_replace(['\\', '$', "'"], ['\\\\', '$', "\\'"], $var) . |
|
| 237 | + return "'". |
|
| 238 | + str_replace(['\\', '$', "'"], ['\\\\', '$', "\\'"], $var). |
|
| 239 | 239 | "'"; |
| 240 | 240 | } |
| 241 | 241 | |