InheritancesResolverService

Resolve declared inheritances within a configuration array

Basic concept:

  • Take a large YAML config and replace the key '__inheritances' by the referenced YAML partial (of the same config file)
  • Maybe also override some keys of the referenced partial
  • Avoid endless loop by reference cycles

e.g.

Form: part1: key1: value1 key2: value2 key3: value3 part2: __inheritances: 10: Form.part1 key2: another_value

will result in:

Form: part1: key1: value1 key2: value2 key3: value3 part2: key1: value1 key2: another_value key3: value3


Scope: frontend / backend

Internal

Table of Contents

Constants

INHERITANCE_OPERATOR  = '__inheritances'
The operator which is used to declare inheritances

Properties

$inheritancePathToCheck  : string
Needed to buffer a configuration path for cyclically inheritances detection while inheritances for this path is ongoing.
$inheritanceStack  : array<string|int, mixed>
This stack is needed to find cyclically inheritances which are on the same nesting level but which do not follow each other directly.
$referenceConfiguration  : array<string|int, mixed>
The reference configuration is used to get untouched values which can be merged into the touched configuration.

Methods

create()  : InheritancesResolverService
Returns an instance of this service. Additionally the configuration which should be resolved can be passed.
getResolvedConfiguration()  : array<string|int, mixed>
Resolve all inheritances within a configuration.
reset()  : InheritancesResolverService
Reset the state of this service.
setReferenceConfiguration()  : InheritancesResolverService
Set the reference configuration which is used to get untouched values which can be merged into the touched configuration.
getValueByPath()  : string|array<string|int, mixed>|null
Check the given array representation of a YAML config for the given path and return it's value / sub-array.
removeInheritanceOperatorRecursive()  : array<string|int, mixed>
Recursively remove self::INHERITANCE_OPERATOR keys
removeVendorNamespaceFromInheritancePath()  : string
resolve()  : array<string|int, mixed>
Resolve all inheritances within a configuration.
resolveInheritancesRecursive()  : array<string|int, mixed>
Additional helper for the resolve method.
throwExceptionIfCycleInheritances()  : mixed
Throw an exception if a cycle is detected.

Constants

INHERITANCE_OPERATOR

The operator which is used to declare inheritances

public mixed INHERITANCE_OPERATOR = '__inheritances'

Properties

$inheritancePathToCheck

Needed to buffer a configuration path for cyclically inheritances detection while inheritances for this path is ongoing.

protected string $inheritancePathToCheck = ''

$inheritanceStack

This stack is needed to find cyclically inheritances which are on the same nesting level but which do not follow each other directly.

protected array<string|int, mixed> $inheritanceStack = []

$referenceConfiguration

The reference configuration is used to get untouched values which can be merged into the touched configuration.

protected array<string|int, mixed> $referenceConfiguration = []

Methods

create()

Returns an instance of this service. Additionally the configuration which should be resolved can be passed.

public static create([array<string|int, mixed> $configuration = [] ]) : InheritancesResolverService
Parameters
$configuration : array<string|int, mixed> = []
Internal
Return values
InheritancesResolverService

getResolvedConfiguration()

Resolve all inheritances within a configuration.

public getResolvedConfiguration() : array<string|int, mixed>

After that the configuration array is cleaned from the inheritance operator.

Internal
Return values
array<string|int, mixed>

setReferenceConfiguration()

Set the reference configuration which is used to get untouched values which can be merged into the touched configuration.

public setReferenceConfiguration(array<string|int, mixed> $referenceConfiguration) : InheritancesResolverService
Parameters
$referenceConfiguration : array<string|int, mixed>
Return values
InheritancesResolverService

getValueByPath()

Check the given array representation of a YAML config for the given path and return it's value / sub-array.

protected getValueByPath(array<string|int, mixed> $config, string $path[, string $delimiter = '.' ]) : string|array<string|int, mixed>|null

If path is not found, return null;

Parameters
$config : array<string|int, mixed>
$path : string
$delimiter : string = '.'
Return values
string|array<string|int, mixed>|null

removeInheritanceOperatorRecursive()

Recursively remove self::INHERITANCE_OPERATOR keys

protected removeInheritanceOperatorRecursive(array<string|int, mixed> $array) : array<string|int, mixed>
Parameters
$array : array<string|int, mixed>
Return values
array<string|int, mixed>

the modified array

removeVendorNamespaceFromInheritancePath()

protected removeVendorNamespaceFromInheritancePath(string $inheritancePath) : string
Parameters
$inheritancePath : string
Return values
string

resolve()

Resolve all inheritances within a configuration.

protected resolve(array<string|int, mixed> $configuration[, array<string|int, mixed> $pathStack = [] ][, bool $setInheritancePathToCheck = true ]) : array<string|int, mixed>

Takes a YAML config mapped to associative array $configuration

  • replace all findings of key '__inheritance' recursively
  • perform a deep search in config by iteration, thus check for endless loop by reference cycle

Return the completed configuration.

Parameters
$configuration : array<string|int, mixed>
  • a mapped YAML configuration (full or partial)
$pathStack : array<string|int, mixed> = []
  • an identifier for YAML key as array (Form.part1.key => {Form, part1, key})
$setInheritancePathToCheck : bool = true
Return values
array<string|int, mixed>

resolveInheritancesRecursive()

Additional helper for the resolve method.

protected resolveInheritancesRecursive(array<string|int, mixed> $inheritances) : array<string|int, mixed>

Takes all inheritances (an array of YAML paths), and check them for endless loops

Parameters
$inheritances : array<string|int, mixed>
Tags
throws
CycleInheritancesException
Return values
array<string|int, mixed>

throwExceptionIfCycleInheritances()

Throw an exception if a cycle is detected.

protected throwExceptionIfCycleInheritances(string $path, string $pathToCheck) : mixed
Parameters
$path : string
$pathToCheck : string
Tags
throws
CycleInheritancesException

        
On this page

Search results