class ProxyClassBuilder (View source)

A Proxy Class Builder which integrates Dependency Injection.

Properties

protected ReflectionService $reflectionService
protected Compiler $compiler
protected LoggerInterface $logger
protected ConfigurationManager $configurationManager
protected CompileTimeObjectManager $objectManager
protected Configuration[] $objectConfigurations

Methods

void
injectReflectionService(ReflectionService $reflectionService)

No description

void
injectCompiler(Compiler $compiler)

No description

void
injectConfigurationManager(ConfigurationManager $configurationManager)

No description

void
injectLogger(LoggerInterface $logger)

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

void
injectObjectManager(CompileTimeObjectManager $objectManager)

No description

void
build()

Analyzes the Object Configuration provided by the compiler and builds the necessary PHP code for the proxy classes to realize dependency injection.

string
buildSetInstanceCode(Configuration $objectConfiguration)

Renders additional code which registers the instance of the proxy class at the Object Manager before constructor injection is executed. Used in constructors and wakeup methods.

string
buildSerializeRelatedEntitiesCode(Configuration $objectConfiguration)

Renders code to create identifier/type information from related entities in an object.

string
buildConstructorInjectionCode(Configuration $objectConfiguration)

Renders additional code for the __construct() method of the Proxy Class which realizes constructor injection.

string
buildPropertyInjectionCode(Configuration $objectConfiguration)

Builds the code necessary to inject setter based dependencies.

array
buildPropertyInjectionCodeByConfiguration(Configuration $objectConfiguration, string $propertyName, Configuration $propertyConfiguration)

Builds code which injects an object which was specified by its object configuration

array
buildPropertyInjectionCodeByString(Configuration $objectConfiguration, ConfigurationProperty $propertyConfiguration, string $propertyName, string $propertyObjectName)

Builds code which injects an object which was specified by its object name

array
buildPropertyInjectionCodeByConfigurationTypeAndPath(Configuration $objectConfiguration, string $propertyName, string $configurationType, string $configurationPath = null)

Builds code which assigns the value stored in the specified configuration into the given class property.

array
buildLazyPropertyInjectionCode(string $propertyObjectName, string $propertyClassName, string $propertyName, string $preparedSetterArgument)

Builds code which injects a DependencyProxy instead of the actual dependency

array
buildSetterInjectionCode(string $className, string $propertyName, string $preparedSetterArgument)

Builds a code snippet which tries to inject the specified property first through calling the related inject() method and then the set() method. If neither exists and the property doesn't exist either, an empty array is returned.

string
buildLifecycleInitializationCode(Configuration $objectConfiguration, int $cause)

Builds code which calls the lifecycle initialization method, if any.

string
buildLifecycleShutdownCode(Configuration $objectConfiguration, int $cause)

Builds code which registers the lifecycle shutdown method, if any.

string
buildMethodParametersCode(array $argumentConfigurations)

FIXME: Not yet completely refactored to new proxy mechanism

string
buildCustomFactoryCall(string $customFactoryObjectName, string $customFactoryMethodName, array $arguments)

No description

void
compileStaticMethods(string $className, ProxyClass $proxyClass)

Compile the result of methods marked with CompileStatic into the proxy class

Details

void injectReflectionService(ReflectionService $reflectionService)

No description

Parameters

ReflectionService $reflectionService

Return Value

void

void injectCompiler(Compiler $compiler)

No description

Parameters

Compiler $compiler

Return Value

void

void injectConfigurationManager(ConfigurationManager $configurationManager)

No description

Parameters

ConfigurationManager $configurationManager

Return Value

void

void injectLogger(LoggerInterface $logger)

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

Parameters

LoggerInterface $logger

Return Value

void

void injectObjectManager(CompileTimeObjectManager $objectManager)

No description

Parameters

CompileTimeObjectManager $objectManager

Return Value

void

void build()

Analyzes the Object Configuration provided by the compiler and builds the necessary PHP code for the proxy classes to realize dependency injection.

Return Value

void

protected string buildSetInstanceCode(Configuration $objectConfiguration)

Renders additional code which registers the instance of the proxy class at the Object Manager before constructor injection is executed. Used in constructors and wakeup methods.

This also makes sure that object creation does not end in an endless loop due to bi-directional dependencies.

Parameters

Configuration $objectConfiguration

Return Value

string

protected string buildSerializeRelatedEntitiesCode(Configuration $objectConfiguration)

Renders code to create identifier/type information from related entities in an object.

