class ProxyClassBuilder (View source)

The main class of the AOP (Aspect Oriented Programming) framework.

Properties

protected Compiler $compiler
protected ReflectionService $reflectionService
protected LoggerInterface $logger
protected PointcutExpressionParser $pointcutExpressionParser

An instance of the pointcut expression parser

protected ProxyClassBuilder $proxyClassBuilder
protected VariableFrontend $objectConfigurationCache
protected CompileTimeObjectManager $objectManager
protected array $excludedSubPackages

Hardcoded list of Flow sub packages (first 15 characters) which must be immune to AOP proxying for security, technical or conceptual reasons.

protected array $aspectContainers

A registry of all known aspects

protected array $methodInterceptorBuilders

Methods

void
injectCompiler(Compiler $compiler)

No description

void
injectReflectionService(ReflectionService $reflectionService)

Injects the reflection service

void
injectLogger(LoggerInterface $logger)

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

void
injectPointcutExpressionParser(PointcutExpressionParser $pointcutExpressionParser)

Injects an instance of the pointcut expression parser

void
injectObjectConfigurationCache(VariableFrontend $objectConfigurationCache)

Injects the cache for storing information about objects

void
injectAdvicedConstructorInterceptorBuilder(AdvicedConstructorInterceptorBuilder $builder)

Injects the Adviced Constructor Interceptor Builder

void
injectAdvicedMethodInterceptorBuilder(AdvicedMethodInterceptorBuilder $builder)

Injects the Adviced Method Interceptor Builder

void
injectObjectManager(CompileTimeObjectManager $objectManager)

No description

void
build()

Builds proxy class code which weaves advices into the respective target classes.

mixed
findPointcut(string $aspectClassName, string $pointcutMethodName)

Traverses the aspect containers to find a pointcut from the aspect class name and pointcut method name

array
getProxyableClasses(array $classNamesByPackage)

Determines which of the given classes are potentially proxyable and returns their names in an array.

array
buildAspectContainers(array $classNames)

Checks the annotations of the specified classes for aspect tags and creates an aspect with advisors accordingly.

buildAspectContainer(string $aspectClassName)

Creates and returns an aspect from the annotations found in a class which is tagged as an aspect. The object acting as an advice will already be fetched (and therefore instantiated if necessary).

bool
buildProxyClass(string $targetClassName, array $aspectContainers)

Builds methods for a single AOP proxy class for the specified class.

proxySubClassesOfClassToEnsureAdvices(string $className, ClassNameIndex $targetClassNameCandidates, ClassNameIndex $treatedSubClasses)

Makes sure that any sub classes of an adviced class also build the advices array on construction.

addBuildMethodsAndAdvicesCodeToClass(string $className, ClassNameIndex $treatedSubClasses)

Adds code to build the methods and advices array in case the parent class has some.

array
getMethodsFromTargetClass(string $targetClassName)

Returns the methods of the target class.

string
buildMethodsAndAdvicesArrayCode(array $methodsAndGroupedAdvices)

Creates code for an array of target methods and their advices.

void
buildMethodsInterceptorCode(string $targetClassName, array $interceptedMethods)

Traverses all intercepted methods and their advices and builds PHP code to intercept methods if necessary.

void
addAdvicedMethodsToInterceptedMethods(array $interceptedMethods, array $methods, string $targetClassName, array $aspectContainers)

Traverses all aspect containers, their aspects and their advisors and adds the methods and their advices to the (usually empty) array of intercepted methods.

void
addIntroducedMethodsToInterceptedMethods(array $interceptedMethods, array $methodsFromIntroducedInterfaces)

Traverses all methods which were introduced by interfaces and adds them to the intercepted methods array if they didn't exist already.

array
getMatchingInterfaceIntroductions(array $aspectContainers, string $targetClassName)

Traverses all aspect containers and returns an array of interface introductions which match the target class.

array
getMatchingPropertyIntroductions(array $aspectContainers, string $targetClassName)

Traverses all aspect containers and returns an array of property introductions which match the target class.

array
getMatchingTraitNamesFromIntroductions(array $aspectContainers, string $targetClassName)

Traverses all aspect containers and returns an array of trait introductions which match the target class.

array
getInterfaceNamesFromIntroductions(array $interfaceIntroductions)

Returns an array of interface names introduced by the given introductions

