ProxyFactory
extends AbstractProxyFactory
in package
This factory is used to create proxy objects for entities at runtime.
Tags
Table of Contents
Constants
- AUTOGENERATE_ALWAYS = 1
- Always generates a new proxy in every request.
- AUTOGENERATE_EVAL = 3
- Generate the proxy classes using eval().
- AUTOGENERATE_FILE_NOT_EXISTS = 2
- Autogenerate the proxy class when the proxy file does not exist.
- AUTOGENERATE_FILE_NOT_EXISTS_OR_CHANGED = 4
- Autogenerate the proxy class when the proxy file does not exist or when the proxied file changed.
- AUTOGENERATE_NEVER = 0
- Never autogenerate a proxy and rely that it was generated by some process before deployment.
- AUTOGENERATE_MODES = [self::AUTOGENERATE_NEVER, self::AUTOGENERATE_ALWAYS, self::AUTOGENERATE_FILE_NOT_EXISTS, self::AUTOGENERATE_EVAL, self::AUTOGENERATE_FILE_NOT_EXISTS_OR_CHANGED]
- PROXY_CLASS_TEMPLATE = <<<'EOPHP' <?php namespace <namespace>; /** * DO NOT EDIT THIS FILE - IT WAS CREATED BY DOCTRINE'S PROXY GENERATOR */ class <proxyShortClassName> extends \<className> implements \<baseProxyInterface> { <useLazyGhostTrait> /** * @internal */ public bool $__isCloning = false; public function __construct(?\Closure $initializer = null) { self::createLazyGhost($initializer, <skippedProperties>, $this); } public function __isInitialized(): bool { return isset($this->lazyObjectState) && $this->isLazyObjectInitialized(); } public function __clone() { $this->__isCloning = true; try { $this->__doClone(); } finally { $this->__isCloning = false; } } public function __serialize(): array { <serializeImpl> } } EOPHP
Properties
- $autoGenerate : int
- $definitions : array<string|int, ProxyDefinition>
- $em : EntityManagerInterface
- $identifierFlattener : IdentifierFlattener
- The IdentifierFlattener used for manipulating identifiers
- $metadataFactory : ClassMetadataFactory
- $proxyGenerator : ProxyGenerator
- $proxyNs : string
- $uow : UnitOfWork
Methods
- __construct() : mixed
- Initializes a new instance of the <tt>ProxyFactory</tt> class that is connected to the given <tt>EntityManager</tt>.
- generateProxyClasses() : int
- Generates proxy classes for all given classes.
- getProxy() : Proxy
- Gets a reference proxy instance for the entity of the given type and identified by the given identifier.
- resetUninitializedProxy() : Proxy
- Reset initialization/cloning logic for an un-initialized proxy
- createProxyDefinition() : ProxyDefinition
- skipClass() : bool
- Determine if this class should be skipped during proxy generation.
- createCloner() : Closure
- Creates a closure capable of finalizing state a cloned proxy
- createInitializer() : Closure
- Creates a closure capable of initializing a proxy
- createLazyInitializer() : callable(Proxy): void
- Creates a closure capable of initializing a proxy
- generateSerializeImpl() : string
- generateSkippedProperties() : string
- generateUseLazyGhostTrait() : string
- getProxyDefinition() : ProxyDefinition
- Get a proxy definition for the given class name.
Constants
AUTOGENERATE_ALWAYS
Always generates a new proxy in every request.
public
mixed
AUTOGENERATE_ALWAYS
= 1
This is only sane during development.
AUTOGENERATE_EVAL
Generate the proxy classes using eval().
public
mixed
AUTOGENERATE_EVAL
= 3
This strategy is only sane for development, and even then it gives me the creeps a little.
AUTOGENERATE_FILE_NOT_EXISTS
Autogenerate the proxy class when the proxy file does not exist.
public
mixed
AUTOGENERATE_FILE_NOT_EXISTS
= 2
This strategy causes a file_exists() call whenever any proxy is used the first time in a request.
AUTOGENERATE_FILE_NOT_EXISTS_OR_CHANGED
Autogenerate the proxy class when the proxy file does not exist or when the proxied file changed.
public
mixed
AUTOGENERATE_FILE_NOT_EXISTS_OR_CHANGED
= 4
This strategy causes a file_exists() call whenever any proxy is used the first time in a request. When the proxied file is changed, the proxy will be updated.
AUTOGENERATE_NEVER
Never autogenerate a proxy and rely that it was generated by some process before deployment.
public
mixed
AUTOGENERATE_NEVER
= 0
AUTOGENERATE_MODES
private
mixed
AUTOGENERATE_MODES
= [self::AUTOGENERATE_NEVER, self::AUTOGENERATE_ALWAYS, self::AUTOGENERATE_FILE_NOT_EXISTS, self::AUTOGENERATE_EVAL, self::AUTOGENERATE_FILE_NOT_EXISTS_OR_CHANGED]
PROXY_CLASS_TEMPLATE
private
mixed
PROXY_CLASS_TEMPLATE
= <<<'EOPHP'
<?php
namespace <namespace>;
/**
* DO NOT EDIT THIS FILE - IT WAS CREATED BY DOCTRINE'S PROXY GENERATOR
*/
class <proxyShortClassName> extends \<className> implements \<baseProxyInterface>
{
<useLazyGhostTrait>
/**
* @internal
*/
public bool $__isCloning = false;
public function __construct(?\Closure $initializer = null)
{
self::createLazyGhost($initializer, <skippedProperties>, $this);
}
public function __isInitialized(): bool
{
return isset($this->lazyObjectState) && $this->isLazyObjectInitialized();
}
public function __clone()
{
$this->__isCloning = true;
try {
$this->__doClone();
} finally {
$this->__isCloning = false;
}
}
public function __serialize(): array
{
<serializeImpl>
}
}
EOPHP
Properties
$autoGenerate
private
int
$autoGenerate
Whether to automatically (re)generate proxy classes.
$definitions
private
array<string|int, ProxyDefinition>
$definitions
= []
$em
private
EntityManagerInterface
$em
The EntityManager this factory is bound to.
$identifierFlattener
The IdentifierFlattener used for manipulating identifiers
private
IdentifierFlattener
$identifierFlattener
$metadataFactory
private
ClassMetadataFactory
$metadataFactory
$proxyGenerator
private
ProxyGenerator
$proxyGenerator
the proxy generator responsible for creating the proxy classes/files.
$proxyNs
private
string
$proxyNs
$uow
private
UnitOfWork
$uow
The UnitOfWork this factory uses to retrieve persisters
Methods
__construct()
Initializes a new instance of the <tt>ProxyFactory</tt> class that is connected to the given <tt>EntityManager</tt>.
public
__construct(EntityManagerInterface $em, string $proxyDir, string $proxyNs[, bool|int $autoGenerate = self::AUTOGENERATE_NEVER ]) : mixed
Parameters
- $em : EntityManagerInterface
-
The EntityManager the new factory works for.
- $proxyDir : string
-
The directory to use for the proxy classes. It must exist.
- $proxyNs : string
-
The namespace to use for the proxy classes.
- $autoGenerate : bool|int = self::AUTOGENERATE_NEVER
-
The strategy for automatically generating proxy classes. Possible values are constants of ProxyFactory::AUTOGENERATE_*.
Tags
generateProxyClasses()
Generates proxy classes for all given classes.
public
generateProxyClasses(array<string|int, ClassMetadata> $classes[, string $proxyDir = null ]) : int
Parameters
- $classes : array<string|int, ClassMetadata>
-
The classes (ClassMetadata instances) for which to generate proxies.
- $proxyDir : string = null
-
The target directory of the proxy classes. If not specified, the directory configured on the Configuration of the EntityManager used by this factory is used.
Return values
int —Number of generated proxies.
getProxy()
Gets a reference proxy instance for the entity of the given type and identified by the given identifier.
public
getProxy(string $className, array<string|int, mixed> $identifier) : Proxy
Parameters
- $className : string
- $identifier : array<string|int, mixed>
Tags
Return values
ProxyresetUninitializedProxy()
Reset initialization/cloning logic for an un-initialized proxy
public
resetUninitializedProxy(Proxy $proxy) : Proxy
Parameters
- $proxy : Proxy
Tags
Return values
ProxycreateProxyDefinition()
protected
createProxyDefinition(mixed $className) : ProxyDefinition
Parameters
- $className : mixed
Return values
ProxyDefinitionskipClass()
Determine if this class should be skipped during proxy generation.
protected
skipClass(ClassMetadata $metadata) : bool
Parameters
- $metadata : ClassMetadata
Return values
boolcreateCloner()
Creates a closure capable of finalizing state a cloned proxy
private
createCloner(ClassMetadata $classMetadata, EntityPersister $entityPersister) : Closure
Parameters
- $classMetadata : ClassMetadata
- $entityPersister : EntityPersister
Tags
Return values
ClosurecreateInitializer()
Creates a closure capable of initializing a proxy
private
createInitializer(ClassMetadata $classMetadata, EntityPersister $entityPersister) : Closure
Parameters
- $classMetadata : ClassMetadata
- $entityPersister : EntityPersister
Tags
Return values
ClosurecreateLazyInitializer()
Creates a closure capable of initializing a proxy
private
createLazyInitializer(ClassMetadata $classMetadata, EntityPersister $entityPersister) : callable(Proxy): void
Parameters
- $classMetadata : ClassMetadata
- $entityPersister : EntityPersister
Tags
Return values
callable(Proxy): voidgenerateSerializeImpl()
private
generateSerializeImpl(ClassMetadata $class) : string
Parameters
- $class : ClassMetadata
Return values
stringgenerateSkippedProperties()
private
generateSkippedProperties(ClassMetadata $class) : string
Parameters
- $class : ClassMetadata
Return values
stringgenerateUseLazyGhostTrait()
private
generateUseLazyGhostTrait(ClassMetadata $class) : string
Parameters
- $class : ClassMetadata
Return values
stringgetProxyDefinition()
Get a proxy definition for the given class name.
private
getProxyDefinition(string $className) : ProxyDefinition
Parameters
- $className : string