Oihana PHP

PrepareFilter

Prepares the `filter` parameter of a controller request.

This trait expects the ControllerParam::FILTER query parameter to be a JSON encoded object or list. When it is valid, the decoded structure is returned and the raw JSON string is recorded in the parameter bag. A filter that cannot be read — not JSON, or JSON that is neither an object nor a list — is refused with an Error400: ignoring it would answer the whole, unfiltered collection as if it were the filtered one. An absent or empty parameter, or the JSON null, means "no filter": the route argument value (or null) is returned instead.

Tags
author

Marc Alcaraz (ekameleon)

since
1.0.0

Table of Contents

Methods

prepareFilter()  : array<string|int, mixed>|null
Prepares and returns the `filter` parameter.

Methods

prepareFilter()

Prepares and returns the `filter` parameter.

protected prepareFilter(ServerRequestInterface|null $request[, array<string|int, mixed> $args = [] ][, array<string|int, mixed>|null &$params = null ]) : array<string|int, mixed>|null
Parameters
$request : ServerRequestInterface|null

The incoming PSR-7 server request, or null when no request context is available.

$args : array<string|int, mixed> = []

The route/controller arguments that may carry a fallback filter value.

$params : array<string|int, mixed>|null = null

A reference to the parameter bag updated in place with the raw JSON filter string.

Tags
throws
Error400

If the filter parameter is not valid JSON, or is JSON but neither an object nor a list.

Return values
array<string|int, mixed>|null —

The decoded filter definition, or the fallback argument value when no filter is provided.

On this page

Search results