- Модуль: rest
- Путь к файлу: ~/bitrix/modules/rest/classes/general/rest.php
- Класс: IRestService
- Вызов: IRestService::sanitizeOrder
static function sanitizeOrder($order, array $availableFields = null)
{
if(!is_array($order))
{
throw new RestException('The order is not an array.', RestException::ERROR_ARGUMENT, CRestServer::STATUS_WRONG_REQUEST);
}
$order = array_change_key_case($order, CASE_UPPER);
foreach($order as $key => $value)
{
if(!is_numeric($key))
{
if($availableFields !== null && !in_array($key, $availableFields))
{
throw new RestException('Order field not allowed: '.$key, RestException::ERROR_ARGUMENT, CRestServer::STATUS_WRONG_REQUEST);
}
if(!in_array(ToUpper($value), array('ASC', 'DESC')))
{
throw new RestException('Order direction should be one of {ASC|DESC}', RestException::ERROR_ARGUMENT, CRestServer::STATUS_WRONG_REQUEST);
}
}
elseif($availableFields !== null && !in_array($value, $availableFields))
{
throw new RestException('Order field not allowed: '.$value, RestException::ERROR_ARGUMENT, CRestServer::STATUS_WRONG_REQUEST);
}
}
return $order;
}