Oihana PHP Arango

resolveFacetDirection.php

Table of Contents

Functions

resolveFacetDirection()  : string
Resolves the traversal direction of a linked facet: which way its edges are followed from the listed document.

Functions

resolveFacetDirection()

Resolves the traversal direction of a linked facet: which way its edges are followed from the listed document.

resolveFacetDirection(array<string|int, mixed> $facet) : string

The direction is not a detail of the AQL — it decides whether the facet finds anything at all. A model whose edges leave the document (doc is the _from) reaches its vertices OUTBOUND; one whose edges point at it reaches them INBOUND. Follow the wrong way and the traversal is perfectly valid and matches nothing, so the facet answers empty buckets in 200 without a word — the shape of silent degradation this library refuses.

Three rules, and each is deliberate:

  • the default is Traversal::INBOUND, which is what every linked facet compiled before this option existed — so a declaration that says nothing keeps its query byte for byte;
  • Traversal::ANY is accepted, and means what it says: linked in either direction. It is the right answer for a relation that is not oriented — with the caveat that a document linked both ways to the same vertex is then reached twice, so Facet::DISTINCT earns its keep;
  • an unknown value is refused, never quietly replaced. Traversal::get() would have fallen back on the default, turning a typo into empty buckets — the very failure the option exists to close — so Traversal::validate() answers instead.
Parameters
$facet : array<string|int, mixed>

The facet definition. Reads AQL::DIRECTION.

Tags
throws
ConstantException

When the declared direction is not a Traversal keyword.

example
use function oihana\arango\models\helpers\facets\resolveFacetDirection;

resolveFacetDirection( [] ) ;                                        // 'INBOUND'  (the default)
resolveFacetDirection( [ AQL::DIRECTION => Traversal::OUTBOUND ] ) ; // 'OUTBOUND'
resolveFacetDirection( [ AQL::DIRECTION => 'sideways' ] ) ;          // throws
since
1.7.0
author

Marc Alcaraz

Return values
string —

The validated direction keyword.

On this page

Search results