class Compiler (View source)

Builder for proxy classes which are used to implement Dependency Injection and Aspect-Oriented Programming

Constants

ORIGINAL_CLASSNAME_SUFFIX

Properties

protected CompileTimeObjectManager $objectManager
protected PhpFrontend $classesCache
protected ReflectionService $reflectionService
protected array $proxyClasses
protected array $excludedSubPackages

Hardcoded list of Flow sub packages which must be immune proxying for security, technical or conceptual reasons.

protected int $excludedSubPackagesLength

Length of the prefix that will be checked for exclusion of proxy building.

protected array $storedProxyClasses

The final map of proxy classes that end up in the cache.

Methods

__construct()

Compiler constructor.

void
injectObjectManager(CompileTimeObjectManager $objectManager)

No description

void
injectClassesCache(PhpFrontend $classesCache)

Injects the cache for storing the renamed original classes and proxy classes

void
injectReflectionService(ReflectionService $reflectionService)

No description

ProxyClass|false
getProxyClass(string $fullClassName)

Returns a proxy class object for the specified original class.

bool
hasCacheEntryForClass(string $fullClassName)

Checks if the specified class still exists in the code cache. If that is the case, it means that obviously the proxy class doesn't have to be rebuilt because otherwise the cache would have been flushed by the file monitor or some other mechanism.

int
compile()

Compiles the configured proxy classes and methods as static PHP code and stores it in the proxy class code cache.

void
emitCompiledClasses(array $classNames)

No description

string
getStoredProxyClassMap()

No description

void
cacheOriginalClassFileAndProxyCode(string $className, string $pathAndFilename, string $proxyClassCode)

Reads the specified class file, appends ORIGINAL_CLASSNAME_SUFFIX to its class name and stores the result in the proxy classes cache.

string
stripOpeningPhpTag(string $classCode)

Removes the first opening php tag ("<?php") from the given $classCode if there is any

static string
renderAttribute(ReflectionAttribute $attribute)

Render the source (string) form of a PHP Attribute.

static string
renderAnnotation(object $annotation)

Render the source (string) form of an Annotation instance.

static string
renderOptionArrayValueAsString(array $optionValue)

Render an array value as string for an annotation.

string
replaceClassName(string $classCode, string $pathAndFilename)

Appends ORIGINAL_CLASSNAME_SUFFIX to the original class name

string
makePrivateConstructorPublic(string $classCode, string $pathAndFilename)

If a constructor exists, and it is private, this method will change its visibility to public in the given class code. This is only necessary in order to allow the proxy class to call its parent constructor.

string
commentOutFinalKeywordForMethods(string $classCode, string $proxyClassCode)

No description

string
replaceSelfWithStatic(string $classCode)

Replace occurrences of "self" with "static" for instantiation with new self() and function return declarations like "public function foo(): self".

Details

__construct()

Compiler constructor.

void injectObjectManager(CompileTimeObjectManager $objectManager)

No description

Parameters

CompileTimeObjectManager $objectManager

Return Value

void

void injectClassesCache(PhpFrontend $classesCache)

Injects the cache for storing the renamed original classes and proxy classes

Parameters

PhpFrontend $classesCache

Return Value

void

void injectReflectionService(ReflectionService $reflectionService)

No description

Parameters

ReflectionService $reflectionService

Return Value

void

ProxyClass|false getProxyClass(string $fullClassName)

Returns a proxy class object for the specified original class.

If no such proxy class has been created yet by this renderer, this function will create one and register it for later use.

If the class is not proxyable, or is not a real class at all, false will be returned

Parameters

string $fullClassName

Name of the original class

Return Value

ProxyClass|false

bool hasCacheEntryForClass(string $fullClassName)

Checks if the specified class still exists in the code cache. If that is the case, it means that obviously the proxy class doesn't have to be rebuilt because otherwise the cache would have been flushed by the file monitor or some other mechanism.

Parameters

string $fullClassName

Name of the original class

Return Value

bool

true if a cache entry exists

int compile()

Compiles the configured proxy classes and methods as static PHP code and stores it in the proxy class code cache.

Also builds the static object container which acts as a registry for non-prototype objects during runtime.

Return Value

int

Number of classes which have been compiled

void emitCompiledClasses(array $classNames)

No description

Parameters

array $classNames

Return Value

void

string getStoredProxyClassMap()

No description

Return Value

string

protected void cacheOriginalClassFileAndProxyCode(string $className, string $pathAndFilename, string $proxyClassCode)

Reads the specified class file, appends ORIGINAL_CLASSNAME_SUFFIX to its class name and stores the result in the proxy classes cache.

Parameters

string $className

Short class name of the class to copy

string $pathAndFilename

Full path and filename of the original class file

string $proxyClassCode

The code that makes up the proxy class

Return Value

void

Exceptions

Exception
InvalidDataException
Exception
ProxyCompilerException

protected string stripOpeningPhpTag(string $classCode)

Removes the first opening php tag ("<?php") from the given $classCode if there is any

Parameters

string $classCode

Return Value

string

the original class code without opening php tag

static string renderAttribute(ReflectionAttribute $attribute)

Render the source (string) form of a PHP Attribute.

Parameters

ReflectionAttribute $attribute

Return Value

string

static string renderAnnotation(object $annotation)

Render the source (string) form of an Annotation instance.

Parameters

object $annotation

Return Value

string

static protected string renderOptionArrayValueAsString(array $optionValue)

Render an array value as string for an annotation.

Parameters

array $optionValue

Return Value

string

protected string replaceClassName(string $classCode, string $pathAndFilename)

Appends ORIGINAL_CLASSNAME_SUFFIX to the original class name

Parameters

string $classCode
string $pathAndFilename

Return Value

string

Exceptions

Exception

protected string makePrivateConstructorPublic(string $classCode, string $pathAndFilename)

If a constructor exists, and it is private, this method will change its visibility to public in the given class code. This is only necessary in order to allow the proxy class to call its parent constructor.

Parameters

string $classCode
string $pathAndFilename

Return Value

string

Exceptions

ProxyCompilerException

protected string commentOutFinalKeywordForMethods(string $classCode, string $proxyClassCode)

No description

Parameters

string $classCode
string $proxyClassCode

Return Value

string

protected string replaceSelfWithStatic(string $classCode)

Replace occurrences of "self" with "static" for instantiation with new self() and function return declarations like "public function foo(): self".

References to constants like "self::FOO" are not replaced.

Parameters

string $classCode

Return Value

string