Documentation

ProxyGenerator
in package

This factory is used to generate proxy classes.

It builds proxies from given parameters, a template and class metadata.

Table of Contents

Constants

PATTERN_MATCH_ID_METHOD  = <<<'EOT' ((?(DEFINE) (?<type>\\?[a-z_\x7f-\xff][\w\x7f-\xff]*(?:\\[a-z_\x7f-\xff][\w\x7f-\xff]*)*) (?<intersection_type>(?&type)\s*&\s*(?&type)) (?<union_type>(?:(?:\(\s*(?&intersection_type)\s*\))|(?&type))(?:\s*\|\s*(?:(?:\(\s*(?&intersection_type)\s*\))|(?&type)))+) )(?:public\s+)?(?:function\s+%s\s*\(\)\s*)\s*(?::\s*(?:(?&union_type)|(?&intersection_type)|(?:\??(?&type)))\s*)?{\s*return\s*\$this->%s;\s*})i EOT
Used to match very simple id methods that don't need to be decorated since the identifier is known.

Properties

$placeholders  : array<string|int, string>|array<string|int, callable>
Map of callables used to fill in placeholders set in the template.
$proxyClassTemplate  : string
Template used as a blueprint to generate proxies.
$proxyDirectory  : string
The directory that contains all proxy classes.
$proxyNamespace  : string
The namespace that contains all proxy classes.

Methods

__construct()  : mixed
Initializes a new instance of the <tt>ProxyFactory</tt> class that is connected to the given <tt>EntityManager</tt>.
generateEnumUseStatements()  : string
Enums must have a use statement when used as public property defaults.
generateProxyClass()  : mixed
Generates a proxy class file.
getProxyFileName()  : string
Generates the Proxy file name.
setPlaceholder()  : mixed
Sets a placeholder to be replaced in the template.
setProxyClassTemplate()  : mixed
Sets the base template used to create proxy classes.
buildParametersString()  : string
formatType()  : string
generateClassName()  : string
Generates the original class name.
generateCloneImpl()  : string
Generates implementation for the `__clone` method of proxies.
generateConstructorImpl()  : string
Generates the constructor code (un-setting public lazy loaded properties, setting identifier field values).
generateLazyPropertiesDefaults()  : string
Generates the array representation of lazy loaded public properties names.
generateLazyPropertiesNames()  : string
Generates the array representation of lazy loaded public properties and their default values.
generateMagicGet()  : string
Generates the magic getter invoked when lazy loaded public properties are requested.
generateMagicIsset()  : string
Generates the magic issetter invoked when lazy loaded public properties are checked against isset().
generateMagicSet()  : string
Generates the magic setter (currently unused).
generateMethods()  : string
Generates decorated methods by picking those available in the parent class.
generateNamespace()  : string
Generates the proxy namespace.
generateProxyShortClassName()  : string
Generates the proxy short class name to be used in the template.
generateSleepImpl()  : string
Generates implementation for the `__sleep` method of proxies.
generateWakeupImpl()  : string
Generates implementation for the `__wakeup` method of proxies.
getLazyLoadedPublicProperties()  : array<string|int, mixed>
Generates the list of default values of public properties.
getLazyLoadedPublicPropertiesNames()  : array<int, string>
Generates the list of public properties to be lazy loaded.
getMethodReturnType()  : string
getParameterDefaultValue()  : string
getParameterNamesForInvoke()  : array<string|int, string>
getParameterNamesForParentCall()  : array<string|int, string>
getParameterType()  : string|null
isShortIdentifierGetter()  : bool
Checks if the method is a short identifier getter.
shouldProxiedMethodReturn()  : bool
verifyClassCanBeProxied()  : mixed

Constants

PATTERN_MATCH_ID_METHOD

Used to match very simple id methods that don't need to be decorated since the identifier is known.

public mixed PATTERN_MATCH_ID_METHOD = <<<'EOT' ((?(DEFINE) (?<type>\\?[a-z_\x7f-\xff][\w\x7f-\xff]*(?:\\[a-z_\x7f-\xff][\w\x7f-\xff]*)*) (?<intersection_type>(?&type)\s*&\s*(?&type)) (?<union_type>(?:(?:\(\s*(?&intersection_type)\s*\))|(?&type))(?:\s*\|\s*(?:(?:\(\s*(?&intersection_type)\s*\))|(?&type)))+) )(?:public\s+)?(?:function\s+%s\s*\(\)\s*)\s*(?::\s*(?:(?&union_type)|(?&intersection_type)|(?:\??(?&type)))\s*)?{\s*return\s*\$this->%s;\s*})i EOT

Properties

$placeholders

Map of callables used to fill in placeholders set in the template.

