Oihana PHP Arango

resolveFacetValue.php

Table of Contents

Functions

resolveFacetValue()  : array{0: mixed, 1: mixed, 2: mixed}|null
Reads a facet value coming from the URL, letting the `{op, val, alt}` request object override the operator and the `alt` chain declared in the facet definition.

Functions

resolveFacetValue()

Reads a facet value coming from the URL, letting the `{op, val, alt}` request object override the operator and the `alt` chain declared in the facet definition.

resolveFacetValue(mixed $value, mixed $op, mixed $alt) : array{0: mixed, 1: mixed, 2: mixed}|null

A facet accepts two shapes on the wire — the bare value (?facets={"author":"alice"}) and the object form (?facets={"author":{"op":"like","val":"al"}}). Only the object form may override the configuration, and only through the keys it actually carries: the caller passes its already-resolved defaults in, and gets back the triplet to keep working with.

An associative array is the object form; a list is a multi-value bare value (["alice","bob"]) and travels untouched.

The presence of val is tested with array_key_exists(), not isset(), so an explicit {"op":"eq","val":null} is honoured as a null value rather than read as a missing one. An object form with no val at all cannot be compared against anything: the helper returns null and the caller drops the facet — which is why the abandon signal is a null return, and not a null value.

Parameters
$value : mixed

The raw facet value from the request.

$op : mixed

The operator declared by the facet definition, used unless overridden.

$alt : mixed

The alt chain declared by the facet definition, used unless overridden.

Tags
example
use function oihana\arango\models\helpers\facets\resolveFacetValue;

resolveFacetValue( 'alice' , 'eq' , null ) ;                              // [ 'eq' , null , 'alice' ]
resolveFacetValue( [ 'op' => 'like' , 'val' => 'al' ] , 'eq' , null ) ;   // [ 'like' , null , 'al' ]
resolveFacetValue( [ 'op' => 'like' ] , 'eq' , null ) ;                   // null — nothing to compare
resolveFacetValue( [ 'alice' , 'bob' ] , 'eq' , null ) ;                  // [ 'eq' , null , ['alice','bob'] ]
since
1.6.0
author

Marc Alcaraz

Return values
array{0: mixed, 1: mixed, 2: mixed}|null

The [ op , alt , value ] triplet to carry on with, or null when the request object carries no val and the facet has nothing to compare.

On this page

Search results