protected function RestWSBaseFormat::splitParameters in RESTful Web Services 7.2
Splits a query parameter into two sub arrays containing the filters and meta controls.
Parameters
array $properties: An array containing the properties of the resource.
array $parameters: An array which contains filters and meta controls.
Return value
array An array containing two sub arrays, one for filters and one for meta controls with corresponding keys.
Throws
RestWSException If a filter isn't valid, the function will throw a RestWSException with the 412 HTTP status code.
2 calls to RestWSBaseFormat::splitParameters()
- RestWSBaseFormat::queryResource in ./
restws.formats.inc - Implements RestWSFormatInterface::queryResource().
- RestWSFormatXML::queryResource in ./
restws.formats.inc - Overrides RestWSBaseFormat::queryResource().
File
- ./
restws.formats.inc, line 356 - RESTful web services module formats.
Class
- RestWSBaseFormat
- A base for all simple formats that are just serializing/unserializing an array of property values.
Code
protected function splitParameters($properties, array $parameters) {
$meta_controls = array();
$rest_controls = restws_meta_controls();
foreach ($parameters as $control_name => $property) {
if (isset($rest_controls[$control_name])) {
$meta_controls[$control_name] = $property;
unset($parameters[$control_name]);
}
}
$filters = array();
foreach ($parameters as $parameter => $value) {
// Check if the property is prefixed.
if (substr($parameter, 0, 9) == 'property_') {
$parameter = substr($parameter, 9, strlen($parameter) - 9);
}
// If the parameter doesn't exist, we can not filter for and need to
// notify the client about it.
if (!isset($properties[$parameter])) {
throw new RestWSException('Not a valid filter: ' . $parameter, 412);
}
$filters[$parameter] = $value;
}
return array(
'meta_controls' => $meta_controls,
'filters' => $filters,
);
}