InheritancesResolverService

Resolve declared inheritances within a configuration array

Basic concept:

  • Take a large YAML config and replace the key '__inheritance' 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: __inheritance: 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  : mixed = '__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
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
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
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|null
Check the given array representation of a YAML config for the given path and return it's value / sub-array.
removeInheritanceOperatorRecursive()  : array
Recursively remove self::INHERITANCE_OPERATOR keys
resolve()  : array
Resolve all inheritances within a configuration.
resolveInheritancesRecursive()  : array
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 $inheritanceStack = []

$referenceConfiguration

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

protected array $referenceConfiguration = []

Methods

getResolvedConfiguration()

Resolve all inheritances within a configuration.

public getResolvedConfiguration() : array

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

Internal
Return values
array

setReferenceConfiguration()

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

public setReferenceConfiguration(array $referenceConfiguration) : InheritancesResolverService
Parameters
$referenceConfiguration : array
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 $config, string $path[, string $delimiter = '.' ]) : string|array|null

If path is not found, return null;

Parameters
$config : array
$path : string
$delimiter : string = '.'
Return values
string|array|null

removeInheritanceOperatorRecursive()

Recursively remove self::INHERITANCE_OPERATOR keys

protected removeInheritanceOperatorRecursive(array $array) : array
Parameters
$array : array
Return values
array —

the modified array

resolve()

Resolve all inheritances within a configuration.

protected resolve(array $configuration[, array $pathStack = [] ][, bool $setInheritancePathToCheck = true ]) : array

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

resolveInheritancesRecursive()

Additional helper for the resolve method.

protected resolveInheritancesRecursive(array $inheritances) : array

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

Parameters
$inheritances : array
Tags
throws
CycleInheritancesException
Return values
array

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