@@ -76,9 +76,10 @@ discard block |
||
76 | 76 | } |
77 | 77 | array_shift($path); |
78 | 78 | } |
79 | - foreach ($this->tags as $tag) |
|
80 | - if ($found = $tag->find($path)) |
|
81 | - $list = array_merge($list, $found); |
|
79 | + foreach ($this->tags as $tag) { |
|
80 | + if ($found = $tag->find($path)) |
|
81 | + $list = array_merge($list, $found); |
|
82 | + } |
|
82 | 83 | return $list; |
83 | 84 | } |
84 | 85 | |
@@ -90,7 +91,9 @@ discard block |
||
90 | 91 | */ |
91 | 92 | function replace($path, Tag $newTag) { |
92 | 93 | if ($this->compare($path[0])) { |
93 | - if (count($path) == 1) return $newTag; |
|
94 | + if (count($path) == 1) { |
|
95 | + return $newTag; |
|
96 | + } |
|
94 | 97 | array_shift($path); |
95 | 98 | } |
96 | 99 | foreach ($this->tags as $k => $tag) { |
@@ -103,21 +106,25 @@ discard block |
||
103 | 106 | } |
104 | 107 | |
105 | 108 | function addSnipContent($contentTag, &$tagArray = array(), $key = 0) { |
106 | - foreach ($this->tags as $k => $tag) |
|
107 | - $tag->addSnipContent($contentTag, $this->tags, $k); |
|
109 | + foreach ($this->tags as $k => $tag) { |
|
110 | + $tag->addSnipContent($contentTag, $this->tags, $k); |
|
111 | + } |
|
108 | 112 | } |
109 | 113 | |
110 | 114 | function compare($tic) { |
111 | - if (isset($tic['type']) && $this->type != $tic['type']) |
|
112 | - return false; |
|
115 | + if (isset($tic['type']) && $this->type != $tic['type']) { |
|
116 | + return false; |
|
117 | + } |
|
113 | 118 | if (isset($tic['id']) && |
114 | 119 | !(isset($this->opt['id']) && $tic['id'] == $this->opt['id']) |
115 | - ) |
|
116 | - return false; |
|
120 | + ) { |
|
121 | + return false; |
|
122 | + } |
|
117 | 123 | if (isset($tic['class']) && !(isset($this->opt['class']) |
118 | 124 | && !array_diff($tic['class'], $this->opt['class'])) |
119 | - ) |
|
120 | - return false; |
|
125 | + ) { |
|
126 | + return false; |
|
127 | + } |
|
121 | 128 | return true; |
122 | 129 | } |
123 | 130 | |
@@ -127,10 +134,11 @@ discard block |
||
127 | 134 | * @param string $mode Mode to add child [append|prepend] |
128 | 135 | */ |
129 | 136 | function addChild(Tag $tag, $mode = "append") { |
130 | - if ($mode == "prepend") |
|
131 | - array_unshift($this->tags, $tag); |
|
132 | - else |
|
133 | - $this->tags[] = $tag; |
|
137 | + if ($mode == "prepend") { |
|
138 | + array_unshift($this->tags, $tag); |
|
139 | + } else { |
|
140 | + $this->tags[] = $tag; |
|
141 | + } |
|
134 | 142 | } |
135 | 143 | |
136 | 144 | /** |
@@ -145,9 +153,12 @@ discard block |
||
145 | 153 | $ind = $doIndent ? str_pad("", $indent, " ") : ""; |
146 | 154 | $oneliner = ((count($this->content) > 1 || $this->tags) ? false : true); |
147 | 155 | $out = $ind . $this->renderStTag() . ($oneliner ? "" : "\n"); |
148 | - if ($this->content) $out .= $this->renderContent($ind, $oneliner); |
|
149 | - foreach ($this->tags as $tag) |
|
150 | - $out .= $tag->render($indent + self::INDENT_SIZE); |
|
156 | + if ($this->content) { |
|
157 | + $out .= $this->renderContent($ind, $oneliner); |
|
158 | + } |
|
159 | + foreach ($this->tags as $tag) { |
|
160 | + $out .= $tag->render($indent + self::INDENT_SIZE); |
|
161 | + } |
|
151 | 162 | $out .= ($oneliner ? "" : $ind) . $this->renderEnTag() . "\n"; |
152 | 163 | return $out; |
153 | 164 | } |
@@ -161,8 +172,9 @@ discard block |
||
161 | 172 | */ |
162 | 173 | function renderContent($pad = "", $oneliner = false) { |
163 | 174 | $out = ""; |
164 | - foreach ($this->content as $c) |
|
165 | - $out .= ($oneliner ? "" : $pad) . $c . ($oneliner ? "" : "\n"); |
|
175 | + foreach ($this->content as $c) { |
|
176 | + $out .= ($oneliner ? "" : $pad) . $c . ($oneliner ? "" : "\n"); |
|
177 | + } |
|
166 | 178 | return $out; |
167 | 179 | } |
168 | 180 |
@@ -36,14 +36,18 @@ |
||
36 | 36 | function getInputAttDynamic(&$atts, &$type, &$content) { |
37 | 37 | parent::getInputAttDynamic($atts, $type, $content); |
38 | 38 | $atts['value'] = "ON"; |
39 | - if ($this->getValue()) |
|
40 | - $atts['checked'] = "checked"; |
|
39 | + if ($this->getValue()) { |
|
40 | + $atts['checked'] = "checked"; |
|
41 | + } |
|
41 | 42 | } |
42 | 43 | |
43 | 44 | function getValue() { |
44 | - if (!is_null($this->setValue)) return $this->setValue; |
|
45 | - if (isset($_REQUEST[$this->form . "__submit"])) |
|
46 | - return isset($_REQUEST[$this->form . "_" . $this->name]); |
|
45 | + if (!is_null($this->setValue)) { |
|
46 | + return $this->setValue; |
|
47 | + } |
|
48 | + if (isset($_REQUEST[$this->form . "__submit"])) { |
|
49 | + return isset($_REQUEST[$this->form . "_" . $this->name]); |
|
50 | + } |
|
47 | 51 | return $this->opt['default']; |
48 | 52 | } |
49 | 53 | } |
50 | 54 | \ No newline at end of file |
@@ -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 |
@@ -108,22 +108,25 @@ discard block |
||
108 | 108 | $revSnip = array(); |
109 | 109 | /** @var Tag $roots */ |
110 | 110 | $roots = array(); |
111 | - foreach ($this->root as $snip) |
|
112 | - if ($snip instanceOf Tag\Snippet) { |
|
111 | + foreach ($this->root as $snip) { |
|
112 | + if ($snip instanceOf Tag\Snippet) { |
|
113 | 113 | if ($snip->getType() == "append") { |
114 | - array_unshift($revSnip, $snip); |
|
114 | + array_unshift($revSnip, $snip); |
|
115 | + } |
|
115 | 116 | } else { |
116 | 117 | $fwdSnip[] = $snip; |
117 | 118 | } |
118 | 119 | } else { |
119 | 120 | $roots[] = $snip; |
120 | 121 | } |
121 | - foreach ($fwdSnip as $snip) |
|
122 | - foreach ($roots as $root) |
|
123 | - $snip->apply($root); |
|
124 | - foreach ($revSnip as $snip) |
|
125 | - foreach ($roots as $root) |
|
126 | - $snip->apply($root); |
|
122 | + foreach ($fwdSnip as $snip) { |
|
123 | + foreach ($roots as $root) |
|
124 | + $snip->apply($root); |
|
125 | + } |
|
126 | + foreach ($revSnip as $snip) { |
|
127 | + foreach ($roots as $root) |
|
128 | + $snip->apply($root); |
|
129 | + } |
|
127 | 130 | $this->root = $roots; |
128 | 131 | } |
129 | 132 | |
@@ -143,9 +146,11 @@ discard block |
||
143 | 146 | $heir = array(); |
144 | 147 | while ($this->lineNo < $this->lineCount) { |
145 | 148 | $line = $this->lines[$this->lineNo]; |
146 | - if (trim($line)) if (preg_match(self::REGEX_PARSE_LINE, $line, $m)) { |
|
149 | + if (trim($line)) { |
|
150 | + if (preg_match(self::REGEX_PARSE_LINE, $line, $m)) { |
|
147 | 151 | if (FALSE !== strpos($m[1], "\t")) |
148 | - throw new ParseError("Tabs are not supported in templates at this time"); |
|
152 | + throw new ParseError("Tabs are not supported in templates at this time"); |
|
153 | + } |
|
149 | 154 | $indent = strlen($m[1]); |
150 | 155 | $tag = isset($m[2]) ? $tag = $m[2] : ""; |
151 | 156 | $classid = isset($m[3]) ? $m[3] : ""; |
@@ -157,13 +162,13 @@ discard block |
||
157 | 162 | unset($m[0]); |
158 | 163 | switch (strlen($code) ? $code[0] : ($textcode ? $textcode : "")) { |
159 | 164 | case "|": //Control Tag |
160 | - if ($code == "|snippet") |
|
161 | - $hTag = new Tag\Snippet($text); |
|
162 | - elseif ($code == "|form") |
|
163 | - $hTag = new Tag\Form($text); |
|
164 | - elseif ($code == "|formhint") |
|
165 | - $hTag = new Tag\FormHint($text); |
|
166 | - elseif ($code == "|else") { |
|
165 | + if ($code == "|snippet") { |
|
166 | + $hTag = new Tag\Snippet($text); |
|
167 | + } elseif ($code == "|form") { |
|
168 | + $hTag = new Tag\Form($text); |
|
169 | + } elseif ($code == "|formhint") { |
|
170 | + $hTag = new Tag\FormHint($text); |
|
171 | + } elseif ($code == "|else") { |
|
167 | 172 | $hTag = new Tag\Control(substr($code, 1), $heir[$i - 1]); |
168 | 173 | $hTag->setVar($text); |
169 | 174 | } else { |
@@ -174,8 +179,9 @@ discard block |
||
174 | 179 | case ":": //Filter Tag |
175 | 180 | $hTag = new Tag\Filter(substr($code, 1)); |
176 | 181 | $hTag->addContent($text, Text::TOKEN_CODE); |
177 | - foreach ($this->consumeBlock($indent) as $l) |
|
178 | - $hTag->addContent($l, Text::TOKEN_CODE); |
|
182 | + foreach ($this->consumeBlock($indent) as $l) { |
|
183 | + $hTag->addContent($l, Text::TOKEN_CODE); |
|
184 | + } |
|
179 | 185 | break; |
180 | 186 | case "_": //String Tag |
181 | 187 | case "__": //Unescape String Tag |
@@ -186,8 +192,9 @@ discard block |
||
186 | 192 | case "//": // Non Printed Comment |
187 | 193 | $hTag = new Tag\Comment($textcode); |
188 | 194 | $hTag->addContent($text); |
189 | - foreach ($this->consumeBlock($indent) as $l) |
|
190 | - $hTag->addContent($l, Text::TOKEN_CODE); |
|
195 | + foreach ($this->consumeBlock($indent) as $l) { |
|
196 | + $hTag->addContent($l, Text::TOKEN_CODE); |
|
197 | + } |
|
191 | 198 | break; |
192 | 199 | default: |
193 | 200 | $attr = array(); |
@@ -198,33 +205,43 @@ discard block |
||
198 | 205 | } |
199 | 206 | $class = array(); $id = ""; $ref = ""; |
200 | 207 | preg_match_all('/[#\.!][a-zA-Z0-9\-\_]+/m', $classid, $cid); |
201 | - if (isset($cid[0])) foreach ($cid[0] as $s) { |
|
202 | - if ($s[0] == "#") $id = substr($s, 1); |
|
203 | - if ($s[0] == ".") $class[] = substr($s, 1); |
|
204 | - if ($s[0] == "!") $ref = substr($s, 1); |
|
208 | + if (isset($cid[0])) { |
|
209 | + foreach ($cid[0] as $s) { |
|
210 | + if ($s[0] == "#") $id = substr($s, 1); |
|
211 | + } |
|
212 | + if ($s[0] == ".") { |
|
213 | + $class[] = substr($s, 1); |
|
214 | + } |
|
215 | + if ($s[0] == "!") { |
|
216 | + $ref = substr($s, 1); |
|
217 | + } |
|
205 | 218 | } |
206 | - if($ref) |
|
207 | - $hTag = new Tag\DynHtml($tag, $class, $attr, $id, $ref); |
|
208 | - else |
|
209 | - $hTag = new Tag\Html($tag, $class, $attr, $id); |
|
219 | + if($ref) { |
|
220 | + $hTag = new Tag\DynHtml($tag, $class, $attr, $id, $ref); |
|
221 | + } else { |
|
222 | + $hTag = new Tag\Html($tag, $class, $attr, $id); |
|
223 | + } |
|
210 | 224 | $hTag->addContent($text); |
211 | 225 | break; |
212 | 226 | } |
213 | 227 | $heir[$i] = $hTag; |
214 | - if ($i > 0) |
|
215 | - $heir[$i - 1]->addChild($hTag); |
|
216 | - else |
|
217 | - $this->root[] = $hTag; |
|
218 | - } else |
|
219 | - throw new ParseError("Unable to parse line {$this->lineNo}\n\"$line\"/" . preg_last_error()); |
|
228 | + if ($i > 0) { |
|
229 | + $heir[$i - 1]->addChild($hTag); |
|
230 | + } else { |
|
231 | + $this->root[] = $hTag; |
|
232 | + } |
|
233 | + } else { |
|
234 | + throw new ParseError("Unable to parse line {$this->lineNo}\n\"$line\"/" . preg_last_error()); |
|
235 | + } |
|
220 | 236 | $this->lineNo++; |
221 | 237 | } |
222 | 238 | } |
223 | 239 | |
224 | 240 | function output() { |
225 | 241 | $out = "<?php\nuse Seufert\\Hamle;\n?>"; |
226 | - foreach ($this->root as $tag) |
|
227 | - $out .= $tag->render(); |
|
242 | + foreach ($this->root as $tag) { |
|
243 | + $out .= $tag->render(); |
|
244 | + } |
|
228 | 245 | return $out; |
229 | 246 | |
230 | 247 | } |
@@ -236,15 +253,18 @@ discard block |
||
236 | 253 | (!trim($this->lines[$this->lineNo + 1]) || |
237 | 254 | preg_match('/^(\s){' . $indent . '}((\s)+[^\s].*)$/', |
238 | 255 | $this->lines[$this->lineNo + 1], $m))) { |
239 | - if (trim($this->lines[$this->lineNo + 1])) |
|
240 | - $out[] = $m[2]; |
|
256 | + if (trim($this->lines[$this->lineNo + 1])) { |
|
257 | + $out[] = $m[2]; |
|
258 | + } |
|
241 | 259 | $this->lineNo++; |
242 | 260 | } |
243 | 261 | return $out; |
244 | 262 | } |
245 | 263 | |
246 | 264 | function indentLevel($indent) { |
247 | - if (!isset($this->indents)) $this->indents = array(); |
|
265 | + if (!isset($this->indents)) { |
|
266 | + $this->indents = array(); |
|
267 | + } |
|
248 | 268 | if (!count($this->indents)) { |
249 | 269 | $this->indents = array(0 => $indent); |
250 | 270 | // Key = indent level, Value = Depth in spaces |
@@ -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 |
@@ -54,23 +54,26 @@ |
||
54 | 54 | } |
55 | 55 | |
56 | 56 | function toHTML($escape = false) { |
57 | - if($escape) |
|
58 | - return "<?=htmlspecialchars(" .$this->toPHP() . ")?>"; |
|
57 | + if($escape) { |
|
58 | + return "<?=htmlspecialchars(" .$this->toPHP() . ")?>"; |
|
59 | + } |
|
59 | 60 | return "<?=" . $this->toPHP() . "?>"; |
60 | 61 | } |
61 | 62 | |
62 | 63 | function toPHP() { |
63 | 64 | $o = [$this->what->toPHPVar()] ; |
64 | - foreach($this->vars as $v) |
|
65 | - $o[] = $this->varToCode($v); |
|
65 | + foreach($this->vars as $v) { |
|
66 | + $o[] = $this->varToCode($v); |
|
67 | + } |
|
66 | 68 | return "{$this->filter}(" . implode(',',$o) . ")"; |
67 | 69 | } |
68 | 70 | |
69 | 71 | static function iterSplit($v, $sep = ",") { |
70 | 72 | $o = []; |
71 | 73 | foreach(explode($sep, $v) as $k=>$i) { |
72 | - if($i) |
|
73 | - $o[] = ['v'=>trim($i), 'value'=>trim($i), 'k'=>$k,'key'=>$k]; |
|
74 | + if($i) { |
|
75 | + $o[] = ['v'=>trim($i), 'value'=>trim($i), 'k'=>$k,'key'=>$k]; |
|
76 | + } |
|
74 | 77 | } |
75 | 78 | return new WrapArray($o); |
76 | 79 | } |