Oihana PHP Arango

getEdges.php

Table of Contents

Functions

getEdges()  : Edges|null
Retrieves an {@see Edges} instance from various types of input definitions.

Functions

getEdges()

Retrieves an {@see Edges} instance from various types of input definitions.

getEdges([array<string|int, mixed>|string|Edges|null $definition = null ][, ContainerInterface|null $container = null ][, string $key = Arango::EDGES ][, Edges|null $default = null ]) : Edges|null

This helper function resolves an Edges object from a direct instance, an array definition, a service name within a PSR-11 container, or falls back to a provided default value.

Behavior:

  • If $definition is an Edges instance, it is returned as-is.
  • If $definition is an array, the function looks for the Arango::EDGES key.
  • If $definition is a non-empty string and $container contains a service with that name, the corresponding service is fetched.
  • If none of the above conditions are met, the $default value is returned.
Parameters
$definition : array<string|int, mixed>|string|Edges|null = null

Input definition that may represent an Edges instance, an associative array containing one, or a container service name.

$container : ContainerInterface|null = null

Optional PSR-11 container used to resolve string service names.

$key : string = Arango::EDGES

Array key to look for when $definition is an array

$default : Edges|null = null

Default Edges instance to return if resolution fails.

Tags
throws
ContainerExceptionInterface
NotFoundExceptionInterface
example
use oihana\arango\models\helpers\getEdges;
use oihana\arango\models\Edges;
use oihana\arango\enums\Arango;
use Psr\Container\ContainerInterface;

$edges = new Edges(['_from' => 'users/1', '_to' => 'posts/5']);

// Example 1: Direct instance
$result = getEdges($edges);
// → returns the same $edges instance

// Example 2: From array definition
$result = getEdges([Arango::EDGES => $edges]);
// → returns the $edges instance from the array

// Example 3: From container service name
$container->method('has')->willReturn(true);
$container->method('get')->willReturn($edges);
$result = getEdges('my.edges.service', $container);
// → returns the $edges instance resolved from the container

// Example 4: With default fallback
$default = new Edges(['_from' => 'fallback/A', '_to' => 'fallback/B']);
$result = getEdges(null, null, $default);
// → returns $default
author

Marc Alcaraz (eKameleon)

version
1.0.0
Return values
Edges|null

Returns the resolved Edges instance or the default value if not found.

On this page

Search results