class Filter (View source)

internal  JSON:API maintains no PHP API since its API is the HTTP API. This class may change at any time and this will break any dependencies on it.
 

Gathers information about the filter parameter.

Constants

KEY_NAME

The JSON:API filter key name.

ROOT_ID

The key for the implicit root group.

CONDITION_KEY

Key in the filter[] parameter for conditions.

GROUP_KEY

Key in the filter[] parameter for groups.

MEMBER_KEY

Key in the filter[][] parameter for group membership.

Properties

protected string $root

The root condition group.

Methods

__construct(EntityConditionGroup $root)

Constructs a new Filter object.

root()

Gets the root condition group.

queryCondition(QueryInterface $query)

Applies the root condition to the given query.

buildGroup(QueryInterface $query, EntityConditionGroup $condition_group)

Applies the root condition to the given query.

static Filter
createFromQueryParameter(mixed $parameter, ResourceType $resource_type, FieldResolver $field_resolver)

Creates a Sort object from a query parameter.

static array
expand(array $original)

Expands any filter parameters using shorthand notation.

static array
expandItem(string $filter_index, array $filter_item)

Expands a filter item in case a shortcut was used.

buildEntityConditionGroup(array $items)

Denormalizes the given filter items into a single EntityConditionGroup.

buildTree(array $root, array $items)

Organizes the flat, normalized filter items into a tree structure.

Details

__construct(EntityConditionGroup $root)

Constructs a new Filter object.

Parameters

EntityConditionGroup $root

An entity condition group which can be applied to an entity query.

root()

Gets the root condition group.

ConditionInterface queryCondition(QueryInterface $query)

Applies the root condition to the given query.

Parameters

QueryInterface $query

The query for which the condition should be constructed.

Return Value

ConditionInterface

The compiled entity query condition.

protected ConditionInterface buildGroup(QueryInterface $query, EntityConditionGroup $condition_group)

Applies the root condition to the given query.

Parameters

QueryInterface $query

The query to which the filter should be applied.

EntityConditionGroup $condition_group

The condition group to build.

Return Value

ConditionInterface

The query with the filter applied.

static Filter createFromQueryParameter(mixed $parameter, ResourceType $resource_type, FieldResolver $field_resolver)

Creates a Sort object from a query parameter.

Parameters

mixed $parameter

The filter query parameter from the Symfony request object.

ResourceType $resource_type

The JSON:API resource type.

FieldResolver $field_resolver

The JSON:API field resolver.

Return Value

Filter

A Sort object with defaults.

static protected array expand(array $original)

Expands any filter parameters using shorthand notation.

Parameters

array $original

The unexpanded filter data.

Return Value

array

The expanded filter data.

static protected array expandItem(string $filter_index, array $filter_item)

Expands a filter item in case a shortcut was used.

Possible cases for the conditions:

  1. filter[uuid][value]=1234.
  2. filter[0][condition][field]=uuid&filter[0][condition][value]=1234.
  3. filter[uuid][condition][value]=1234.
  4. filter[uuid][value]=1234&filter[uuid][group]=my_group.

Parameters

string $filter_index

The index.

array $filter_item

The raw filter item.

Return Value

array

The expanded filter item.

static protected EntityConditionGroup buildEntityConditionGroup(array $items)

Denormalizes the given filter items into a single EntityConditionGroup.

Parameters

array $items

The normalized entity conditions and groups.

Return Value

EntityConditionGroup

A root group containing all the denormalized conditions and groups.

static protected EntityConditionGroup buildTree(array $root, array $items)

Organizes the flat, normalized filter items into a tree structure.

Parameters

array $root

The root of the tree to build.

array $items

The normalized entity conditions and groups.

Return Value

EntityConditionGroup

The entity condition group