class ConfigurationBuilder (View source)

Object Configuration Builder which can build object configuration objects from information collected by reflection combined with arrays of configuration options as defined in an Objects.yaml file.

Properties

protected ReflectionService $reflectionService
protected LoggerInterface $logger
protected array $excludeClassesFromConstructorAutowiring

An array of object names for which constructor injection autowiring should be disabled.

Methods

void
injectReflectionService(ReflectionService $reflectionService)

No description

void
injectLogger(LoggerInterface $logger)

Injects the (system) logger based on PSR-3.

void
injectExcludeClassesFromConstructorAutowiring(array $excludeClassesFromConstructorAutowiring)

No description

buildObjectConfigurations(array $availableClassAndInterfaceNamesByPackage, array $rawObjectConfigurationsByPackages)

Traverses through the given class and interface names and builds a base object configuration for all of them. Then parses the provided extra configuration and merges the result into the overall configuration. Finally autowires dependencies of arguments and properties which can be resolved automatically.

array
enhanceRawConfigurationWithAnnotationOptions(string $className, array $rawObjectConfiguration)

Builds a raw configuration array by parsing possible scope and autowiring annotations from the given class or interface.

parseConfigurationArray(string $objectName, array $rawConfigurationOptions, string $configurationSourceHint = '', Configuration $existingObjectConfiguration = null)

Builds an object configuration object from a generic configuration container.

int
parseScope(string $value)

Parses the value of the option "scope"

static int
parseAutowiring(mixed $value)

Parses the value of the option "autowiring"

parsePropertyOfTypeObject(string $propertyName, mixed $objectNameOrConfiguration, Configuration $parentObjectConfiguration)

Parses the configuration for properties of type OBJECT

parseArgumentOfTypeObject(string $argumentName, mixed $objectNameOrConfiguration, string $configurationSourceHint)

Parses the configuration for arguments of type OBJECT

void
wireFactoryArguments(array $objectConfigurations)

Creates a "virtual object configuration" for factory arguments, turning:

void
autowireArguments(array $objectConfigurations)

If mandatory constructor arguments have not been defined yet, this function tries to autowire them if possible.

void
autowireProperties(array $objectConfigurations)

This function tries to find yet unmatched dependencies which need to be injected via "inject*" setter methods.

Details

void injectReflectionService(ReflectionService $reflectionService)

No description

Parameters

ReflectionService $reflectionService

Return Value

void

void injectLogger(LoggerInterface $logger)

Injects the (system) logger based on PSR-3.

Parameters

LoggerInterface $logger

Return Value

void

void injectExcludeClassesFromConstructorAutowiring(array $excludeClassesFromConstructorAutowiring)

No description

Parameters

array $excludeClassesFromConstructorAutowiring

Return Value

void

Configuration[] buildObjectConfigurations(array $availableClassAndInterfaceNamesByPackage, array $rawObjectConfigurationsByPackages)

Traverses through the given class and interface names and builds a base object configuration for all of them. Then parses the provided extra configuration and merges the result into the overall configuration. Finally autowires dependencies of arguments and properties which can be resolved automatically.

Parameters

array $availableClassAndInterfaceNamesByPackage

An array of available class names, grouped by package key

array $rawObjectConfigurationsByPackages

An array of package keys and their raw (ie. unparsed) object configurations

Return Value

Configuration[]

Object configurations

Exceptions

InvalidObjectConfigurationException

protected array enhanceRawConfigurationWithAnnotationOptions(string $className, array $rawObjectConfiguration)

Builds a raw configuration array by parsing possible scope and autowiring annotations from the given class or interface.

Parameters

string $className
array $rawObjectConfiguration

Return Value

array

protected Configuration parseConfigurationArray(string $objectName, array $rawConfigurationOptions, string $configurationSourceHint = '', Configuration $existingObjectConfiguration = null)

Builds an object configuration object from a generic configuration container.

Parameters

string $objectName

Name of the object

array $rawConfigurationOptions

The configuration array with options for the object configuration

string $configurationSourceHint

A human readable hint on the original source of the configuration (for troubleshooting)

Configuration $existingObjectConfiguration

If set, this object configuration object will be used instead of creating a fresh one

Return Value

Configuration

The object configuration object

Exceptions

InvalidObjectConfigurationException

protected int parseScope(string $value)

Parses the value of the option "scope"

Parameters

string $value

Value of the option

Return Value

int

The scope translated into a Configuration::SCOPE_* constant

Exceptions

InvalidObjectConfigurationException

static protected int parseAutowiring(mixed $value)

Parses the value of the option "autowiring"

Parameters

mixed $value

Value of the option

Return Value

int

The autowiring option translated into one of Configuration::AUTOWIRINGMODE*

Exceptions

InvalidObjectConfigurationException

protected ConfigurationProperty parsePropertyOfTypeObject(string $propertyName, mixed $objectNameOrConfiguration, Configuration $parentObjectConfiguration)

Parses the configuration for properties of type OBJECT

Parameters

string $propertyName

Name of the property

mixed $objectNameOrConfiguration

Value of the "object" section of the property configuration - either a string or an array

Configuration $parentObjectConfiguration

The Configuration object this property belongs to

Return Value

ConfigurationProperty

A configuration property of type object

Exceptions

InvalidObjectConfigurationException

protected ConfigurationArgument parseArgumentOfTypeObject(string $argumentName, mixed $objectNameOrConfiguration, string $configurationSourceHint)

Parses the configuration for arguments of type OBJECT

Parameters

string $argumentName

Name of the argument

mixed $objectNameOrConfiguration

Value of the "object" section of the argument configuration - either a string or an array

string $configurationSourceHint

A human readable hint on the original source of the configuration (for troubleshooting)

Return Value

ConfigurationArgument

A configuration argument of type object

Exceptions

InvalidObjectConfigurationException

protected void wireFactoryArguments(array $objectConfigurations)

Creates a "virtual object configuration" for factory arguments, turning:

'Some\Class\Name': factoryObjectName: 'Some\Factory\Class' arguments: 1: object: factoryObjectName: 'Some\Other\Factory\Class'

into:

'Some\Class\Name': factoryObjectName: 'Some\Factory\Class' arguments: 1: object: 'Some\Class\Name:argument:1'

'Some\Class\Name:argument:1': factoryObjectName: 'Some\Other\Factory\Class'

Parameters

array $objectConfigurations

Return Value

void

protected void autowireArguments(array $objectConfigurations)

If mandatory constructor arguments have not been defined yet, this function tries to autowire them if possible.

Parameters

array $objectConfigurations

Return Value

void

Exceptions

UnresolvedDependenciesException

protected void autowireProperties(array $objectConfigurations)

This function tries to find yet unmatched dependencies which need to be injected via "inject*" setter methods.

Parameters

array $objectConfigurations

Return Value

void

Exceptions

Exception