protected array<string|int, string>|array<string|int, callable> $placeholders = ['baseProxyInterface' => \Doctrine\Common\Proxy\Proxy::class, 'additionalProperties' => '']

$proxyClassTemplate

Template used as a blueprint to generate proxies.

protected string $proxyClassTemplate = '<?php namespace <namespace>; <enumUseStatements> /** * DO NOT EDIT THIS FILE - IT WAS CREATED BY DOCTRINE\'S PROXY GENERATOR */ class <proxyShortClassName> extends \\<className> implements \\<baseProxyInterface> { /** * @var \\Closure the callback responsible for loading properties in the proxy object. This callback is called with * three parameters, being respectively the proxy object to be initialized, the method that triggered the * initialization process and an array of ordered parameters that were passed to that method. * * @see \\Doctrine\\Common\\Proxy\\Proxy::__setInitializer */ public $__initializer__; /** * @var \\Closure the callback responsible of loading properties that need to be copied in the cloned object * * @see \\Doctrine\\Common\\Proxy\\Proxy::__setCloner */ public $__cloner__; /** * @var boolean flag indicating if this object was already initialized * * @see \\Doctrine\\Persistence\\Proxy::__isInitialized */ public $__isInitialized__ = false; /** * @var array<string, null> properties to be lazy loaded, indexed by property name */ public static $lazyPropertiesNames = <lazyPropertiesNames>; /** * @var array<string, mixed> default values of properties to be lazy loaded, with keys being the property names * * @see \\Doctrine\\Common\\Proxy\\Proxy::__getLazyProperties */ public static $lazyPropertiesDefaults = <lazyPropertiesDefaults>; <additionalProperties> <constructorImpl> <magicGet> <magicSet> <magicIsset> <sleepImpl> <wakeupImpl> <cloneImpl> /** * Forces initialization of the proxy */ public function __load(): void { $this->__initializer__ && $this->__initializer__->__invoke($this, \'__load\', []); } /** * {@inheritDoc} * @internal generated method: use only when explicitly handling proxy specific loading logic */ public function __isInitialized(): bool { return $this->__isInitialized__; } /** * {@inheritDoc} * @internal generated method: use only when explicitly handling proxy specific loading logic */ public function __setInitialized($initialized): void { $this->__isInitialized__ = $initialized; } /** * {@inheritDoc} * @internal generated method: use only when explicitly handling proxy specific loading logic */ public function __setInitializer(\\Closure $initializer = null): void { $this->__initializer__ = $initializer; } /** * {@inheritDoc} * @internal generated method: use only when explicitly handling proxy specific loading logic */ public function __getInitializer(): ?\\Closure { return $this->__initializer__; } /** * {@inheritDoc} * @internal generated method: use only when explicitly handling proxy specific loading logic */ public function __setCloner(\\Closure $cloner = null): void { $this->__cloner__ = $cloner; } /** * {@inheritDoc} * @internal generated method: use only when explicitly handling proxy specific cloning logic */ public function __getCloner(): ?\\Closure { return $this->__cloner__; } /** * {@inheritDoc} * @internal generated method: use only when explicitly handling proxy specific loading logic * @deprecated no longer in use - generated code now relies on internal components rather than generated public API * @static */ public function __getLazyProperties(): array { return self::$lazyPropertiesDefaults; } <methods> } '

$proxyDirectory

The directory that contains all proxy classes.

private string $proxyDirectory

$proxyNamespace

The namespace that contains all proxy classes.

private string $proxyNamespace

Methods

__construct()

Initializes a new instance of the <tt>ProxyFactory</tt> class that is connected to the given <tt>EntityManager</tt>.

public __construct(string $proxyDirectory, string $proxyNamespace) : mixed
Parameters
$proxyDirectory : string

The directory to use for the proxy classes. It must exist.

$proxyNamespace : string

The namespace to use for the proxy classes.

Tags
throws
InvalidArgumentException

generateEnumUseStatements()

Enums must have a use statement when used as public property defaults.

public generateEnumUseStatements(ClassMetadata $class) : string
Parameters
$class : ClassMetadata
Return values
string

getProxyFileName()

Generates the Proxy file name.

public getProxyFileName(string $className[, string $baseDirectory = null ]) : string
Parameters
$className : string
$baseDirectory : string = null

Optional base directory for proxy file name generation. If not specified, the directory configured on the Configuration of the EntityManager will be used by this factory.

Tags
psalm-param

class-string $className

Return values
string

setPlaceholder()

Sets a placeholder to be replaced in the template.

public setPlaceholder(string $name, string|callable $placeholder) : mixed
Parameters
$name : string
$placeholder : string|callable
Tags
throws
InvalidArgumentException

setProxyClassTemplate()

Sets the base template used to create proxy classes.

public setProxyClassTemplate(string $proxyClassTemplate) : mixed
Parameters
$proxyClassTemplate : string

buildParametersString()

private buildParametersString(array<string|int, ReflectionParameter$parameters[, array<string|int, string> $renameParameters = [] ]) : string
Parameters
$parameters : array<string|int, ReflectionParameter>
$renameParameters : array<string|int, string> = []
Return values
string

formatType()

private formatType(ReflectionType $type, ReflectionMethod $method[, ReflectionParameter|null $parameter = null ]) : string
Parameters
$type : ReflectionType
$method : ReflectionMethod
$parameter : ReflectionParameter|null = null
Return values
string

generateCloneImpl()

Generates implementation for the `__clone` method of proxies.

private generateCloneImpl(ClassMetadata $class) : string
Parameters
$class : ClassMetadata
Return values
string

generateConstructorImpl()

Generates the constructor code (un-setting public lazy loaded properties, setting identifier field values).

private generateConstructorImpl(ClassMetadata $class) : string
Parameters
$class : ClassMetadata
Return values
string

generateLazyPropertiesDefaults()

Generates the array representation of lazy loaded public properties names.

private generateLazyPropertiesDefaults(ClassMetadata $class) : string
Parameters
$class : ClassMetadata
Return values
string

generateLazyPropertiesNames()

Generates the array representation of lazy loaded public properties and their default values.

private generateLazyPropertiesNames(ClassMetadata $class) : string
Parameters
$class : ClassMetadata
Return values
string

generateMagicGet()

Generates the magic getter invoked when lazy loaded public properties are requested.

private generateMagicGet(ClassMetadata $class) : string
Parameters
$class : ClassMetadata
Return values
string

generateMagicIsset()

Generates the magic issetter invoked when lazy loaded public properties are checked against isset().

private generateMagicIsset(ClassMetadata $class) : string
Parameters
$class : ClassMetadata
Return values
string

generateMethods()

Generates decorated methods by picking those available in the parent class.

private generateMethods(ClassMetadata $class) : string
Parameters
$class : ClassMetadata
Return values
string

generateProxyShortClassName()

Generates the proxy short class name to be used in the template.

private generateProxyShortClassName(ClassMetadata $class) : string
Parameters
$class : ClassMetadata
Return values
string

generateSleepImpl()

Generates implementation for the `__sleep` method of proxies.

private generateSleepImpl(ClassMetadata $class) : string
Parameters
$class : ClassMetadata
Return values
string

generateWakeupImpl()

Generates implementation for the `__wakeup` method of proxies.

private generateWakeupImpl(ClassMetadata $class) : string
Parameters
$class : ClassMetadata
Return values
string

getLazyLoadedPublicProperties()

Generates the list of default values of public properties.

private getLazyLoadedPublicProperties(ClassMetadata $class) : array<string|int, mixed>
Parameters
$class : ClassMetadata
Return values
array<string|int, mixed>

getLazyLoadedPublicPropertiesNames()

Generates the list of public properties to be lazy loaded.

private getLazyLoadedPublicPropertiesNames(ClassMetadata $class) : array<int, string>
Parameters
$class : ClassMetadata
Return values
array<int, string>

getMethodReturnType()

private getMethodReturnType(ReflectionMethod $method) : string
Parameters
$method : ReflectionMethod
Return values
string

getParameterDefaultValue()

private getParameterDefaultValue(ReflectionParameter $parameter) : string
Parameters
$parameter : ReflectionParameter
Return values
string

getParameterNamesForInvoke()

private getParameterNamesForInvoke(array<string|int, ReflectionParameter$parameters) : array<string|int, string>
Parameters
$parameters : array<string|int, ReflectionParameter>
Return values
array<string|int, string>

getParameterNamesForParentCall()

private getParameterNamesForParentCall(array<string|int, ReflectionParameter$parameters) : array<string|int, string>
Parameters
$parameters : array<string|int, ReflectionParameter>
Return values
array<string|int, string>

getParameterType()

private getParameterType(ReflectionParameter $parameter) : string|null
Parameters
$parameter : ReflectionParameter
Return values
string|null

isShortIdentifierGetter()

Checks if the method is a short identifier getter.

private isShortIdentifierGetter(ReflectionMethod $method, ClassMetadata $class) : bool

What does this mean? For proxy objects the identifier is already known, however accessing the getter for this identifier usually triggers the lazy loading, leading to a query that may not be necessary if only the ID is interesting for the userland code (for example in views that generate links to the entity, but do not display anything else).

Parameters
$method : ReflectionMethod
$class : ClassMetadata
Return values
bool

shouldProxiedMethodReturn()

private shouldProxiedMethodReturn(ReflectionMethod $method) : bool
Parameters
$method : ReflectionMethod
Return values
bool

        
On this page

Search results