@@ -63,14 +63,14 @@ discard block |
||
| 63 | 63 | |
| 64 | 64 | public $baseModel; |
| 65 | 65 | |
| 66 | - const REL_CHILD = 0x01; /* Child Relation */ |
|
| 66 | + const REL_CHILD = 0x01; /* Child Relation */ |
|
| 67 | 67 | const REL_PARENT = 0x02; /* Parent Relation */ |
| 68 | - const REL_ANY = 0x03; /* Unspecified or any relation */ |
|
| 68 | + const REL_ANY = 0x03; /* Unspecified or any relation */ |
|
| 69 | 69 | |
| 70 | - const SORT_NATURAL = 0x00; /* Sort in what ever order is 'default' */ |
|
| 71 | - const SORT_ASCENDING = 0x02; /* Sort Ascending */ |
|
| 70 | + const SORT_NATURAL = 0x00; /* Sort in what ever order is 'default' */ |
|
| 71 | + const SORT_ASCENDING = 0x02; /* Sort Ascending */ |
|
| 72 | 72 | const SORT_DESCENDING = 0x03; /* Sort Decending */ |
| 73 | - const SORT_RANDOM = 0x04; /* Sort Randomly */ |
|
| 73 | + const SORT_RANDOM = 0x04; /* Sort Randomly */ |
|
| 74 | 74 | /** |
| 75 | 75 | * Create new HAMLE Parser |
| 76 | 76 | * |
@@ -81,12 +81,12 @@ discard block |
||
| 81 | 81 | */ |
| 82 | 82 | function __construct($baseModel, $setup = NULL) { |
| 83 | 83 | self::$me = $this; |
| 84 | - if(!$setup) |
|
| 84 | + if (!$setup) |
|
| 85 | 85 | $setup = new Setup(); |
| 86 | 86 | $this->parse = new Parse(); |
| 87 | - if(!$setup instanceOf Setup) |
|
| 87 | + if (!$setup instanceOf Setup) |
|
| 88 | 88 | throw new Exception\Unsupported("Unsupported Setup Helper was passed, it must extends hamleSetup"); |
| 89 | - if(!$baseModel instanceOf Model) |
|
| 89 | + if (!$baseModel instanceOf Model) |
|
| 90 | 90 | throw new Exception\Unsupported("Unsupported Model(".get_class($baseModel).") Type was passed, it must implement hamleModel"); |
| 91 | 91 | $this->setup = $setup; |
| 92 | 92 | $this->baseModel = $baseModel; |
@@ -94,9 +94,9 @@ discard block |
||
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | function initSnipFiles() { |
| 97 | - if($this->snipMod == 0) { |
|
| 97 | + if ($this->snipMod == 0) { |
|
| 98 | 98 | $this->snipFiles = $this->setup->snippetFiles(); |
| 99 | - foreach($this->snipFiles as $f) { |
|
| 99 | + foreach ($this->snipFiles as $f) { |
|
| 100 | 100 | if (!file_exists($f)) throw new Exception\NotFound("Unable to find Snippet File ($f)"); |
| 101 | 101 | $this->snipFiles = max($this->snipFiles, filemtime($f)); |
| 102 | 102 | } |
@@ -111,17 +111,17 @@ discard block |
||
| 111 | 111 | */ |
| 112 | 112 | function load($hamleFile, \Closure $parseFunc = null) { |
| 113 | 113 | $template = $this->setup->templatePath($hamleFile); |
| 114 | - if(!file_exists($template)) |
|
| 114 | + if (!file_exists($template)) |
|
| 115 | 115 | throw new Exception\NotFound("Unable to find HAMLE Template ($template)"); |
| 116 | 116 | $this->cacheFile = $this->setup->cachePath( |
| 117 | - str_replace("/","-",$hamleFile).".php"); |
|
| 117 | + str_replace("/", "-", $hamleFile).".php"); |
|
| 118 | 118 | $this->setup->debugLog("Set cache file path to ({$this->cacheFile})"); |
| 119 | - $cacheFileAge = is_file($this->cacheFile)?filemtime($this->cacheFile):0; |
|
| 119 | + $cacheFileAge = is_file($this->cacheFile) ?filemtime($this->cacheFile) : 0; |
|
| 120 | 120 | $cacheDirty = !$this->cache || |
| 121 | 121 | $cacheFileAge < $this->snipMod || $cacheFileAge < filemtime($template); |
| 122 | - if($cacheDirty) { |
|
| 122 | + if ($cacheDirty) { |
|
| 123 | 123 | $this->setup->debugLog("Parsing File ($template to {$this->cacheFile})"); |
| 124 | - $this->parse($parseFunc?"":file_get_contents($template), $parseFunc); |
|
| 124 | + $this->parse($parseFunc ? "" : file_get_contents($template), $parseFunc); |
|
| 125 | 125 | } else |
| 126 | 126 | $this->setup->debugLog("Using Cached file ({$this->cacheFile})"); |
| 127 | 127 | return $this; |
@@ -135,22 +135,22 @@ discard block |
||
| 135 | 135 | * @throws Exception\ParseError if unable to write to the cache file |
| 136 | 136 | */ |
| 137 | 137 | function parse($hamleCode, \Closure $parseFunc = null) { |
| 138 | - if(!$this->cacheFile) |
|
| 138 | + if (!$this->cacheFile) |
|
| 139 | 139 | $this->cacheFile = $this->setup->cachePath("string.hamle.php"); |
| 140 | - if($parseFunc) |
|
| 140 | + if ($parseFunc) |
|
| 141 | 141 | $parseFunc($this->parse); |
| 142 | 142 | else |
| 143 | 143 | $this->parse->str($hamleCode); |
| 144 | 144 | $this->setup->debugLog("Loading Snippet Files"); |
| 145 | - foreach($this->snipFiles as $snip) |
|
| 145 | + foreach ($this->snipFiles as $snip) |
|
| 146 | 146 | $this->parse->parseSnip(file_get_contents($snip)); |
| 147 | 147 | $this->setup->debugLog("Applying Snippet Files"); |
| 148 | 148 | $this->parse->applySnip(); |
| 149 | 149 | $this->setup->debugLog("Executing Parse Filters"); |
| 150 | - foreach($this->setup->getFilters() as $filter) |
|
| 150 | + foreach ($this->setup->getFilters() as $filter) |
|
| 151 | 151 | $this->parse->parseFilter($filter); |
| 152 | 152 | $this->setup->debugLog("Updating Cache File ({$this->cacheFile})"); |
| 153 | - if(FALSE === file_put_contents($this->cacheFile, $this->parse->output($this->setup->getMinify()))) |
|
| 153 | + if (FALSE === file_put_contents($this->cacheFile, $this->parse->output($this->setup->getMinify()))) |
|
| 154 | 154 | throw new Exception\ParseError( |
| 155 | 155 | "Unable to write to cache file ({$this->cacheFile})"); |
| 156 | 156 | } |
@@ -161,9 +161,9 @@ discard block |
||
| 161 | 161 | */ |
| 162 | 162 | function string($hamleString) { |
| 163 | 163 | $md5 = md5($hamleString); |
| 164 | - $stringId = substr($md5,0,12).substr($md5,24,8); |
|
| 164 | + $stringId = substr($md5, 0, 12).substr($md5, 24, 8); |
|
| 165 | 165 | $this->cacheFile = $this->setup->cachePath("string.$stringId.hamle.php"); |
| 166 | - if(!is_file($this->cacheFile)) |
|
| 166 | + if (!is_file($this->cacheFile)) |
|
| 167 | 167 | $this->parse($hamleString); |
| 168 | 168 | } |
| 169 | 169 | |
@@ -183,9 +183,9 @@ discard block |
||
| 183 | 183 | $baseModel = $this->baseModel; |
| 184 | 184 | $this->baseModel = null; |
| 185 | 185 | $currentModel = $baseModel == Scope::getTopScope(); |
| 186 | - if(!$currentModel && $baseModel) Scope::add($baseModel); |
|
| 186 | + if (!$currentModel && $baseModel) Scope::add($baseModel); |
|
| 187 | 187 | require $this->cacheFile; |
| 188 | - if(!$currentModel && $baseModel) Scope::done(); |
|
| 188 | + if (!$currentModel && $baseModel) Scope::done(); |
|
| 189 | 189 | $this->baseModel = $baseModel; |
| 190 | 190 | $out = ob_get_contents(); |
| 191 | 191 | ob_end_clean(); |
@@ -202,7 +202,7 @@ discard block |
||
| 202 | 202 | * @return int The line number being passed by the parser |
| 203 | 203 | */ |
| 204 | 204 | static function getLineNo() { |
| 205 | - if(!isset(self::$me)) |
|
| 205 | + if (!isset(self::$me)) |
|
| 206 | 206 | return 0; |
| 207 | 207 | return self::$me->parse->getLineNo(); |
| 208 | 208 | } |
@@ -38,14 +38,14 @@ discard block |
||
| 38 | 38 | $this->source[] = $ref; |
| 39 | 39 | $this->baseType = $tag; |
| 40 | 40 | self::$var++; |
| 41 | - $this->varname = "\$dynhtml" . self::$var; |
|
| 41 | + $this->varname = "\$dynhtml".self::$var; |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | function render($indent = 0, $minify = false) { |
| 45 | 45 | $data = H\Text::varToCode(array("base" => $this->baseType, "type" => $this->type, "opt" => $this->opt, "source" => $this->source, "content" => $this->content)); |
| 46 | - $out = "<?php " . $this->varname . "=$data; echo Hamle\\Tag\\DynHtml::toStTag(" . $this->varname . ",\$form)."; |
|
| 47 | - $out .= "implode(\"\\n\"," . $this->varname . "['content'])."; |
|
| 48 | - $out .= "Hamle\\Tag\\DynHtml::toEnTag(" . $this->varname . ",\$form)?>".($minify ? '' : "\n"); |
|
| 46 | + $out = "<?php ".$this->varname."=$data; echo Hamle\\Tag\\DynHtml::toStTag(".$this->varname.",\$form)."; |
|
| 47 | + $out .= "implode(\"\\n\",".$this->varname."['content'])."; |
|
| 48 | + $out .= "Hamle\\Tag\\DynHtml::toEnTag(".$this->varname.",\$form)?>".($minify ? '' : "\n"); |
|
| 49 | 49 | return $out; |
| 50 | 50 | } |
| 51 | 51 | |
@@ -57,21 +57,21 @@ discard block |
||
| 57 | 57 | foreach ($d['source'] as $source) { |
| 58 | 58 | $form->getField($source)->getDynamicAtt($d['base'], $d['opt'], $d['type'], $d['content']); |
| 59 | 59 | } |
| 60 | - $out = "<" . $d['type'] . " "; |
|
| 60 | + $out = "<".$d['type']." "; |
|
| 61 | 61 | foreach ($d['opt'] as $k => $v) { |
| 62 | 62 | if (is_array($v)) { |
| 63 | 63 | foreach ($v as $k2 => $v2) |
| 64 | - if ($v[$k2] instanceof Text) $v[$k2] = eval('return ' . $v[$k2]->toPHP() . ';'); |
|
| 64 | + if ($v[$k2] instanceof Text) $v[$k2] = eval('return '.$v[$k2]->toPHP().';'); |
|
| 65 | 65 | $v = implode(" ", $v); |
| 66 | 66 | } |
| 67 | - if ($v instanceOf H\Text) $v = eval('return ' . $v->toPHP() . ';'); |
|
| 68 | - $out .= $k . "=\"" . htmlspecialchars($v) . "\" "; |
|
| 67 | + if ($v instanceOf H\Text) $v = eval('return '.$v->toPHP().';'); |
|
| 68 | + $out .= $k."=\"".htmlspecialchars($v)."\" "; |
|
| 69 | 69 | } |
| 70 | 70 | $out .= in_array($d['type'], self::$selfCloseTags) ? "/>" : ">"; |
| 71 | 71 | return $out; |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | static function toEnTag($d, $form) { |
| 75 | - return in_array($d['type'], self::$selfCloseTags) ? '' : "</" . $d['type'] . ">"; |
|
| 75 | + return in_array($d['type'], self::$selfCloseTags) ? '' : "</".$d['type'].">"; |
|
| 76 | 76 | } |
| 77 | 77 | } |
| 78 | 78 | \ No newline at end of file |
@@ -47,13 +47,13 @@ discard block |
||
| 47 | 47 | */ |
| 48 | 48 | function __construct($tag, $parentTag = null) { |
| 49 | 49 | parent::__construct(); |
| 50 | - $this->o = "\$o" . self::$instCount++; |
|
| 50 | + $this->o = "\$o".self::$instCount++; |
|
| 51 | 51 | $this->type = strtolower($tag); |
| 52 | 52 | $this->var = ""; |
| 53 | 53 | if ($parentTag && $this->type == "else") { |
| 54 | - if($parentTag instanceof H\Tag) { |
|
| 54 | + if ($parentTag instanceof H\Tag) { |
|
| 55 | 55 | $elseTag = $parentTag->tags[count($parentTag->tags) - 1]; |
| 56 | - if($elseTag instanceof H\Tag\Control && |
|
| 56 | + if ($elseTag instanceof H\Tag\Control && |
|
| 57 | 57 | in_array($elseTag->type, array('with', 'if')) |
| 58 | 58 | ) { |
| 59 | 59 | $elseTag->else = true; |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | function renderStTag() { |
| 70 | - $out = "<" . "?php "; |
|
| 70 | + $out = "<"."?php "; |
|
| 71 | 71 | $scopeName = ""; |
| 72 | 72 | if (preg_match('/ as ([a-zA-Z]+)$/', $this->var, $m)) { |
| 73 | 73 | $scopeName = $m[1]; |
@@ -78,20 +78,20 @@ discard block |
||
| 78 | 78 | switch ($this->type) { |
| 79 | 79 | case "each": |
| 80 | 80 | if ($this->var) |
| 81 | - $out .= "foreach(" . $hsv->toPHP() . " as {$this->o}) { \n"; |
|
| 81 | + $out .= "foreach(".$hsv->toPHP()." as {$this->o}) { \n"; |
|
| 82 | 82 | else |
| 83 | 83 | $out .= "foreach(Hamle\\Scope::get() as {$this->o}) { \n"; |
| 84 | 84 | $out .= "Hamle\\Scope::add({$this->o}); "; |
| 85 | 85 | break; |
| 86 | 86 | case "if": |
| 87 | 87 | $hsvcomp = new H\Text\Comparison($this->var); |
| 88 | - $out .= "if(" . $hsvcomp->toPHP() . ") {"; |
|
| 88 | + $out .= "if(".$hsvcomp->toPHP().") {"; |
|
| 89 | 89 | break; |
| 90 | 90 | case "with": |
| 91 | 91 | if ($scopeName) |
| 92 | - $out .= "Hamle\\Scope::add(" . $hsv->toPHP() . ", \"$scopeName\");\n;"; |
|
| 92 | + $out .= "Hamle\\Scope::add(".$hsv->toPHP().", \"$scopeName\");\n;"; |
|
| 93 | 93 | else { |
| 94 | - $out .= "if(({$this->o} = " . $hsv->toPHP() . ") && " . |
|
| 94 | + $out .= "if(({$this->o} = ".$hsv->toPHP().") && ". |
|
| 95 | 95 | "{$this->o}->valid()) {\n"; |
| 96 | 96 | $out .= "Hamle\\Scope::add({$this->o});\n;"; |
| 97 | 97 | } |
@@ -101,13 +101,13 @@ discard block |
||
| 101 | 101 | break; |
| 102 | 102 | case "include": |
| 103 | 103 | $file = $hsv->toHTML(); |
| 104 | - if($file[0] == "#") |
|
| 104 | + if ($file[0] == "#") |
|
| 105 | 105 | $out .= "echo Hamle\\Run::includeFragment(".$hsv->toPHP().");"; |
| 106 | 106 | else |
| 107 | - $out .= "echo Hamle\\Run::includeFile(" . $hsv->toPHP() . ");"; |
|
| 107 | + $out .= "echo Hamle\\Run::includeFile(".$hsv->toPHP().");"; |
|
| 108 | 108 | break; |
| 109 | 109 | } |
| 110 | - return $out . "\n?>"; |
|
| 110 | + return $out."\n?>"; |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | /** |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | function renderEnTag() { |
| 121 | - $out = '<' . '?php '; |
|
| 121 | + $out = '<'.'?php '; |
|
| 122 | 122 | switch ($this->type) { |
| 123 | 123 | case "each"; |
| 124 | 124 | $out .= 'Hamle\\Scope::done(); '; |
@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | break; |
| 142 | 142 | } |
| 143 | 143 | if ($this->else) $out .= "else{"; |
| 144 | - return $out . "\n?>"; |
|
| 144 | + return $out."\n?>"; |
|
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | function render($indent = 0, $minify = false) { |
@@ -143,11 +143,11 @@ discard block |
||
| 143 | 143 | function render($indent = 0, $minify = false) {
|
| 144 | 144 | $ind = $minify ? '' : str_pad('', $indent);
|
| 145 | 145 | $oneliner = (!(count($this->content) > 1 || $this->tags)); |
| 146 | - $out = $ind . $this->renderStTag() . ($oneliner || $minify ? '' : "\n"); |
|
| 146 | + $out = $ind.$this->renderStTag().($oneliner || $minify ? '' : "\n"); |
|
| 147 | 147 | if ($this->content) $out .= $this->renderContent($ind, $oneliner || $minify); |
| 148 | 148 | foreach ($this->tags as $tag) |
| 149 | 149 | $out .= $tag->render($indent + self::INDENT_SIZE, $minify); |
| 150 | - $out .= ($minify || $oneliner ? '' : $ind) . $this->renderEnTag() . ($minify ? '' : "\n"); |
|
| 150 | + $out .= ($minify || $oneliner ? '' : $ind).$this->renderEnTag().($minify ? '' : "\n"); |
|
| 151 | 151 | return $out; |
| 152 | 152 | } |
| 153 | 153 | |
@@ -161,7 +161,7 @@ discard block |
||
| 161 | 161 | function renderContent($pad = "", $oneliner = false) {
|
| 162 | 162 | $out = ""; |
| 163 | 163 | foreach ($this->content as $c) |
| 164 | - $out .= ($oneliner ? '' : $pad) . $c . ($oneliner ? '' : "\n"); |
|
| 164 | + $out .= ($oneliner ? '' : $pad).$c.($oneliner ? '' : "\n"); |
|
| 165 | 165 | return $out; |
| 166 | 166 | } |
| 167 | 167 | |
@@ -54,12 +54,12 @@ discard block |
||
| 54 | 54 | $pos = 0; |
| 55 | 55 | $this->nodes = []; |
| 56 | 56 | $rFlag = PREG_OFFSET_CAPTURE + PREG_SET_ORDER; |
| 57 | - if(trim($s) === '') { |
|
| 57 | + if (trim($s) === '') { |
|
| 58 | 58 | $this->nodes[] = new Text\Plain($s, $mode); |
| 59 | 59 | return; |
| 60 | 60 | } |
| 61 | - if($mode === self::TOKEN_CONTROL) { |
|
| 62 | - if(preg_match('/^"(.*)"$/', trim($s), $m)) { |
|
| 61 | + if ($mode === self::TOKEN_CONTROL) { |
|
| 62 | + if (preg_match('/^"(.*)"$/', trim($s), $m)) { |
|
| 63 | 63 | $this->nodes[] = new Text($m[1]); |
| 64 | 64 | } |
| 65 | 65 | else { |
@@ -68,20 +68,20 @@ discard block |
||
| 68 | 68 | return; |
| 69 | 69 | } |
| 70 | 70 | preg_match_all(self::REGEX_HTML, $s, $m, $rFlag); |
| 71 | - foreach($m as $match) { |
|
| 72 | - if($mode & self::FIND_BARDOLLAR && isset($match[2])) { |
|
| 73 | - if($match[2][1] != $pos) { |
|
| 71 | + foreach ($m as $match) { |
|
| 72 | + if ($mode & self::FIND_BARDOLLAR && isset($match[2])) { |
|
| 73 | + if ($match[2][1] != $pos) { |
|
| 74 | 74 | $this->nodes[] = new Text\Plain( |
| 75 | 75 | substr($s, $pos, $match[2][1] - $pos), $mode); |
| 76 | 76 | } |
| 77 | 77 | $this->nodes[] = new Text\Complex(substr($match[2][0], 1, -1)); |
| 78 | 78 | $pos = $match[2][1] + strlen($match[2][0]); |
| 79 | 79 | } |
| 80 | - else if($mode & self::FIND_DOLLARVAR) { |
|
| 81 | - if($match[1][1] > 0 && $s[$match[1][1] - 1] === '\\') { |
|
| 80 | + else if ($mode & self::FIND_DOLLARVAR) { |
|
| 81 | + if ($match[1][1] > 0 && $s[$match[1][1] - 1] === '\\') { |
|
| 82 | 82 | continue; |
| 83 | 83 | } |
| 84 | - if($match[1][1] != $pos) { |
|
| 84 | + if ($match[1][1] != $pos) { |
|
| 85 | 85 | $this->nodes[] = new Text\Plain( |
| 86 | 86 | substr($s, $pos, $match[1][1] - $pos), $mode); |
| 87 | 87 | } |
@@ -89,14 +89,14 @@ discard block |
||
| 89 | 89 | $pos = $match[1][1] + strlen($match[1][0]); |
| 90 | 90 | } |
| 91 | 91 | } |
| 92 | - if($pos != strlen($s)) { |
|
| 92 | + if ($pos != strlen($s)) { |
|
| 93 | 93 | $this->nodes[] = new Text\Plain(substr($s, $pos), $mode); |
| 94 | 94 | } |
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | function toHTML($escape = false) { |
| 98 | 98 | $out = []; |
| 99 | - foreach($this->nodes as $string) { |
|
| 99 | + foreach ($this->nodes as $string) { |
|
| 100 | 100 | $out[] = $string->toHTML($escape); |
| 101 | 101 | } |
| 102 | 102 | return implode('', $out); |
@@ -108,34 +108,34 @@ discard block |
||
| 108 | 108 | |
| 109 | 109 | function toPHP() { |
| 110 | 110 | $out = []; |
| 111 | - foreach($this->nodes as $string) { |
|
| 111 | + foreach ($this->nodes as $string) { |
|
| 112 | 112 | $out[] = $string->toPHP(); |
| 113 | 113 | } |
| 114 | 114 | return implode(".", $out); |
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | function doEval() { |
| 118 | - return eval('use Seufert\Hamle; return ' . $this->toPHP() . ';'); |
|
| 118 | + return eval('use Seufert\Hamle; return '.$this->toPHP().';'); |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | static function varToCode($var) { |
| 122 | - if(is_array($var)) { |
|
| 122 | + if (is_array($var)) { |
|
| 123 | 123 | $code = []; |
| 124 | - foreach($var as $key => $value) { |
|
| 125 | - $code[] = self::varToCode($key) . '=>' . self::varToCode($value); |
|
| 124 | + foreach ($var as $key => $value) { |
|
| 125 | + $code[] = self::varToCode($key).'=>'.self::varToCode($value); |
|
| 126 | 126 | } |
| 127 | - return 'array(' . implode(',', $code) . ')'; //remove unnecessary coma |
|
| 127 | + return 'array('.implode(',', $code).')'; //remove unnecessary coma |
|
| 128 | 128 | } |
| 129 | - if(is_bool($var)) { |
|
| 129 | + if (is_bool($var)) { |
|
| 130 | 130 | return ($var ? 'TRUE' : 'FALSE'); |
| 131 | 131 | } |
| 132 | - if(is_int($var) || is_float($var) || is_numeric($var)) { |
|
| 132 | + if (is_int($var) || is_float($var) || is_numeric($var)) { |
|
| 133 | 133 | return $var; |
| 134 | 134 | } |
| 135 | - if($var instanceof Text) { |
|
| 135 | + if ($var instanceof Text) { |
|
| 136 | 136 | return $var->toPHP(); |
| 137 | 137 | } |
| 138 | - return "'" . str_replace(['$', "'"], ['$', "\\'"], $var) . "'"; |
|
| 138 | + return "'".str_replace(['$', "'"], ['$', "\\'"], $var)."'"; |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | /** |
@@ -45,7 +45,7 @@ |
||
| 45 | 45 | |
| 46 | 46 | static function decodeClassId($s) { |
| 47 | 47 | $out = $m = array(); |
| 48 | - if(preg_match('/^[a-zA-Z0-9\_]+/', $s, $m)) |
|
| 48 | + if (preg_match('/^[a-zA-Z0-9\_]+/', $s, $m)) |
|
| 49 | 49 | $out['type'] = $m[0]; |
| 50 | 50 | preg_match_all('/[#\.][a-zA-Z0-9\-\_]+/m', $s, $m); |
| 51 | 51 | if (isset($m[0])) foreach ($m[0] as $ss) { |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | */ |
| 51 | 51 | public function __construct($s) { |
| 52 | 52 | $m = array(); |
| 53 | - if (!preg_match('/^\$\((' . self::REGEX_FUNCSEL . '*)(.*)\)$/', $s, $m)) |
|
| 53 | + if (!preg_match('/^\$\(('.self::REGEX_FUNCSEL.'*)(.*)\)$/', $s, $m)) |
|
| 54 | 54 | throw new ParseError("Unable to read \$ func in '$s'"); |
| 55 | 55 | if (trim($m[2])) |
| 56 | 56 | $this->sub = new FuncSub($m[2]); |
@@ -92,13 +92,13 @@ discard block |
||
| 92 | 92 | } |
| 93 | 93 | $rand = false; |
| 94 | 94 | if (preg_match_all('/\\^(-?)([a-zA-Z0-9_]*)/', $s, $m)) { |
| 95 | - foreach($m[0] as $k=>$mv) |
|
| 95 | + foreach ($m[0] as $k=>$mv) |
|
| 96 | 96 | if ($m[2][$k]) { |
| 97 | - $dir = $m[1][$k] == "-"?Hamle\Hamle::SORT_DESCENDING:Hamle\Hamle::SORT_ASCENDING; |
|
| 97 | + $dir = $m[1][$k] == "-" ?Hamle\Hamle::SORT_DESCENDING : Hamle\Hamle::SORT_ASCENDING; |
|
| 98 | 98 | $att['sort'][$m[2][$k]] = $dir; |
| 99 | 99 | } else $rand = true; |
| 100 | 100 | } |
| 101 | - if($rand) |
|
| 101 | + if ($rand) |
|
| 102 | 102 | $att['sort'] = [""=>$att['dir'] = Hamle\Hamle::SORT_RANDOM]; |
| 103 | 103 | return $att; |
| 104 | 104 | } |
@@ -116,25 +116,25 @@ discard block |
||
| 116 | 116 | * @return string PHP Code |
| 117 | 117 | */ |
| 118 | 118 | public function toPHP() { |
| 119 | - $sub = $this->sub ? "->" . $this->sub->toPHP() : ""; |
|
| 120 | - if($this->scope instanceof Scope) { |
|
| 121 | - return $this->scope->toPHP() . $sub; |
|
| 122 | - } elseif($this->scope === true) { |
|
| 119 | + $sub = $this->sub ? "->".$this->sub->toPHP() : ""; |
|
| 120 | + if ($this->scope instanceof Scope) { |
|
| 121 | + return $this->scope->toPHP().$sub; |
|
| 122 | + } elseif ($this->scope === true) { |
|
| 123 | 123 | return "Hamle\\Scope::get(0)$sub"; |
| 124 | 124 | } |
| 125 | - $limit = Text::varToCode($this->sortlimit['sort']) . "," . |
|
| 126 | - $this->sortlimit['limit'] . "," . $this->sortlimit['offset']; |
|
| 125 | + $limit = Text::varToCode($this->sortlimit['sort']).",". |
|
| 126 | + $this->sortlimit['limit'].",".$this->sortlimit['offset']; |
|
| 127 | 127 | if (count($this->filt['tag'])) |
| 128 | - return "Hamle\\Run::modelTypeTags(" . |
|
| 129 | - Text::varToCode($this->filt['tag']) . ",$limit)$sub"; |
|
| 128 | + return "Hamle\\Run::modelTypeTags(". |
|
| 129 | + Text::varToCode($this->filt['tag']).",$limit)$sub"; |
|
| 130 | 130 | if (count($this->filt['id'])) |
| 131 | 131 | if (isset($this->filt['id']['*']) && count($this->filt['id']['*']) == 1) |
| 132 | - return "Hamle\\Run::modelId(" . |
|
| 133 | - Text::varToCode(current($this->filt['id']['*'])) . |
|
| 132 | + return "Hamle\\Run::modelId(". |
|
| 133 | + Text::varToCode(current($this->filt['id']['*'])). |
|
| 134 | 134 | ",$limit)$sub"; |
| 135 | 135 | else |
| 136 | - return "Hamle\\Run::modelTypeId(" . |
|
| 137 | - Text::varToCode($this->filt['id']) . ",$limit)$sub"; |
|
| 136 | + return "Hamle\\Run::modelTypeId(". |
|
| 137 | + Text::varToCode($this->filt['id']).",$limit)$sub"; |
|
| 138 | 138 | return ""; |
| 139 | 139 | } |
| 140 | 140 | |
@@ -143,7 +143,7 @@ discard block |
||
| 143 | 143 | * @return Model |
| 144 | 144 | */ |
| 145 | 145 | public function getOrCreateModel(Model $parent = null) { |
| 146 | - if($this->scope instanceof Scope) { |
|
| 146 | + if ($this->scope instanceof Scope) { |
|
| 147 | 147 | $parent = $this->scope->getOrCreateModel(); |
| 148 | 148 | } elseif ($this->scope === true) |
| 149 | 149 | $parent = \Seufert\Hamle\Scope::get(0); |
@@ -169,9 +169,9 @@ discard block |
||
| 169 | 169 | $this->sortlimit['limit'], |
| 170 | 170 | $this->sortlimit['offset'] |
| 171 | 171 | ); |
| 172 | - if($this->sub) |
|
| 172 | + if ($this->sub) |
|
| 173 | 173 | return $this->sub->getOrCreateModel($parent)->current(); |
| 174 | - if(!$parent) |
|
| 174 | + if (!$parent) |
|
| 175 | 175 | throw new \RuntimeException('Unable to create model with no relation'); |
| 176 | 176 | return $parent->current(); |
| 177 | 177 | } |
@@ -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; |
@@ -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") |
@@ -191,7 +191,7 @@ discard block |
||
| 191 | 191 | break; |
| 192 | 192 | default: |
| 193 | 193 | $attr = array(); |
| 194 | - if(isset($params[0]) && $params[0] == "[") {
|
|
| 194 | + if (isset($params[0]) && $params[0] == "[") {
|
|
| 195 | 195 | $param = substr($params, 1, -1); |
| 196 | 196 | $param = str_replace(['+', '\\&'], ['%2B', '%26'], $param); |
| 197 | 197 | // parse_str($param, $attr); |
@@ -204,7 +204,7 @@ discard block |
||
| 204 | 204 | if ($s[0] == ".") $class[] = substr($s, 1); |
| 205 | 205 | if ($s[0] == "!") $ref = substr($s, 1); |
| 206 | 206 | } |
| 207 | - if($ref) |
|
| 207 | + if ($ref) |
|
| 208 | 208 | $hTag = new Tag\DynHtml($tag, $class, $attr, $id, $ref); |
| 209 | 209 | else |
| 210 | 210 | $hTag = new Tag\Html($tag, $class, $attr, $id); |
@@ -217,16 +217,16 @@ discard block |
||
| 217 | 217 | else |
| 218 | 218 | $this->root[] = $hTag; |
| 219 | 219 | } else |
| 220 | - throw new ParseError("Unable to parse line {$this->lineNo}\n\"$line\"/" . preg_last_error());
|
|
| 220 | + throw new ParseError("Unable to parse line {$this->lineNo}\n\"$line\"/".preg_last_error());
|
|
| 221 | 221 | $this->lineNo++; |
| 222 | 222 | } |
| 223 | 223 | } |
| 224 | 224 | |
| 225 | 225 | function parseQueryString($qs) {
|
| 226 | 226 | $out = []; |
| 227 | - foreach(explode('&',$qs) as $s) {
|
|
| 228 | - $kv = explode('=',$s,2);
|
|
| 229 | - $out[urldecode($kv[0])] = isset($kv[1])?urldecode($kv[1]):null; |
|
| 227 | + foreach (explode('&', $qs) as $s) {
|
|
| 228 | + $kv = explode('=', $s, 2);
|
|
| 229 | + $out[urldecode($kv[0])] = isset($kv[1]) ?urldecode($kv[1]) : null; |
|
| 230 | 230 | } |
| 231 | 231 | return $out; |
| 232 | 232 | } |
@@ -244,7 +244,7 @@ discard block |
||
| 244 | 244 | $m = array(); |
| 245 | 245 | while ($this->lineNo + 1 < $this->lineCount && |
| 246 | 246 | (!trim($this->lines[$this->lineNo + 1]) || |
| 247 | - preg_match('/^(\s){' . $indent . '}((\s)+[^\s].*)$/',
|
|
| 247 | + preg_match('/^(\s){'.$indent.'}((\s)+[^\s].*)$/',
|
|
| 248 | 248 | $this->lines[$this->lineNo + 1], $m))) {
|
| 249 | 249 | if (trim($this->lines[$this->lineNo + 1])) |
| 250 | 250 | $out[] = $m[2]; |