array
getIntroducedMethodsFromInterfaceIntroductions(array $interfaceIntroductions)

Returns all methods declared by the introduced interfaces

string
renderSourceHint(string $aspectClassName, string $methodName, string $tagName)

Renders a short message which gives a hint on where the currently parsed pointcut expression was defined.

Details

void injectCompiler(Compiler $compiler)

No description

Parameters

Compiler $compiler

Return Value

void

void injectReflectionService(ReflectionService $reflectionService)

Injects the reflection service

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 injectPointcutExpressionParser(PointcutExpressionParser $pointcutExpressionParser)

Injects an instance of the pointcut expression parser

Parameters

PointcutExpressionParser $pointcutExpressionParser

Return Value

void

void injectObjectConfigurationCache(VariableFrontend $objectConfigurationCache)

Injects the cache for storing information about objects

Parameters

VariableFrontend $objectConfigurationCache

Return Value

void

void injectAdvicedConstructorInterceptorBuilder(AdvicedConstructorInterceptorBuilder $builder)

Injects the Adviced Constructor Interceptor Builder

Parameters

AdvicedConstructorInterceptorBuilder $builder

Return Value

void

void injectAdvicedMethodInterceptorBuilder(AdvicedMethodInterceptorBuilder $builder)

Injects the Adviced Method Interceptor Builder

Parameters

AdvicedMethodInterceptorBuilder $builder

Return Value

void

void injectObjectManager(CompileTimeObjectManager $objectManager)

No description

Parameters

CompileTimeObjectManager $objectManager

Return Value

void

void build()

Builds proxy class code which weaves advices into the respective target classes.

The object configurations provided by the Compiler are searched for possible aspect annotations. If an aspect class is found, the pointcut expressions are parsed and a new aspect with one or more advisors is added to the aspect registry of the AOP framework. Finally all advices are woven into their target classes by generating proxy classes.

In general, the command neos.flow:core:compile is responsible for compilation and calls this method to do so.

In order to distinguish between an emerged / changed possible target class and a class which has been matched previously but just didn't have to be proxied, the latter are kept track of by an "unproxiedClass-*" cache entry.

Return Value

void

mixed findPointcut(string $aspectClassName, string $pointcutMethodName)

Traverses the aspect containers to find a pointcut from the aspect class name and pointcut method name

Parameters

string $aspectClassName

Name of the aspect class where the pointcut has been declared

string $pointcutMethodName

Method name of the pointcut

Return Value

mixed

The Aop\Pointcut\Pointcut or false if none was found

protected array getProxyableClasses(array $classNamesByPackage)

Determines which of the given classes are potentially proxyable and returns their names in an array.

Parameters

array $classNamesByPackage

Names of the classes to check

Return Value

array

Names of classes which can be proxied

protected array buildAspectContainers(array $classNames)

Checks the annotations of the specified classes for aspect tags and creates an aspect with advisors accordingly.

Parameters

array $classNames

Classes to check for aspect tags.

Return Value

array

An array of Aop\AspectContainer for all aspects which were found.

protected AspectContainer buildAspectContainer(string $aspectClassName)

Creates and returns an aspect from the annotations found in a class which is tagged as an aspect. The object acting as an advice will already be fetched (and therefore instantiated if necessary).

Parameters

string $aspectClassName

Name of the class which forms the aspect, contains advices etc.

Return Value

AspectContainer

The aspect container containing one or more advisors

Exceptions

Exception

bool buildProxyClass(string $targetClassName, array $aspectContainers)

Builds methods for a single AOP proxy class for the specified class.

Parameters

string $targetClassName

Name of the class to create a proxy class file for

array $aspectContainers

The array of aspect containers from the AOP Framework

Return Value

bool

true if the proxy class could be built, false otherwise.

protected ClassNameIndex proxySubClassesOfClassToEnsureAdvices(string $className, ClassNameIndex $targetClassNameCandidates, ClassNameIndex $treatedSubClasses)

Makes sure that any sub classes of an adviced class also build the advices array on construction.

Parameters

string $className

The adviced class name

ClassNameIndex $targetClassNameCandidates

target class names for advices

ClassNameIndex $treatedSubClasses

Already treated (sub) classes to avoid duplication

Return Value

ClassNameIndex

The new collection of already treated classes

protected ClassNameIndex addBuildMethodsAndAdvicesCodeToClass(string $className, ClassNameIndex $treatedSubClasses)

