151 |
if (!is_array($group)) { |
if (!is_array($group)) { |
152 |
$group = array($group); |
$group = array($group); |
153 |
} |
} |
154 |
|
// position of the element, $elem, of a $group that is currently being considered |
155 |
|
$pos = 0; |
156 |
foreach($group as $elem) { |
foreach($group as $elem) { |
157 |
if (isset($data[$elem]) && !empty($data[$elem])) { |
if (isset($data[$elem]) && !empty($data[$elem])) { |
158 |
if ($group_idx != -1 && $group_idx != $i) { // The keys from disjoint groups found in data |
if ($group_idx != -1 && $group_idx != $i) { // The keys from disjoint groups found in data |
159 |
return -1; |
return -1; |
160 |
} |
} |
161 |
|
if ($group_idx < 0 && $pos > 0) { |
162 |
|
// not all keys in a group found inside data |
163 |
|
return -1; |
164 |
|
} |
165 |
$group_idx = $i; |
$group_idx = $i; |
166 |
} else { // Not all strings in a group found insidee of data, error |
} else { // Not all strings in a group found insidee of data, error |
167 |
if ($group_idx == $i) { |
if ($group_idx == $i) { |
168 |
return -1; |
return -1; |
169 |
} |
} |
170 |
} |
} |
171 |
|
$pos++; |
172 |
} |
} |
173 |
|
|
174 |
} |
} |
176 |
} |
} |
177 |
|
|
178 |
|
|
179 |
|
/* |
180 |
|
* Send a reply depending on the result of processing of a request. |
181 |
|
* |
182 |
|
* @param string $result The result of the processing. |
183 |
|
* @param string $KO_msg String containing the error that dappened |
184 |
|
* during the processing of valid request data. |
185 |
|
*/ |
186 |
|
protected function sendReply($result, $KO_msg = null) { |
187 |
|
// if there were any errors, return an error code |
188 |
|
if ($result != 'OK') { |
189 |
|
// if there was a problem with the data itself, send the error info |
190 |
|
if ($result != 'KO') { |
191 |
|
return $this->sendHttpCode(400, $result); |
192 |
|
} |
193 |
|
// problem in processing the data |
194 |
|
return $this->sendHttpCode(500, $KO_msg); |
195 |
|
} |
196 |
|
|
197 |
|
return $this->sendHttpCode(200); |
198 |
|
} |
199 |
|
|
200 |
|
|
201 |
/* |
/* |
202 |
* Sends the return http status code. |
* Sends the return http status code. |
203 |
* @param string|int $code The code to send |
* @param string|int $code The code to send |