Oihana PHP Arango

parseFilterSegment.php

Table of Contents

Functions

parseFilterSegment()  : FilterPath|null
Parse a single path segment from hierarchical configuration.

Functions

parseFilterSegment()

Parse a single path segment from hierarchical configuration.

parseFilterSegment(string $segment, array<string|int, mixed> $filters[, array<string|int, mixed> $edges = [] ][, array<string|int, mixed> $joins = [] ][, array<string|int, mixed> $parentPath = [] ][, ContainerInterface|null $container = null ]) : FilterPath|null

This function analyzes a filter path segment and determines its type (simple field, document, array expansion, edge, or join). It validates the segment against the configuration and, for edges and joins, resolves nested relations from target models.

Key Features:

  • Validates array notation consistency (e.g., employee[*] must be of type EDGES/JOINS/ARRAY_EXPANSION)
  • Resolves nested edges/joins from target models for multi-level traversals
  • Supports both explicit relation references (via AQL::RELATION) and implicit (segment key)
  • Accumulates full path for better error reporting

Nested Relations Resolution: For edges, the function:

  1. Gets the edge model from the container
  2. Determines target model based on traversal direction (INBOUND → from, OUTBOUND → to)
  3. Extracts edges/joins from target model
  4. Merges with explicit nested relations from edge configuration

For joins, the function:

  1. Gets the join target model from the container
  2. Extracts edges/joins from target model
Parameters
$segment : string

Current path segment (e.g., "employee[*]", "address", "workLocation")

$filters : array<string|int, mixed>

Current level AQL::FILTERS configuration

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

Available edges configuration at current level

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

Available joins configuration at current level

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

Accumulated path from parent segments for error reporting

$container : ContainerInterface|null = null

DI container for resolving target models and their relations

Tags
throws
RuntimeException

If relation reference is not found in edges/joins configuration

ContainerExceptionInterface

If container encounters an error resolving models

NotFoundExceptionInterface

If target model is not found in container

example
// Simple field
$info = parseFilterSegment('email', ['email' => FilterType::STRING], [], [], []);
// → type: 'string', path: ['email'], nestedEdges: [], nestedJoins: []

// Custom callable
$customFilter = fn($init, &$binds, $doc) => "LOWER($doc.name) == 'test'";
$info = parseFilterSegment('custom', ['custom' => $customFilter], [], [], []);
// → type: Closure, path: ['custom']

// Edge with nested relations
$info = parseFilterSegment(
    'employee[*]',
    ['employee' => ['type' => Filter::EDGES, 'filters' => [...]]],
    ['employee' => ['model' => Models::EMPLOYEE_EDGE]],
    [],
    [],
    $container
);
// → type: 'edges', path: ['employee'], nestedEdges: [...from target model...], nestedJoins: [...]
Return values
FilterPath|null

Parsed segment information with nested relations, or null if segment is not allowed

On this page

Search results