Adds code to build the methods and advices array in case the parent class has some.

Parameters

string $className
ClassNameIndex $treatedSubClasses

Return Value

ClassNameIndex

protected array getMethodsFromTargetClass(string $targetClassName)

Returns the methods of the target class.

Parameters

string $targetClassName

Name of the target class

Return Value

array

Method information with declaring class and method name pairs

protected string buildMethodsAndAdvicesArrayCode(array $methodsAndGroupedAdvices)

Creates code for an array of target methods and their advices.

Example:

$this->Flow_Aop_Proxy_targetMethodsAndGroupedAdvices = array( 'getSomeProperty' => array( \Neos\Flow\Aop\Advice\AroundAdvice::class => array( new \Neos\Flow\Aop\Advice\AroundAdvice(\Neos\Foo\SomeAspect::class, 'aroundAdvice', \Neos\Flow\Core\Bootstrap::$staticObjectManager, function() { ... }), ), ), );

Parameters

array $methodsAndGroupedAdvices

An array of method names and grouped advice objects

Return Value

string

PHP code for the content of an array of target method names and advice objects

See also

buildProxyClass()

protected void buildMethodsInterceptorCode(string $targetClassName, array $interceptedMethods)

Traverses all intercepted methods and their advices and builds PHP code to intercept methods if necessary.

The generated code is added directly to the proxy class by calling the respective methods of the Compiler API.

Parameters

string $targetClassName

The target class the pointcut should match with

array $interceptedMethods

An array of method names which need to be intercepted

Return Value

void

Exceptions

VoidImplementationException

protected void addAdvicedMethodsToInterceptedMethods(array $interceptedMethods, array $methods, string $targetClassName, array $aspectContainers)

Traverses all aspect containers, their aspects and their advisors and adds the methods and their advices to the (usually empty) array of intercepted methods.

Parameters

array $interceptedMethods

An array (empty or not) which contains the names of the intercepted methods and additional information

array $methods

An array of class and method names which are matched against the pointcut (class name = name of the class or interface the method was declared)

string $targetClassName

Name of the class the pointcut should match with

array $aspectContainers

All aspects to take into consideration

Return Value

void

protected void addIntroducedMethodsToInterceptedMethods(array $interceptedMethods, array $methodsFromIntroducedInterfaces)

Traverses all methods which were introduced by interfaces and adds them to the intercepted methods array if they didn't exist already.

Parameters

array $interceptedMethods

An array (empty or not) which contains the names of the intercepted methods and additional information

array $methodsFromIntroducedInterfaces

An array of class and method names from introduced interfaces

Return Value

void

protected array getMatchingInterfaceIntroductions(array $aspectContainers, string $targetClassName)

Traverses all aspect containers and returns an array of interface introductions which match the target class.

Parameters

array $aspectContainers

All aspects to take into consideration

string $targetClassName

Name of the class the pointcut should match with

Return Value

array

array of interface names

protected array getMatchingPropertyIntroductions(array $aspectContainers, string $targetClassName)

Traverses all aspect containers and returns an array of property introductions which match the target class.

Parameters

array $aspectContainers

All aspects to take into consideration

string $targetClassName

Name of the class the pointcut should match with

Return Value

array

array of property introductions

protected array getMatchingTraitNamesFromIntroductions(array $aspectContainers, string $targetClassName)

Traverses all aspect containers and returns an array of trait introductions which match the target class.

Parameters

array $aspectContainers

All aspects to take into consideration

string $targetClassName

Name of the class the pointcut should match with

Return Value

array

array of trait names

protected array getInterfaceNamesFromIntroductions(array $interfaceIntroductions)

Returns an array of interface names introduced by the given introductions

Parameters

array $interfaceIntroductions

An array of interface introductions

Return Value

array

Array of interface names

protected array getIntroducedMethodsFromInterfaceIntroductions(array $interfaceIntroductions)

Returns all methods declared by the introduced interfaces

Parameters

array $interfaceIntroductions

An array of Aop\InterfaceIntroduction

Return Value

array

An array of method information (interface, method name)

Exceptions

Exception

protected string renderSourceHint(string $aspectClassName, string $methodName, string $tagName)

Renders a short message which gives a hint on where the currently parsed pointcut expression was defined.

Parameters

string $aspectClassName
string $methodName
string $tagName

Return Value

string