class ProxyClassBuilder (View source)

A Proxy Class Builder which integrates Dependency Injection

Constants

AUTOGENERATED_PROXY_METHOD_COMMENT

Properties

protected $reflectionService
protected $compiler
protected $logger
protected $configurationManager
protected $cacheManager
protected $objectManager
protected Configuration[] $objectConfigurations

Methods

void
injectReflectionService(ReflectionService $reflectionService)

No description

void
injectCompiler(Compiler $compiler)

No description

void
injectConfigurationManager(ConfigurationManager $configurationManager)

No description

void
injectCacheManager(CacheManager $cacheManager)

No description

void
injectLogger(LoggerInterface $logger)

No description

void
injectObjectManager(CompileTimeObjectManager $objectManager)

No description

void
build()

Analyzes the object configuration provided by the compile-time object manager 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
buildSetRelatedEntitiesCode()

No description

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|null $configurationPath = null)

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

array
buildPropertyInjectionCodeByCacheIdentifier(Configuration $objectConfiguration, string $propertyName, string $cacheIdentifier)

Builds code which assigns the frontend of the specified cache 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|null
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 injectCacheManager(CacheManager $cacheManager)

No description

Parameters

CacheManager $cacheManager

Return Value

void

void injectLogger(LoggerInterface $logger)

No description

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 compile-time object manager and builds the necessary PHP code for the proxy classes to realize dependency injection.

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 bidirectional 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.

The code is only rendered if one of the following conditions is met:

  • The class is annotated with Entity
  • The class is annotated with Scope("session")
  • The class has properties annotated with Transient
  • The class has properties annotated with Inject

Despite the previous condition, the code will not be rendered if the following condition is true:

  • The class already has a __sleep() method (we assume that the developer wants to take care of serialization themself)

NOTE: Even though the method name suggests that it is only dealing with related entities code, it is currently also used for removing injected properties before serialization. This should be refactored in the future.

Parameters

Configuration $objectConfiguration

Return Value

string

protected string buildSetRelatedEntitiesCode()

No description

Return Value

string

protected string buildConstructorInjectionCode(Configuration $objectConfiguration)

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

protected string buildPropertyInjectionCode(Configuration $objectConfiguration)

Builds the code necessary to inject setter based dependencies.

Parameters

Configuration $objectConfiguration

Return Value

string

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

lines of 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

lines of PHP code

Exceptions

UnknownObjectException

array buildPropertyInjectionCodeByConfigurationTypeAndPath(Configuration $objectConfiguration, string $propertyName, string $configurationType, string|null $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|null $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

array buildPropertyInjectionCodeByCacheIdentifier(Configuration $objectConfiguration, string $propertyName, string $cacheIdentifier)

Builds code which assigns the frontend of the specified cache into the given class property.

Parameters

Configuration $objectConfiguration

Configuration of the object to inject into

string $propertyName

Name of the property to inject

string $cacheIdentifier

the identifier of the cache to inject

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|null 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|null

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

Exceptions

InvalidConfigurationTypeException

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
ReflectionException