Oihana PHP

PrepareFacets uses trait:short

Prepares the facet definitions of a controller request.

This trait merges the facets carried by the route arguments with two request-driven sources: the per-parameter facet definitions declared in the controller params mapping (see prepareParamsFacets()), and a raw JSON facets query parameter. Each contributing query value is URL-encoded and recorded in the parameter bag, while invalid JSON is logged as a warning and ignored.

Tags
author

Marc Alcaraz (ekameleon)

since
1.0.0

Table of Contents

Properties

$params  : array<string|int, mixed>|null
The default parameters definition.

Methods

initializeParams()  : static
Initializes the params definition from an array.
prepareFacets()  : array<string|int, mixed>|null
Prepares and returns the facet definitions.
prepareParamsFacets()  : void
Try to creates the facets definition with the $this->params array definition of the controller.

Properties

$params

The default parameters definition.

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

Methods

initializeParams()

Initializes the params definition from an array.

public initializeParams([array<string|int, mixed> $init = [] ]) : static
Parameters
$init : array<string|int, mixed> = []

Initialization array, read from the ControllerParam::PARAMS key.

Return values
static

Returns the current instance for method chaining.

prepareFacets()

Prepares and returns the facet definitions.

protected prepareFacets(ServerRequestInterface|null $request[, array<string|int, mixed> $args = [] ][, array<string|int, mixed>|null &$params = [] ]) : 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 an initial set of facets.

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

A reference to the parameter bag updated in place with the URL-encoded facet payloads.

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

The merged facet definitions.

prepareParamsFacets()

Try to creates the facets definition with the $this->params array definition of the controller.

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

Target all 'facets' definitions.

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, optionally carrying a ControllerParam::PARAMS mapping.

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

A reference to the facet collection enriched in place from the matching query parameters.

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

A reference to the parameter bag updated in place with the URL-encoded facet payloads.

Tags
example

To list with the controller multiple things by ids, you can invoke the route url : https://myapi/products?id=[12,255,300]

1 - Initialize the facets in the model definition :

FACETS =>
[
    Prop::ID =>
    [
         Facet::TYPE       => Facet::IN ,
         Facet::EXPRESSION => [ SQL::COLUMN => $primaryKey , SQL::TABLE => $tableAlias , SQL::ALTER => StringFunction::RTRIM   ] ,
    ] ,
]

2 - Defines the paramters behavior in the controller definition :

ControllerParam::PARAMS => [ Prop::ID => ControllerParam::FACETS ]
On this page

Search results