@@ -86,13 +86,13 @@ discard block |
||
86 | 86 | } |
87 | 87 | $rand = false; |
88 | 88 | if (preg_match_all('/\\^(-?)([a-zA-Z0-9\_]*)/', $s, $m)) { |
89 | - foreach($m[0] as $k=>$mv) |
|
89 | + foreach ($m[0] as $k=>$mv) |
|
90 | 90 | if ($m[2][$k]) { |
91 | - $dir = $m[1][$k] == "-"?Hamle\Hamle::SORT_DESCENDING:Hamle\Hamle::SORT_ASCENDING; |
|
91 | + $dir = $m[1][$k] == "-" ? Hamle\Hamle::SORT_DESCENDING : Hamle\Hamle::SORT_ASCENDING; |
|
92 | 92 | $att['sort'][$m[2][$k]] = $dir; |
93 | 93 | } else $rand = true; |
94 | 94 | } |
95 | - if($rand) |
|
95 | + if ($rand) |
|
96 | 96 | $att['sort'] = [""=>$att['dir'] = Hamle\Hamle::SORT_RANDOM]; |
97 | 97 | return $att; |
98 | 98 | } |
@@ -111,9 +111,9 @@ discard block |
||
111 | 111 | */ |
112 | 112 | function toPHP() { |
113 | 113 | $sub = $this->sub ? "->" . $this->sub->toPHP() : ""; |
114 | - if($this->scope instanceof Scope) { |
|
114 | + if ($this->scope instanceof Scope) { |
|
115 | 115 | return $this->scope->toPHP() . $sub; |
116 | - } elseif($this->scope === true) { |
|
116 | + } elseif ($this->scope === true) { |
|
117 | 117 | return "Hamle\\Scope::get(0)$sub"; |
118 | 118 | } |
119 | 119 | $limit = Text::varToCode($this->sortlimit['sort']) . "," . |
@@ -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 |