Cake\Controller\Component\PaginatorComponent::validateSort PHP Метод

validateSort() публичный Метод

You can use the whitelist parameter to control which columns/fields are available for sorting. This helps prevent users from ordering large result sets on un-indexed values. If you need to sort on associated columns or synthetic properties you will need to use a whitelist. Any columns listed in the sort whitelist will be implicitly trusted. You can use this to sort on synthetic columns, or columns added in custom find operations that may not exist in the schema.
public validateSort ( Cake\Datasource\RepositoryInterface $object, array $options ) : array
$object Cake\Datasource\RepositoryInterface Repository object.
$options array The pagination options being used for this request.
Результат array An array of options with sort + direction removed and replaced with order if possible.
    public function validateSort(RepositoryInterface $object, array $options)
    {
        if (isset($options['sort'])) {
            $direction = null;
            if (isset($options['direction'])) {
                $direction = strtolower($options['direction']);
            }
            if (!in_array($direction, ['asc', 'desc'])) {
                $direction = 'asc';
            }
            $options['order'] = [$options['sort'] => $direction];
        }
        unset($options['sort'], $options['direction']);
        if (empty($options['order'])) {
            $options['order'] = [];
        }
        if (!is_array($options['order'])) {
            return $options;
        }
        $inWhitelist = false;
        if (isset($options['sortWhitelist'])) {
            $field = key($options['order']);
            $inWhitelist = in_array($field, $options['sortWhitelist'], true);
            if (!$inWhitelist) {
                $options['order'] = [];
                return $options;
            }
        }
        $options['order'] = $this->_prefix($object, $options['order'], $inWhitelist);
        return $options;
    }