@@ -41,7 +41,9 @@ discard block |
||
| 41 | 41 | public function cachePath($f) {
|
| 42 | 42 | $s = DIRECTORY_SEPARATOR; |
| 43 | 43 | $dir = implode($s,[__DIR__,"..","..","cache",""]); |
| 44 | - if(!is_dir($dir)) mkdir($dir); |
|
| 44 | + if(!is_dir($dir)) { |
|
| 45 | + mkdir($dir); |
|
| 46 | + } |
|
| 45 | 47 | return $dir.$f; |
| 46 | 48 | } |
| 47 | 49 | |
@@ -67,8 +69,9 @@ discard block |
||
| 67 | 69 | * @throws Exception\RunTime |
| 68 | 70 | */ |
| 69 | 71 | public function getModelTypeID($typeId, $sort = [], $limit = 0, $offset = 0) {
|
| 70 | - if(count($typeId) > 1) |
|
| 71 | - throw new Exception\RunTime("Unable to open more than one ID at a time");
|
|
| 72 | + if(count($typeId) > 1) { |
|
| 73 | + throw new Exception\RunTime("Unable to open more than one ID at a time"); |
|
| 74 | + } |
|
| 72 | 75 | return new Model\Zero(); |
| 73 | 76 | } |
| 74 | 77 | |
@@ -35,8 +35,9 @@ |
||
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | function hamleGet($key) { |
| 38 | - if (!isset($this->data[$this->pos][$key])) |
|
| 39 | - return "Missing Key [$key]"; |
|
| 38 | + if (!isset($this->data[$this->pos][$key])) { |
|
| 39 | + return "Missing Key [$key]"; |
|
| 40 | + } |
|
| 40 | 41 | return $this->data[$this->pos][$key]; |
| 41 | 42 | } |
| 42 | 43 | |
@@ -81,13 +81,16 @@ discard block |
||
| 81 | 81 | */ |
| 82 | 82 | function __construct($baseModel, $setup = NULL) { |
| 83 | 83 | self::$me = $this; |
| 84 | - if(!$setup) |
|
| 85 | - $setup = new Setup(); |
|
| 84 | + if(!$setup) { |
|
| 85 | + $setup = new Setup(); |
|
| 86 | + } |
|
| 86 | 87 | $this->parse = new Parse(); |
| 87 | - if(!$setup instanceOf Setup) |
|
| 88 | - throw new Exception\Unsupported("Unsupported Setup Helper was passed, it must extends hamleSetup"); |
|
| 89 | - if(!$baseModel instanceOf Model) |
|
| 90 | - throw new Exception\Unsupported("Unsupported Model(".get_class($baseModel).") Type was passed, it must implement hamleModel"); |
|
| 88 | + if(!$setup instanceOf Setup) { |
|
| 89 | + throw new Exception\Unsupported("Unsupported Setup Helper was passed, it must extends hamleSetup"); |
|
| 90 | + } |
|
| 91 | + if(!$baseModel instanceOf Model) { |
|
| 92 | + throw new Exception\Unsupported("Unsupported Model(".get_class($baseModel).") Type was passed, it must implement hamleModel"); |
|
| 93 | + } |
|
| 91 | 94 | $this->setup = $setup; |
| 92 | 95 | $this->baseModel = $baseModel; |
| 93 | 96 | $this->initSnipFiles(); |
@@ -97,7 +100,9 @@ discard block |
||
| 97 | 100 | if($this->snipMod == 0) { |
| 98 | 101 | $this->snipFiles = $this->setup->snippetFiles(); |
| 99 | 102 | foreach($this->snipFiles as $f) { |
| 100 | - if (!file_exists($f)) throw new Exception\NotFound("Unable to find Snippet File ($f)"); |
|
| 103 | + if (!file_exists($f)) { |
|
| 104 | + throw new Exception\NotFound("Unable to find Snippet File ($f)"); |
|
| 105 | + } |
|
| 101 | 106 | $this->snipFiles = max($this->snipFiles, filemtime($f)); |
| 102 | 107 | } |
| 103 | 108 | } |
@@ -111,8 +116,9 @@ discard block |
||
| 111 | 116 | */ |
| 112 | 117 | function load($hamleFile, \Closure $parseFunc = null) { |
| 113 | 118 | $template = $this->setup->templatePath($hamleFile); |
| 114 | - if(!file_exists($template)) |
|
| 115 | - throw new Exception\NotFound("Unable to find HAMLE Template ($template)"); |
|
| 119 | + if(!file_exists($template)) { |
|
| 120 | + throw new Exception\NotFound("Unable to find HAMLE Template ($template)"); |
|
| 121 | + } |
|
| 116 | 122 | $this->cacheFile = $this->setup->cachePath( |
| 117 | 123 | str_replace("/","-",$hamleFile).".php"); |
| 118 | 124 | $this->setup->debugLog("Set cache file path to ({$this->cacheFile})"); |
@@ -122,8 +128,9 @@ discard block |
||
| 122 | 128 | if($cacheDirty) { |
| 123 | 129 | $this->setup->debugLog("Parsing File ($template to {$this->cacheFile})"); |
| 124 | 130 | $this->parse($parseFunc?"":file_get_contents($template), $parseFunc); |
| 125 | - } else |
|
| 126 | - $this->setup->debugLog("Using Cached file ({$this->cacheFile})"); |
|
| 131 | + } else { |
|
| 132 | + $this->setup->debugLog("Using Cached file ({$this->cacheFile})"); |
|
| 133 | + } |
|
| 127 | 134 | return $this; |
| 128 | 135 | } |
| 129 | 136 | /** |
@@ -135,24 +142,29 @@ discard block |
||
| 135 | 142 | * @throws Exception\ParseError if unable to write to the cache file |
| 136 | 143 | */ |
| 137 | 144 | function parse($hamleCode, \Closure $parseFunc = null) { |
| 138 | - if(!$this->cacheFile) |
|
| 139 | - $this->cacheFile = $this->setup->cachePath("string.hamle.php"); |
|
| 140 | - if($parseFunc) |
|
| 141 | - $parseFunc($this->parse); |
|
| 142 | - else |
|
| 143 | - $this->parse->str($hamleCode); |
|
| 145 | + if(!$this->cacheFile) { |
|
| 146 | + $this->cacheFile = $this->setup->cachePath("string.hamle.php"); |
|
| 147 | + } |
|
| 148 | + if($parseFunc) { |
|
| 149 | + $parseFunc($this->parse); |
|
| 150 | + } else { |
|
| 151 | + $this->parse->str($hamleCode); |
|
| 152 | + } |
|
| 144 | 153 | $this->setup->debugLog("Loading Snippet Files"); |
| 145 | - foreach($this->snipFiles as $snip) |
|
| 146 | - $this->parse->parseSnip(file_get_contents($snip)); |
|
| 154 | + foreach($this->snipFiles as $snip) { |
|
| 155 | + $this->parse->parseSnip(file_get_contents($snip)); |
|
| 156 | + } |
|
| 147 | 157 | $this->setup->debugLog("Applying Snippet Files"); |
| 148 | 158 | $this->parse->applySnip(); |
| 149 | 159 | $this->setup->debugLog("Executing Parse Filters"); |
| 150 | - foreach($this->setup->getFilters() as $filter) |
|
| 151 | - $this->parse->parseFilter($filter); |
|
| 160 | + foreach($this->setup->getFilters() as $filter) { |
|
| 161 | + $this->parse->parseFilter($filter); |
|
| 162 | + } |
|
| 152 | 163 | $this->setup->debugLog("Updating Cache File ({$this->cacheFile})"); |
| 153 | - if(FALSE === file_put_contents($this->cacheFile, $this->parse->output())) |
|
| 154 | - throw new Exception\ParseError( |
|
| 164 | + if(FALSE === file_put_contents($this->cacheFile, $this->parse->output())) { |
|
| 165 | + throw new Exception\ParseError( |
|
| 155 | 166 | "Unable to write to cache file ({$this->cacheFile})"); |
| 167 | + } |
|
| 156 | 168 | } |
| 157 | 169 | |
| 158 | 170 | /** |
@@ -163,8 +175,9 @@ discard block |
||
| 163 | 175 | $md5 = md5($hamleString); |
| 164 | 176 | $stringId = substr($md5,0,12).substr($md5,24,8); |
| 165 | 177 | $this->cacheFile = $this->setup->cachePath("string.$stringId.hamle.php"); |
| 166 | - if(!is_file($this->cacheFile)) |
|
| 167 | - $this->parse($hamleString); |
|
| 178 | + if(!is_file($this->cacheFile)) { |
|
| 179 | + $this->parse($hamleString); |
|
| 180 | + } |
|
| 168 | 181 | } |
| 169 | 182 | |
| 170 | 183 | /** |
@@ -179,9 +192,13 @@ discard block |
||
| 179 | 192 | $baseModel = $this->baseModel; |
| 180 | 193 | $this->baseModel = null; |
| 181 | 194 | $currentModel = $baseModel == Scope::getTopScope(); |
| 182 | - if(!$currentModel && $baseModel) Scope::add($baseModel); |
|
| 195 | + if(!$currentModel && $baseModel) { |
|
| 196 | + Scope::add($baseModel); |
|
| 197 | + } |
|
| 183 | 198 | require $this->cacheFile; |
| 184 | - if(!$currentModel && $baseModel) Scope::done(); |
|
| 199 | + if(!$currentModel && $baseModel) { |
|
| 200 | + Scope::done(); |
|
| 201 | + } |
|
| 185 | 202 | $this->baseModel = $baseModel; |
| 186 | 203 | $out = ob_get_contents(); |
| 187 | 204 | ob_end_clean(); |
@@ -198,8 +215,9 @@ discard block |
||
| 198 | 215 | * @return int The line number being passed by the parser |
| 199 | 216 | */ |
| 200 | 217 | static function getLineNo() { |
| 201 | - if(!isset(self::$me)) |
|
| 202 | - return 0; |
|
| 218 | + if(!isset(self::$me)) { |
|
| 219 | + return 0; |
|
| 220 | + } |
|
| 203 | 221 | return self::$me->parse->getLineNo(); |
| 204 | 222 | } |
| 205 | 223 | |
@@ -73,14 +73,16 @@ discard block |
||
| 73 | 73 | $scopeName = $m[1]; |
| 74 | 74 | $lookup = substr($this->var, 0, strlen($this->var) - strlen($m[0])); |
| 75 | 75 | $hsv = new H\Text(trim($lookup), H\Text::TOKEN_CONTROL); |
| 76 | - } else |
|
| 77 | - $hsv = new H\Text($this->var, H\Text::TOKEN_CONTROL); |
|
| 76 | + } else { |
|
| 77 | + $hsv = new H\Text($this->var, H\Text::TOKEN_CONTROL); |
|
| 78 | + } |
|
| 78 | 79 | switch ($this->type) { |
| 79 | 80 | case "each": |
| 80 | - if ($this->var) |
|
| 81 | - $out .= "foreach(" . $hsv->toPHP() . " as {$this->o}) { \n"; |
|
| 82 | - else |
|
| 83 | - $out .= "foreach(Hamle\\Scope::get() as {$this->o}) { \n"; |
|
| 81 | + if ($this->var) { |
|
| 82 | + $out .= "foreach(" . $hsv->toPHP() . " as {$this->o}) { \n"; |
|
| 83 | + } else { |
|
| 84 | + $out .= "foreach(Hamle\\Scope::get() as {$this->o}) { \n"; |
|
| 85 | + } |
|
| 84 | 86 | $out .= "Hamle\\Scope::add({$this->o}); "; |
| 85 | 87 | break; |
| 86 | 88 | case "if": |
@@ -88,9 +90,9 @@ discard block |
||
| 88 | 90 | $out .= "if(" . $hsvcomp->toPHP() . ") {"; |
| 89 | 91 | break; |
| 90 | 92 | case "with": |
| 91 | - if ($scopeName) |
|
| 92 | - $out .= "Hamle\\Scope::add(" . $hsv->toPHP() . ", \"$scopeName\");\n;"; |
|
| 93 | - else { |
|
| 93 | + if ($scopeName) { |
|
| 94 | + $out .= "Hamle\\Scope::add(" . $hsv->toPHP() . ", \"$scopeName\");\n;"; |
|
| 95 | + } else { |
|
| 94 | 96 | $out .= "if(({$this->o} = " . $hsv->toPHP() . ") && " . |
| 95 | 97 | "{$this->o}->valid()) {\n"; |
| 96 | 98 | $out .= "Hamle\\Scope::add({$this->o});\n;"; |
@@ -101,10 +103,11 @@ discard block |
||
| 101 | 103 | break; |
| 102 | 104 | case "include": |
| 103 | 105 | $file = $hsv->toHTML(); |
| 104 | - if($file[0] == "#") |
|
| 105 | - $out .= "echo Hamle\\Run::includeFragment(".$hsv->toPHP().");"; |
|
| 106 | - else |
|
| 107 | - $out .= "echo Hamle\\Run::includeFile(" . $hsv->toPHP() . ");"; |
|
| 106 | + if($file[0] == "#") { |
|
| 107 | + $out .= "echo Hamle\\Run::includeFragment(".$hsv->toPHP().");"; |
|
| 108 | + } else { |
|
| 109 | + $out .= "echo Hamle\\Run::includeFile(" . $hsv->toPHP() . ");"; |
|
| 110 | + } |
|
| 108 | 111 | break; |
| 109 | 112 | } |
| 110 | 113 | return $out . ' ?>'; |
@@ -123,8 +126,9 @@ discard block |
||
| 123 | 126 | case "each"; |
| 124 | 127 | $out .= 'Hamle\\Scope::done(); '; |
| 125 | 128 | $out .= '}'; |
| 126 | - if (!$this->var) |
|
| 127 | - $out .= "Hamle\\Scope::get()->rewind();\n"; |
|
| 129 | + if (!$this->var) { |
|
| 130 | + $out .= "Hamle\\Scope::get()->rewind();\n"; |
|
| 131 | + } |
|
| 128 | 132 | break; |
| 129 | 133 | case "if": |
| 130 | 134 | case "else": |
@@ -140,7 +144,9 @@ discard block |
||
| 140 | 144 | return ""; |
| 141 | 145 | break; |
| 142 | 146 | } |
| 143 | - if ($this->else) $out .= "else{"; |
|
| 147 | + if ($this->else) { |
|
| 148 | + $out .= "else{"; |
|
| 149 | + } |
|
| 144 | 150 | return $out . ' ?>'; |
| 145 | 151 | } |
| 146 | 152 | |
@@ -43,10 +43,12 @@ discard block |
||
| 43 | 43 | */ |
| 44 | 44 | function __construct($s) { |
| 45 | 45 | $m = array(); |
| 46 | - if (!preg_match('/^\$\((' . self::REGEX_FUNCSEL . '*)(.*)\)$/', $s, $m)) |
|
| 47 | - throw new ParseError("Unable to read \$ func in '$s'"); |
|
| 48 | - if (trim($m[2])) |
|
| 49 | - $this->sub = new FuncSub($m[2]); |
|
| 46 | + if (!preg_match('/^\$\((' . self::REGEX_FUNCSEL . '*)(.*)\)$/', $s, $m)) { |
|
| 47 | + throw new ParseError("Unable to read \$ func in '$s'"); |
|
| 48 | + } |
|
| 49 | + if (trim($m[2])) { |
|
| 50 | + $this->sub = new FuncSub($m[2]); |
|
| 51 | + } |
|
| 50 | 52 | if (!trim($m[1])) { |
| 51 | 53 | $this->scope = true; |
| 52 | 54 | return; |
@@ -63,17 +65,24 @@ discard block |
||
| 63 | 65 | $m = array(); |
| 64 | 66 | $att = array('id' => array(), 'tag' => array()); |
| 65 | 67 | foreach (explode(",", $s) as $str) { |
| 66 | - if (preg_match('/^[a-zA-Z0-9\\_]+/', $str, $m)) $type = $m[0]; |
|
| 67 | - else $type = "*"; |
|
| 68 | - if (preg_match('/#([a-zA-Z0-9\_\\${}]+)/', $str, $m)) $att['id'][$type][] = $m[1]; |
|
| 69 | - elseif (preg_match_all('/\\.([a-zA-Z0-9\_\-\\${}]+)/', $str, $m)) |
|
| 70 | - foreach ($m[1] as $tag) |
|
| 68 | + if (preg_match('/^[a-zA-Z0-9\\_]+/', $str, $m)) { |
|
| 69 | + $type = $m[0]; |
|
| 70 | + } else { |
|
| 71 | + $type = "*"; |
|
| 72 | + } |
|
| 73 | + if (preg_match('/#([a-zA-Z0-9\_\\${}]+)/', $str, $m)) { |
|
| 74 | + $att['id'][$type][] = $m[1]; |
|
| 75 | + } elseif (preg_match_all('/\\.([a-zA-Z0-9\_\-\\${}]+)/', $str, $m)) { |
|
| 76 | + foreach ($m[1] as $tag) |
|
| 71 | 77 | $att['tag'][$type][] = new Text($tag, Text::TOKEN_CODE); |
| 72 | - else $att['tag'][$type] = array(); |
|
| 78 | + } else { |
|
| 79 | + $att['tag'][$type] = array(); |
|
| 80 | + } |
|
| 73 | 81 | } |
| 74 | 82 | //var_dump($att); |
| 75 | - if (!(count($att['id']) xor count($att['tag']))) |
|
| 76 | - throw new ParseError("Only tag, type or id can be combined"); |
|
| 83 | + if (!(count($att['id']) xor count($att['tag']))) { |
|
| 84 | + throw new ParseError("Only tag, type or id can be combined"); |
|
| 85 | + } |
|
| 77 | 86 | return $att; |
| 78 | 87 | } |
| 79 | 88 | |
@@ -86,14 +95,18 @@ discard block |
||
| 86 | 95 | } |
| 87 | 96 | $rand = false; |
| 88 | 97 | if (preg_match_all('/\\^(-?)([a-zA-Z0-9\_]*)/', $s, $m)) { |
| 89 | - foreach($m[0] as $k=>$mv) |
|
| 90 | - if ($m[2][$k]) { |
|
| 98 | + foreach($m[0] as $k=>$mv) { |
|
| 99 | + if ($m[2][$k]) { |
|
| 91 | 100 | $dir = $m[1][$k] == "-"?Hamle\Hamle::SORT_DESCENDING:Hamle\Hamle::SORT_ASCENDING; |
| 101 | + } |
|
| 92 | 102 | $att['sort'][$m[2][$k]] = $dir; |
| 93 | - } else $rand = true; |
|
| 103 | + } else { |
|
| 104 | + $rand = true; |
|
| 105 | + } |
|
| 106 | + } |
|
| 107 | + if($rand) { |
|
| 108 | + $att['sort'] = [""=>$att['dir'] = Hamle\Hamle::SORT_RANDOM]; |
|
| 94 | 109 | } |
| 95 | - if($rand) |
|
| 96 | - $att['sort'] = [""=>$att['dir'] = Hamle\Hamle::SORT_RANDOM]; |
|
| 97 | 110 | return $att; |
| 98 | 111 | } |
| 99 | 112 | |
@@ -118,17 +131,19 @@ discard block |
||
| 118 | 131 | } |
| 119 | 132 | $limit = Text::varToCode($this->sortlimit['sort']) . "," . |
| 120 | 133 | $this->sortlimit['limit'] . "," . $this->sortlimit['offset']; |
| 121 | - if (count($this->filt['tag'])) |
|
| 122 | - return "Hamle\\Run::modelTypeTags(" . |
|
| 134 | + if (count($this->filt['tag'])) { |
|
| 135 | + return "Hamle\\Run::modelTypeTags(" . |
|
| 123 | 136 | Text::varToCode($this->filt['tag']) . ",$limit)$sub"; |
| 124 | - if (count($this->filt['id'])) |
|
| 125 | - if (isset($this->filt['id']['*']) && count($this->filt['id']['*']) == 1) |
|
| 137 | + } |
|
| 138 | + if (count($this->filt['id'])) { |
|
| 139 | + if (isset($this->filt['id']['*']) && count($this->filt['id']['*']) == 1) |
|
| 126 | 140 | return "Hamle\\Run::modelId(" . |
| 127 | 141 | Text::varToCode(current($this->filt['id']['*'])) . |
| 128 | 142 | ",$limit)$sub"; |
| 129 | - else |
|
| 130 | - return "Hamle\\Run::modelTypeId(" . |
|
| 143 | + } else { |
|
| 144 | + return "Hamle\\Run::modelTypeId(" . |
|
| 131 | 145 | Text::varToCode($this->filt['id']) . ",$limit)$sub"; |
| 146 | + } |
|
| 132 | 147 | return ""; |
| 133 | 148 | } |
| 134 | 149 | |
@@ -39,21 +39,27 @@ discard block |
||
| 39 | 39 | $s = substr($s,0,$pos); |
| 40 | 40 | } |
| 41 | 41 | $s = explode("->", $s); |
| 42 | - if(count($s) == 1) $s = explode("-!",$s[0]); |
|
| 43 | - if (!$s[0]) throw new ParseError("Unable to parse Complex Expression"); |
|
| 44 | - if ($s[0][1] == "(") |
|
| 45 | - $this->func = new Text\Func($s[0]); |
|
| 46 | - elseif ($s[0][1] == "[") |
|
| 47 | - $this->func = new Text\Scope($s[0]); |
|
| 48 | - else |
|
| 49 | - $this->func = new SimpleVar($s[0]); |
|
| 42 | + if(count($s) == 1) { |
|
| 43 | + $s = explode("-!",$s[0]); |
|
| 44 | + } |
|
| 45 | + if (!$s[0]) { |
|
| 46 | + throw new ParseError("Unable to parse Complex Expression"); |
|
| 47 | + } |
|
| 48 | + if ($s[0][1] == "(") { |
|
| 49 | + $this->func = new Text\Func($s[0]); |
|
| 50 | + } elseif ($s[0][1] == "[") { |
|
| 51 | + $this->func = new Text\Scope($s[0]); |
|
| 52 | + } else { |
|
| 53 | + $this->func = new SimpleVar($s[0]); |
|
| 54 | + } |
|
| 50 | 55 | array_shift($s); |
| 51 | 56 | $this->sel = $s; |
| 52 | 57 | } |
| 53 | 58 | |
| 54 | 59 | function toHTML($escape = false) { |
| 55 | - if($escape) |
|
| 56 | - return "<?=htmlspecialchars(" .$this->toPHP() . ")?>"; |
|
| 60 | + if($escape) { |
|
| 61 | + return "<?=htmlspecialchars(" .$this->toPHP() . ")?>"; |
|
| 62 | + } |
|
| 57 | 63 | return "<?=" . $this->toPHP() . "?>"; |
| 58 | 64 | } |
| 59 | 65 | function toPHP() { |
@@ -62,11 +68,13 @@ discard block |
||
| 62 | 68 | function toPHPVar() { |
| 63 | 69 | if ($this->sel) { |
| 64 | 70 | $sel = array(); |
| 65 | - foreach ($this->sel as $s) |
|
| 66 | - $sel[] = "hamleGet('$s')"; |
|
| 71 | + foreach ($this->sel as $s) { |
|
| 72 | + $sel[] = "hamleGet('$s')"; |
|
| 73 | + } |
|
| 67 | 74 | return $this->func->toPHP() . "->" . implode('->', $sel); |
| 68 | - } else |
|
| 69 | - return $this->func->toPHP(); |
|
| 75 | + } else { |
|
| 76 | + return $this->func->toPHP(); |
|
| 77 | + } |
|
| 70 | 78 | } |
| 71 | 79 | |
| 72 | 80 | } |
| 73 | 81 | \ No newline at end of file |
@@ -41,8 +41,9 @@ discard block |
||
| 41 | 41 | if(preg_match("/^([a-z]+)(\\((.*)\\))?$/", $s, $m)) { |
| 42 | 42 | $this->filter = $m[1]; |
| 43 | 43 | $this->vars = isset($m[3]) ? explode(',', $m[3]) : []; |
| 44 | - foreach($this->vars as $k=>$v) |
|
| 45 | - $this->vars[$k] = str_replace(",",',',$v); |
|
| 44 | + foreach($this->vars as $k=>$v) { |
|
| 45 | + $this->vars[$k] = str_replace(",",',',$v); |
|
| 46 | + } |
|
| 46 | 47 | } else { |
| 47 | 48 | throw new ParseError("Unable to parse filter expression \"$s\""); |
| 48 | 49 | } |
@@ -54,29 +55,33 @@ discard block |
||
| 54 | 55 | $this->filter = "Seufert\\Hamle\\Text\\Filter::{$this->filter}"; |
| 55 | 56 | } |
| 56 | 57 | $mapFilter = ['json'=>'json_encode']; |
| 57 | - if(isset($mapFilter[$this->filter])) |
|
| 58 | - $this->filter = $mapFilter[$this->filter]; |
|
| 58 | + if(isset($mapFilter[$this->filter])) { |
|
| 59 | + $this->filter = $mapFilter[$this->filter]; |
|
| 60 | + } |
|
| 59 | 61 | $this->what = $what; |
| 60 | 62 | } |
| 61 | 63 | |
| 62 | 64 | function toHTML($escape = false) { |
| 63 | - if($escape) |
|
| 64 | - return "<?=htmlspecialchars(" .$this->toPHP() . ")?>"; |
|
| 65 | + if($escape) { |
|
| 66 | + return "<?=htmlspecialchars(" .$this->toPHP() . ")?>"; |
|
| 67 | + } |
|
| 65 | 68 | return "<?=" . $this->toPHP() . "?>"; |
| 66 | 69 | } |
| 67 | 70 | |
| 68 | 71 | function toPHP() { |
| 69 | 72 | $o = [$this->what->toPHPVar()] ; |
| 70 | - foreach($this->vars as $v) |
|
| 71 | - $o[] = $this->varToCode($v); |
|
| 73 | + foreach($this->vars as $v) { |
|
| 74 | + $o[] = $this->varToCode($v); |
|
| 75 | + } |
|
| 72 | 76 | return "{$this->filter}(" . implode(',',$o) . ")"; |
| 73 | 77 | } |
| 74 | 78 | |
| 75 | 79 | static function itersplit($v, $sep = ",") { |
| 76 | 80 | $o = []; |
| 77 | 81 | foreach(explode($sep, $v) as $k=>$i) { |
| 78 | - if($i) |
|
| 79 | - $o[] = ['v'=>trim($i), 'value'=>trim($i), 'k'=>$k,'key'=>$k]; |
|
| 82 | + if($i) { |
|
| 83 | + $o[] = ['v'=>trim($i), 'value'=>trim($i), 'k'=>$k,'key'=>$k]; |
|
| 84 | + } |
|
| 80 | 85 | } |
| 81 | 86 | return new WrapArray($o); |
| 82 | 87 | } |
@@ -18,12 +18,14 @@ discard block |
||
| 18 | 18 | static $namedScopes = array(); |
| 19 | 19 | |
| 20 | 20 | static function add($model, $name = null) {
|
| 21 | - if (!$model instanceOf Model) |
|
| 22 | - throw new Unsupported("Unsupported Model (".get_class($model)."), Needs to implement hamleModel Interface");
|
|
| 23 | - if ($name) |
|
| 24 | - self::$namedScopes[$name] = $model; |
|
| 25 | - else |
|
| 26 | - self::$scopes[] = $model; |
|
| 21 | + if (!$model instanceOf Model) { |
|
| 22 | + throw new Unsupported("Unsupported Model (".get_class($model)."), Needs to implement hamleModel Interface"); |
|
| 23 | + } |
|
| 24 | + if ($name) { |
|
| 25 | + self::$namedScopes[$name] = $model; |
|
| 26 | + } else { |
|
| 27 | + self::$scopes[] = $model; |
|
| 28 | + } |
|
| 27 | 29 | } |
| 28 | 30 | |
| 29 | 31 | static function done() {
|
@@ -41,15 +43,21 @@ discard block |
||
| 41 | 43 | */ |
| 42 | 44 | static function get($id = 0) {
|
| 43 | 45 | if (0 == $id) {
|
| 44 | - if ($scope = end(self::$scopes)) |
|
| 45 | - return $scope; |
|
| 46 | + if ($scope = end(self::$scopes)) { |
|
| 47 | + return $scope; |
|
| 48 | + } |
|
| 46 | 49 | throw new OutOfScope("Unable to find Scope ($id)");
|
| 47 | 50 | } |
| 48 | 51 | $key = $id - 1; |
| 49 | - if ($id < 0) $key = count(self::$scopes) + $id - 1; |
|
| 50 | - if ($id == 0) $key = count(self::$scopes) - 1; |
|
| 51 | - if (!isset(self::$scopes[$key])) |
|
| 52 | - throw new OutOfScope("Unable to find Scope ($id) or $key");
|
|
| 52 | + if ($id < 0) { |
|
| 53 | + $key = count(self::$scopes) + $id - 1; |
|
| 54 | + } |
|
| 55 | + if ($id == 0) { |
|
| 56 | + $key = count(self::$scopes) - 1; |
|
| 57 | + } |
|
| 58 | + if (!isset(self::$scopes[$key])) { |
|
| 59 | + throw new OutOfScope("Unable to find Scope ($id) or $key"); |
|
| 60 | + } |
|
| 53 | 61 | return self::$scopes[$key]; |
| 54 | 62 | } |
| 55 | 63 | |
@@ -67,8 +75,9 @@ discard block |
||
| 67 | 75 | self::$namedScopes[$name]->rewind(); |
| 68 | 76 | return self::$namedScopes[$name]; |
| 69 | 77 | } else |
| 70 | - if(self::$returnZeroOnNoScope) |
|
| 71 | - return new Model\Zero(); |
|
| 78 | + if(self::$returnZeroOnNoScope) { |
|
| 79 | + return new Model\Zero(); |
|
| 80 | + } |
|
| 72 | 81 | throw new RunTime("Unable to find scope ($name)");
|
| 73 | 82 | } |
| 74 | 83 | |
@@ -38,17 +38,25 @@ |
||
| 38 | 38 | */ |
| 39 | 39 | function __construct($s) { |
| 40 | 40 | $m = array(); |
| 41 | - if (!preg_match('/^ +([><]) +('.self::REGEX_FUNCSEL . '+)(.*)$/', $s, $m)) |
|
| 42 | - throw new ParseError("Unable to read \$ sub func in '$s'"); |
|
| 43 | - if ($m[1] == "<") $this->dir = Hamle\Hamle::REL_PARENT; |
|
| 44 | - elseif ($m[1] == ">") $this->dir = Hamle\Hamle::REL_CHILD; |
|
| 45 | - else $this->dir = Hamle\Hamle::REL_ANY; |
|
| 41 | + if (!preg_match('/^ +([><]) +('.self::REGEX_FUNCSEL . '+)(.*)$/', $s, $m)) { |
|
| 42 | + throw new ParseError("Unable to read \$ sub func in '$s'"); |
|
| 43 | + } |
|
| 44 | + if ($m[1] == "<") { |
|
| 45 | + $this->dir = Hamle\Hamle::REL_PARENT; |
|
| 46 | + } elseif ($m[1] == ">") { |
|
| 47 | + $this->dir = Hamle\Hamle::REL_CHILD; |
|
| 48 | + } else { |
|
| 49 | + $this->dir = Hamle\Hamle::REL_ANY; |
|
| 50 | + } |
|
| 46 | 51 | $this->sortlimit = $this->attSortLimit($m[2]); |
| 47 | 52 | $this->filt = $this->attIdTag($m[2]); |
| 48 | 53 | $this->grouptype = $this->attGroupType($m[2]); |
| 49 | - if ($this->filt['id']) throw new ParseError("Unable to select by id"); |
|
| 50 | - if (trim($m[3])) |
|
| 51 | - $this->sub = new FuncSub($m[3]); |
|
| 54 | + if ($this->filt['id']) { |
|
| 55 | + throw new ParseError("Unable to select by id"); |
|
| 56 | + } |
|
| 57 | + if (trim($m[3])) { |
|
| 58 | + $this->sub = new FuncSub($m[3]); |
|
| 59 | + } |
|
| 52 | 60 | } |
| 53 | 61 | |
| 54 | 62 | /** |