Used in sleep methods.

Parameters

Configuration $objectConfiguration

Return Value

string

protected string buildConstructorInjectionCode(Configuration $objectConfiguration)

Renders additional code for the __construct() method of the Proxy Class which realizes constructor injection.

Parameters

Configuration $objectConfiguration

Return Value

string

The built code

Exceptions

UnknownObjectException

protected string buildPropertyInjectionCode(Configuration $objectConfiguration)

Builds the code necessary to inject setter based dependencies.

Parameters

Configuration $objectConfiguration

(needed to produce helpful exception message)

Return Value

string

The built code

Exceptions

UnknownObjectException

protected array buildPropertyInjectionCodeByConfiguration(Configuration $objectConfiguration, string $propertyName, Configuration $propertyConfiguration)

Builds code which injects an object which was specified by its object configuration

Parameters

Configuration $objectConfiguration

Configuration of the object to inject into

string $propertyName

Name of the property to inject

Configuration $propertyConfiguration

Configuration of the object to inject

Return Value

array

PHP code

Exceptions

UnknownObjectException

array buildPropertyInjectionCodeByString(Configuration $objectConfiguration, ConfigurationProperty $propertyConfiguration, string $propertyName, string $propertyObjectName)

Builds code which injects an object which was specified by its object name

Parameters

Configuration $objectConfiguration

Configuration of the object to inject into

ConfigurationProperty $propertyConfiguration
string $propertyName

Name of the property to inject

string $propertyObjectName

Object name of the object to inject

Return Value

array

PHP code

Exceptions

UnknownObjectException

array buildPropertyInjectionCodeByConfigurationTypeAndPath(Configuration $objectConfiguration, string $propertyName, string $configurationType, string $configurationPath = null)

Builds code which assigns the value stored in the specified configuration into the given class property.

Parameters

Configuration $objectConfiguration

Configuration of the object to inject into

string $propertyName

Name of the property to inject

string $configurationType

the configuration type of the injected property (one of the ConfigurationManager::CONFIGURATIONTYPE* constants)

string $configurationPath

Path with "." as separator specifying the setting value to inject or NULL if the complete configuration array should be injected

Return Value

array

PHP code

protected array buildLazyPropertyInjectionCode(string $propertyObjectName, string $propertyClassName, string $propertyName, string $preparedSetterArgument)

Builds code which injects a DependencyProxy instead of the actual dependency

Parameters

string $propertyObjectName

Object name of the dependency to inject

string $propertyClassName

Class name of the dependency to inject

string $propertyName

Name of the property in the class to inject into

string $preparedSetterArgument

PHP code to use for retrieving the value to inject

Return Value

array

PHP code

protected array buildSetterInjectionCode(string $className, string $propertyName, string $preparedSetterArgument)

Builds a code snippet which tries to inject the specified property first through calling the related inject() method and then the set() method. If neither exists and the property doesn't exist either, an empty array is returned.

If neither inject() nor set() exists, but the property does exist, NULL is returned

Parameters

string $className

Name of the class to inject into

string $propertyName

Name of the property to inject

string $preparedSetterArgument

PHP code to use for retrieving the value to inject

Return Value

array

PHP code

protected string buildLifecycleInitializationCode(Configuration $objectConfiguration, int $cause)

Builds code which calls the lifecycle initialization method, if any.

Parameters

Configuration $objectConfiguration
int $cause

a ObjectManagerInterface::INITIALIZATIONCAUSE_* constant which is the cause of the initialization command being called.

Return Value

string

protected string buildLifecycleShutdownCode(Configuration $objectConfiguration, int $cause)

Builds code which registers the lifecycle shutdown method, if any.

Parameters

Configuration $objectConfiguration
int $cause

a ObjectManagerInterface::INITIALIZATIONCAUSE_* constant which is the cause of the initialization command being called.

Return Value

string

protected string buildMethodParametersCode(array $argumentConfigurations)

FIXME: Not yet completely refactored to new proxy mechanism

Parameters

array $argumentConfigurations

Return Value

string

protected string buildCustomFactoryCall(string $customFactoryObjectName, string $customFactoryMethodName, array $arguments)

No description

Parameters

string $customFactoryObjectName
string $customFactoryMethodName
array $arguments

Return Value

string

protected void compileStaticMethods(string $className, ProxyClass $proxyClass)

Compile the result of methods marked with CompileStatic into the proxy class

Parameters

string $className
ProxyClass $proxyClass

Return Value

void

Exceptions

Exception