1 | <?php |
||
9 | class Dynamic extends AbstractParser |
||
10 | { |
||
11 | /** |
||
12 | * @var array |
||
13 | */ |
||
14 | protected $uriParts = []; |
||
15 | |||
16 | 6 | public function parseMap() |
|
21 | |||
22 | 6 | protected function parseMapForVariables() |
|
38 | |||
39 | /** |
||
40 | * @param $part |
||
41 | * @return array |
||
42 | */ |
||
43 | 4 | public function getVariableFromPart($part) |
|
73 | |||
74 | /** |
||
75 | * @param $uri |
||
76 | * @return bool |
||
77 | */ |
||
78 | 3 | public function match($uri) |
|
99 | |||
100 | /** |
||
101 | * @param $uri |
||
102 | */ |
||
103 | 3 | public function parseUriParts($uri) |
|
107 | |||
108 | /** |
||
109 | * @return bool |
||
110 | */ |
||
111 | 3 | public function getVariableParts() |
|
125 | |||
126 | /** |
||
127 | * @return bool |
||
128 | */ |
||
129 | 1 | protected function preMatch() |
|
139 | |||
140 | /** |
||
141 | * @return array |
||
142 | */ |
||
143 | 3 | public function getUriParts() |
|
147 | |||
148 | /** |
||
149 | * @param array $uriParts |
||
150 | */ |
||
151 | public function setUriParts($uriParts) |
||
155 | |||
156 | /** |
||
157 | * @return bool |
||
158 | */ |
||
159 | 3 | protected function parseParams() |
|
160 | { |
||
161 | 3 | $uriParts = $this->getUriParts(); |
|
162 | 3 | foreach ($this->parts as $key => $part) { |
|
163 | 3 | if (strstr($part, ":") === false) { |
|
164 | // part is static - no named params |
||
165 | 2 | if (!isset($uriParts[$key]) || $uriParts[$key] != $part) { |
|
166 | // corresponding part in URI does not match |
||
167 | return false; |
||
168 | } |
||
169 | } else { |
||
170 | 3 | $var = str_replace(":", "", $part); |
|
171 | 3 | $this->setParam($var, isset($uriParts[$key]) ? $uriParts[$key] : null); |
|
172 | } |
||
173 | } |
||
174 | |||
175 | 3 | return true; |
|
176 | } |
||
177 | |||
178 | /** |
||
179 | * @return bool |
||
180 | */ |
||
181 | 3 | protected function postMatch() |
|
185 | } |
||
186 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: