@@ -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]; |