class ProxyClassBuilder (View source)

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

Properties

protected $compiler
protected $reflectionService
protected $logger
protected $pointcutExpressionParser
protected $objectConfigurationCache
protected $objectManager
protected $excludedSubPackages

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

protected $aspectContainers

A registry of all known aspects

protected $methodInterceptorBuilders

Methods

void
injectCompiler(Compiler $compiler)

No description

void
injectReflectionService(ReflectionService $reflectionService)

No description

void
injectLogger(LoggerInterface $logger)

No description

void
injectPointcutExpressionParser(PointcutExpressionParser $pointcutExpressionParser)

No description

void
injectObjectConfigurationCache(VariableFrontend $objectConfigurationCache)

No description

void
injectObjectManager(CompileTimeObjectManager $objectManager)

No description

void
build()

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

Pointcut|false
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 subclasses of an advised 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
addAdvisedMethodsToInterceptedMethods(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)

No description

Parameters

ReflectionService $reflectionService

Return Value

void

void injectLogger(LoggerInterface $logger)

No description

Parameters

LoggerInterface $logger

Return Value

void

void injectPointcutExpressionParser(PointcutExpressionParser $pointcutExpressionParser)

No description

Parameters

PointcutExpressionParser $pointcutExpressionParser

Return Value

void

void injectObjectConfigurationCache(VariableFrontend $objectConfigurationCache)

No description

Parameters

VariableFrontend $objectConfigurationCache

Return Value

void

void injectAdvisedConstructorInterceptorBuilder(AdvisedConstructorInterceptorBuilder $builder)

No description

Parameters

AdvisedConstructorInterceptorBuilder $builder

Return Value

void

void injectAdvisedMethodInterceptorBuilder(AdvisedMethodInterceptorBuilder $builder)

No description

Parameters

AdvisedMethodInterceptorBuilder $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.

Pointcut|false 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

Pointcut|false

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

Exceptions

Exception
FilesException
InvalidPointcutExpressionException
ReflectionException
Exception

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
InvalidPointcutExpressionException
Exception
FilesException
ReflectionException

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.

Exceptions

ReflectionException
CannotBuildObjectException
VoidImplementationException
Exception
Exception

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

Makes sure that any subclasses of an advised class also build the advices array on construction.

Parameters

string $className

The advised 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

Exceptions

ClassLoadingForReflectionFailedException
ReflectionException
InvalidClassException
CannotBuildObjectException

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

Exceptions

ReflectionException
CannotBuildObjectException

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

Exceptions

ReflectionException

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 addAdvisedMethodsToInterceptedMethods(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

Exceptions

Exception

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

Exceptions

Exception

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

Exceptions

Exception

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