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

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(Annotation $annotation)

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

static string
renderOptionArrayValueAsString(array $optionValue)

Render an array value as string for an annotation.

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

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

emitCompiledClasses(array $classNames)

No description

Parameters

array $classNames

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

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(Annotation $annotation)

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

Parameters

Annotation $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