2009-07-16 17:29:15 +04:00
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* This software consists of voluntary contributions made by many individuals
|
|
|
|
* and is licensed under the LGPL. For more information, see
|
|
|
|
* <http://www.doctrine-project.org>.
|
|
|
|
*/
|
|
|
|
|
2009-07-16 18:03:22 +04:00
|
|
|
namespace Doctrine\ORM\Proxy;
|
2009-07-16 17:29:15 +04:00
|
|
|
|
2009-10-15 00:18:36 +04:00
|
|
|
use Doctrine\ORM\EntityManager,
|
|
|
|
Doctrine\ORM\Mapping\ClassMetadata,
|
2012-01-16 13:57:29 +04:00
|
|
|
Doctrine\ORM\Mapping\AssociationMapping,
|
|
|
|
Doctrine\Common\Util\ClassUtils;
|
2009-07-16 17:29:15 +04:00
|
|
|
|
|
|
|
/**
|
2009-10-15 00:18:36 +04:00
|
|
|
* This factory is used to create proxy objects for entities at runtime.
|
2009-07-16 17:29:15 +04:00
|
|
|
*
|
|
|
|
* @author Roman Borschel <roman@code-factory.org>
|
2009-07-16 18:03:22 +04:00
|
|
|
* @author Giorgio Sironi <piccoloprincipeazzurro@gmail.com>
|
2009-07-16 17:29:15 +04:00
|
|
|
* @since 2.0
|
|
|
|
*/
|
2009-07-16 18:03:22 +04:00
|
|
|
class ProxyFactory
|
2009-07-16 17:29:15 +04:00
|
|
|
{
|
2009-10-15 00:18:36 +04:00
|
|
|
/** The EntityManager this factory is bound to. */
|
2009-07-16 17:29:15 +04:00
|
|
|
private $_em;
|
2009-10-15 00:18:36 +04:00
|
|
|
/** Whether to automatically (re)generate proxy classes. */
|
|
|
|
private $_autoGenerate;
|
|
|
|
/** The namespace that contains all proxy classes. */
|
|
|
|
private $_proxyNamespace;
|
|
|
|
/** The directory that contains all proxy classes. */
|
|
|
|
private $_proxyDir;
|
2009-07-16 17:29:15 +04:00
|
|
|
|
2012-01-16 13:57:29 +04:00
|
|
|
/**
|
|
|
|
* Used to match very simple id methods that don't need
|
|
|
|
* to be proxied since the identifier is known.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
const PATTERN_MATCH_ID_METHOD = '((public\s)?(function\s{1,}%s\s?\(\)\s{1,})\s{0,}{\s{0,}return\s{0,}\$this->%s;\s{0,}})i';
|
|
|
|
|
2009-07-16 17:29:15 +04:00
|
|
|
/**
|
2010-04-26 15:02:30 +04:00
|
|
|
* Initializes a new instance of the <tt>ProxyFactory</tt> class that is
|
|
|
|
* connected to the given <tt>EntityManager</tt>.
|
|
|
|
*
|
|
|
|
* @param EntityManager $em The EntityManager the new factory works for.
|
|
|
|
* @param string $proxyDir The directory to use for the proxy classes. It must exist.
|
|
|
|
* @param string $proxyNs The namespace to use for the proxy classes.
|
|
|
|
* @param boolean $autoGenerate Whether to automatically generate proxy classes.
|
2009-07-16 17:29:15 +04:00
|
|
|
*/
|
2009-10-15 00:18:36 +04:00
|
|
|
public function __construct(EntityManager $em, $proxyDir, $proxyNs, $autoGenerate = false)
|
2009-07-16 17:29:15 +04:00
|
|
|
{
|
2009-10-15 00:18:36 +04:00
|
|
|
if ( ! $proxyDir) {
|
2010-03-05 19:35:00 +03:00
|
|
|
throw ProxyException::proxyDirectoryRequired();
|
2009-10-15 00:18:36 +04:00
|
|
|
}
|
|
|
|
if ( ! $proxyNs) {
|
2010-03-05 19:35:00 +03:00
|
|
|
throw ProxyException::proxyNamespaceRequired();
|
2009-10-15 00:18:36 +04:00
|
|
|
}
|
2009-07-16 17:29:15 +04:00
|
|
|
$this->_em = $em;
|
2009-10-15 00:18:36 +04:00
|
|
|
$this->_proxyDir = $proxyDir;
|
|
|
|
$this->_autoGenerate = $autoGenerate;
|
|
|
|
$this->_proxyNamespace = $proxyNs;
|
2010-03-05 19:35:00 +03:00
|
|
|
}
|
|
|
|
|
2009-07-16 17:29:15 +04:00
|
|
|
/**
|
2009-10-15 00:18:36 +04:00
|
|
|
* Gets a reference proxy instance for the entity of the given type and identified by
|
|
|
|
* the given identifier.
|
2009-07-16 17:29:15 +04:00
|
|
|
*
|
|
|
|
* @param string $className
|
|
|
|
* @param mixed $identifier
|
|
|
|
* @return object
|
|
|
|
*/
|
2009-10-28 18:32:55 +03:00
|
|
|
public function getProxy($className, $identifier)
|
2009-07-16 17:29:15 +04:00
|
|
|
{
|
2012-01-16 13:57:29 +04:00
|
|
|
$fqn = ClassUtils::generateProxyClassName($className, $this->_proxyNamespace);
|
2010-03-05 19:35:00 +03:00
|
|
|
|
2010-11-06 00:17:05 +03:00
|
|
|
if (! class_exists($fqn, false)) {
|
2012-01-16 13:57:29 +04:00
|
|
|
$fileName = $this->getProxyFileName($className);
|
2010-11-06 00:17:05 +03:00
|
|
|
if ($this->_autoGenerate) {
|
2012-01-16 13:57:29 +04:00
|
|
|
$this->_generateProxyClass($this->_em->getClassMetadata($className), $fileName, self::$_proxyClassTemplate);
|
2010-11-06 00:17:05 +03:00
|
|
|
}
|
2009-10-15 00:18:36 +04:00
|
|
|
require $fileName;
|
|
|
|
}
|
2010-03-05 19:35:00 +03:00
|
|
|
|
2009-10-15 00:18:36 +04:00
|
|
|
if ( ! $this->_em->getMetadataFactory()->hasMetadataFor($fqn)) {
|
|
|
|
$this->_em->getMetadataFactory()->setMetadataFor($fqn, $this->_em->getClassMetadata($className));
|
|
|
|
}
|
2010-03-05 19:35:00 +03:00
|
|
|
|
2009-07-16 17:29:15 +04:00
|
|
|
$entityPersister = $this->_em->getUnitOfWork()->getEntityPersister($className);
|
2010-03-05 19:35:00 +03:00
|
|
|
|
2009-10-15 00:18:36 +04:00
|
|
|
return new $fqn($entityPersister, $identifier);
|
2009-07-16 17:29:15 +04:00
|
|
|
}
|
2010-03-05 19:35:00 +03:00
|
|
|
|
2012-01-16 13:57:29 +04:00
|
|
|
/**
|
|
|
|
* Generate the Proxy file name
|
|
|
|
*
|
|
|
|
* @param string $className
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
private function getProxyFileName($className)
|
|
|
|
{
|
|
|
|
return $this->_proxyDir . DIRECTORY_SEPARATOR . '__CG__' . str_replace('\\', '', $className) . '.php';
|
|
|
|
}
|
|
|
|
|
2009-10-15 00:18:36 +04:00
|
|
|
/**
|
|
|
|
* Generates proxy classes for all given classes.
|
2010-03-05 19:35:00 +03:00
|
|
|
*
|
2009-10-15 00:18:36 +04:00
|
|
|
* @param array $classes The classes (ClassMetadata instances) for which to generate proxies.
|
|
|
|
* @param string $toDir 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.
|
|
|
|
*/
|
|
|
|
public function generateProxyClasses(array $classes, $toDir = null)
|
|
|
|
{
|
|
|
|
$proxyDir = $toDir ?: $this->_proxyDir;
|
|
|
|
$proxyDir = rtrim($proxyDir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
|
|
|
|
foreach ($classes as $class) {
|
2010-08-08 14:05:21 +04:00
|
|
|
/* @var $class ClassMetadata */
|
|
|
|
if ($class->isMappedSuperclass) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-01-16 13:57:29 +04:00
|
|
|
$proxyFileName = $this->getProxyFileName($class->name);
|
|
|
|
$this->_generateProxyClass($class, $proxyFileName, self::$_proxyClassTemplate);
|
2009-10-15 00:18:36 +04:00
|
|
|
}
|
|
|
|
}
|
2010-03-05 19:35:00 +03:00
|
|
|
|
2009-10-15 00:18:36 +04:00
|
|
|
/**
|
2010-03-29 17:20:41 +04:00
|
|
|
* Generates a proxy class file.
|
2010-03-05 19:35:00 +03:00
|
|
|
*
|
2012-02-14 22:08:44 +04:00
|
|
|
* @param ClassMetadata $class Metadata for the original class
|
|
|
|
* @param string $fileName Filename (full path) for the generated class
|
|
|
|
* @param string $file The proxy class template data
|
2009-10-15 00:18:36 +04:00
|
|
|
*/
|
2012-02-14 22:07:51 +04:00
|
|
|
private function _generateProxyClass(ClassMetadata $class, $fileName, $file)
|
2009-10-15 00:18:36 +04:00
|
|
|
{
|
|
|
|
$methods = $this->_generateMethods($class);
|
|
|
|
$sleepImpl = $this->_generateSleep($class);
|
2011-02-26 14:47:59 +03:00
|
|
|
$cloneImpl = $class->reflClass->hasMethod('__clone') ? 'parent::__clone();' : ''; // hasMethod() checks case-insensitive
|
2009-10-15 00:18:36 +04:00
|
|
|
|
|
|
|
$placeholders = array(
|
|
|
|
'<namespace>',
|
|
|
|
'<proxyClassName>', '<className>',
|
2011-02-26 14:47:59 +03:00
|
|
|
'<methods>', '<sleepImpl>', '<cloneImpl>'
|
2009-10-15 00:18:36 +04:00
|
|
|
);
|
2009-10-31 11:59:27 +03:00
|
|
|
|
2012-01-16 13:57:29 +04:00
|
|
|
$className = ltrim($class->name, '\\');
|
|
|
|
$proxyClassName = ClassUtils::generateProxyClassName($class->name, $this->_proxyNamespace);
|
|
|
|
$parts = explode('\\', strrev($proxyClassName), 2);
|
|
|
|
$proxyClassNamespace = strrev($parts[1]);
|
|
|
|
$proxyClassName = strrev($parts[0]);
|
2009-10-31 11:59:27 +03:00
|
|
|
|
2009-10-15 00:18:36 +04:00
|
|
|
$replacements = array(
|
2012-01-16 13:57:29 +04:00
|
|
|
$proxyClassNamespace,
|
|
|
|
$proxyClassName,
|
|
|
|
$className,
|
|
|
|
$methods,
|
|
|
|
$sleepImpl,
|
|
|
|
$cloneImpl
|
2009-10-15 00:18:36 +04:00
|
|
|
);
|
2010-03-05 19:35:00 +03:00
|
|
|
|
2009-10-15 00:18:36 +04:00
|
|
|
$file = str_replace($placeholders, $replacements, $file);
|
|
|
|
|
2011-10-20 20:35:41 +04:00
|
|
|
$parentDirectory = dirname($fileName);
|
2011-10-25 06:45:23 +04:00
|
|
|
|
2011-10-25 22:51:09 +04:00
|
|
|
if ( ! is_dir($parentDirectory)) {
|
|
|
|
if (false === @mkdir($parentDirectory, 0775, true)) {
|
|
|
|
throw ProxyException::proxyDirectoryNotWritable();
|
|
|
|
}
|
|
|
|
} else if ( ! is_writable($parentDirectory)) {
|
2011-10-25 06:32:38 +04:00
|
|
|
throw ProxyException::proxyDirectoryNotWritable();
|
2011-10-20 20:35:41 +04:00
|
|
|
}
|
|
|
|
|
2010-07-23 01:11:23 +04:00
|
|
|
file_put_contents($fileName, $file, LOCK_EX);
|
2009-10-15 00:18:36 +04:00
|
|
|
}
|
2010-03-05 19:35:00 +03:00
|
|
|
|
2009-10-15 00:18:36 +04:00
|
|
|
/**
|
|
|
|
* Generates the methods of a proxy class.
|
2010-03-05 19:35:00 +03:00
|
|
|
*
|
2009-10-15 00:18:36 +04:00
|
|
|
* @param ClassMetadata $class
|
|
|
|
* @return string The code of the generated methods.
|
|
|
|
*/
|
|
|
|
private function _generateMethods(ClassMetadata $class)
|
|
|
|
{
|
|
|
|
$methods = '';
|
2010-03-05 19:35:00 +03:00
|
|
|
|
2011-11-13 20:16:43 +04:00
|
|
|
$methodNames = array();
|
2009-10-15 00:18:36 +04:00
|
|
|
foreach ($class->reflClass->getMethods() as $method) {
|
2010-01-06 17:12:27 +03:00
|
|
|
/* @var $method ReflectionMethod */
|
2011-11-13 20:16:43 +04:00
|
|
|
if ($method->isConstructor() || in_array(strtolower($method->getName()), array("__sleep", "__clone")) || isset($methodNames[$method->getName()])) {
|
2009-10-15 00:18:36 +04:00
|
|
|
continue;
|
|
|
|
}
|
2011-11-13 20:16:43 +04:00
|
|
|
$methodNames[$method->getName()] = true;
|
2010-03-05 19:35:00 +03:00
|
|
|
|
2009-10-15 00:18:36 +04:00
|
|
|
if ($method->isPublic() && ! $method->isFinal() && ! $method->isStatic()) {
|
2011-07-27 00:30:20 +04:00
|
|
|
$methods .= "\n" . ' public function ';
|
2010-05-10 18:17:17 +04:00
|
|
|
if ($method->returnsReference()) {
|
|
|
|
$methods .= '&';
|
|
|
|
}
|
|
|
|
$methods .= $method->getName() . '(';
|
2009-10-15 00:18:36 +04:00
|
|
|
$firstParam = true;
|
|
|
|
$parameterString = $argumentString = '';
|
2010-03-05 19:35:00 +03:00
|
|
|
|
2009-10-15 00:18:36 +04:00
|
|
|
foreach ($method->getParameters() as $param) {
|
|
|
|
if ($firstParam) {
|
|
|
|
$firstParam = false;
|
|
|
|
} else {
|
|
|
|
$parameterString .= ', ';
|
|
|
|
$argumentString .= ', ';
|
|
|
|
}
|
2010-03-05 19:35:00 +03:00
|
|
|
|
2009-10-15 00:18:36 +04:00
|
|
|
// We need to pick the type hint class too
|
|
|
|
if (($paramClass = $param->getClass()) !== null) {
|
|
|
|
$parameterString .= '\\' . $paramClass->getName() . ' ';
|
|
|
|
} else if ($param->isArray()) {
|
|
|
|
$parameterString .= 'array ';
|
|
|
|
}
|
2010-03-05 19:35:00 +03:00
|
|
|
|
2009-10-15 00:18:36 +04:00
|
|
|
if ($param->isPassedByReference()) {
|
|
|
|
$parameterString .= '&';
|
|
|
|
}
|
2010-03-05 19:35:00 +03:00
|
|
|
|
2009-10-15 00:18:36 +04:00
|
|
|
$parameterString .= '$' . $param->getName();
|
|
|
|
$argumentString .= '$' . $param->getName();
|
2010-03-05 19:35:00 +03:00
|
|
|
|
2009-10-15 00:18:36 +04:00
|
|
|
if ($param->isDefaultValueAvailable()) {
|
|
|
|
$parameterString .= ' = ' . var_export($param->getDefaultValue(), true);
|
|
|
|
}
|
|
|
|
}
|
2010-03-05 19:35:00 +03:00
|
|
|
|
2010-03-19 00:30:09 +03:00
|
|
|
$methods .= $parameterString . ')';
|
2011-07-27 00:30:20 +04:00
|
|
|
$methods .= "\n" . ' {' . "\n";
|
2011-05-20 22:50:03 +04:00
|
|
|
if ($this->isShortIdentifierGetter($method, $class)) {
|
2011-11-08 12:43:06 +04:00
|
|
|
$identifier = lcfirst(substr($method->getName(), 3));
|
|
|
|
|
2011-11-08 12:47:33 +04:00
|
|
|
$cast = in_array($class->fieldMappings[$identifier]['type'], array('integer', 'smallint')) ? '(int) ' : '';
|
2011-11-08 12:43:06 +04:00
|
|
|
|
2011-10-15 19:24:13 +04:00
|
|
|
$methods .= ' if ($this->__isInitialized__ === false) {' . "\n";
|
2011-11-08 12:43:06 +04:00
|
|
|
$methods .= ' return ' . $cast . '$this->_identifier["' . $identifier . '"];' . "\n";
|
2011-10-15 19:24:13 +04:00
|
|
|
$methods .= ' }' . "\n";
|
2011-05-20 22:50:03 +04:00
|
|
|
}
|
2011-07-27 00:30:20 +04:00
|
|
|
$methods .= ' $this->__load();' . "\n";
|
2010-03-19 07:19:15 +03:00
|
|
|
$methods .= ' return parent::' . $method->getName() . '(' . $argumentString . ');';
|
2011-07-27 00:30:20 +04:00
|
|
|
$methods .= "\n" . ' }' . "\n";
|
2009-10-15 00:18:36 +04:00
|
|
|
}
|
|
|
|
}
|
2010-03-05 19:35:00 +03:00
|
|
|
|
2009-10-15 00:18:36 +04:00
|
|
|
return $methods;
|
|
|
|
}
|
2010-03-05 19:35:00 +03:00
|
|
|
|
2011-05-20 22:50:03 +04:00
|
|
|
/**
|
2012-01-16 13:57:29 +04:00
|
|
|
* Check if the method is a short identifier getter.
|
|
|
|
*
|
|
|
|
* 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).
|
|
|
|
*
|
2011-05-20 22:50:03 +04:00
|
|
|
* @param ReflectionMethod $method
|
|
|
|
* @param ClassMetadata $class
|
|
|
|
* @return bool
|
|
|
|
*/
|
2012-02-14 22:12:20 +04:00
|
|
|
private function isShortIdentifierGetter($method, ClassMetadata $class)
|
2011-05-20 22:50:03 +04:00
|
|
|
{
|
2011-11-13 20:16:43 +04:00
|
|
|
$identifier = lcfirst(substr($method->getName(), 3));
|
2012-01-16 13:57:29 +04:00
|
|
|
$cheapCheck = (
|
2011-05-20 22:50:03 +04:00
|
|
|
$method->getNumberOfParameters() == 0 &&
|
|
|
|
substr($method->getName(), 0, 3) == "get" &&
|
2011-10-19 13:58:59 +04:00
|
|
|
in_array($identifier, $class->identifier, true) &&
|
|
|
|
$class->hasField($identifier) &&
|
2011-05-20 22:50:03 +04:00
|
|
|
(($method->getEndLine() - $method->getStartLine()) <= 4)
|
2011-11-08 12:43:06 +04:00
|
|
|
&& in_array($class->fieldMappings[$identifier]['type'], array('integer', 'bigint', 'smallint', 'string'))
|
2011-05-20 22:50:03 +04:00
|
|
|
);
|
2012-01-16 13:57:29 +04:00
|
|
|
|
|
|
|
if ($cheapCheck) {
|
2012-01-30 14:44:08 +04:00
|
|
|
$code = file($method->getDeclaringClass()->getFileName());
|
2012-01-16 13:57:29 +04:00
|
|
|
$code = trim(implode(" ", array_slice($code, $method->getStartLine() - 1, $method->getEndLine() - $method->getStartLine() + 1)));
|
|
|
|
|
|
|
|
$pattern = sprintf(self::PATTERN_MATCH_ID_METHOD, $method->getName(), $identifier);
|
|
|
|
|
|
|
|
if (preg_match($pattern, $code)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2011-05-20 22:50:03 +04:00
|
|
|
}
|
|
|
|
|
2009-10-15 00:18:36 +04:00
|
|
|
/**
|
|
|
|
* Generates the code for the __sleep method for a proxy class.
|
2010-03-05 19:35:00 +03:00
|
|
|
*
|
2009-10-15 00:18:36 +04:00
|
|
|
* @param $class
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
private function _generateSleep(ClassMetadata $class)
|
|
|
|
{
|
|
|
|
$sleepImpl = '';
|
2010-03-05 19:35:00 +03:00
|
|
|
|
2009-10-15 00:18:36 +04:00
|
|
|
if ($class->reflClass->hasMethod('__sleep')) {
|
2010-07-30 00:27:00 +04:00
|
|
|
$sleepImpl .= "return array_merge(array('__isInitialized__'), parent::__sleep());";
|
2009-10-15 00:18:36 +04:00
|
|
|
} else {
|
2010-07-30 00:27:00 +04:00
|
|
|
$sleepImpl .= "return array('__isInitialized__', ";
|
2009-10-15 00:18:36 +04:00
|
|
|
$first = true;
|
2010-03-05 19:35:00 +03:00
|
|
|
|
2009-10-15 00:18:36 +04:00
|
|
|
foreach ($class->getReflectionProperties() as $name => $prop) {
|
|
|
|
if ($first) {
|
|
|
|
$first = false;
|
|
|
|
} else {
|
|
|
|
$sleepImpl .= ', ';
|
|
|
|
}
|
2010-03-05 19:35:00 +03:00
|
|
|
|
2009-10-15 00:18:36 +04:00
|
|
|
$sleepImpl .= "'" . $name . "'";
|
|
|
|
}
|
2010-03-05 19:35:00 +03:00
|
|
|
|
2009-10-15 00:18:36 +04:00
|
|
|
$sleepImpl .= ');';
|
|
|
|
}
|
2010-03-05 19:35:00 +03:00
|
|
|
|
2009-10-15 00:18:36 +04:00
|
|
|
return $sleepImpl;
|
|
|
|
}
|
2010-03-05 19:35:00 +03:00
|
|
|
|
2010-04-26 15:02:30 +04:00
|
|
|
/** Proxy class code template */
|
2009-10-15 00:18:36 +04:00
|
|
|
private static $_proxyClassTemplate =
|
|
|
|
'<?php
|
2010-03-19 07:19:15 +03:00
|
|
|
|
|
|
|
namespace <namespace>;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* THIS CLASS WAS GENERATED BY THE DOCTRINE ORM. DO NOT EDIT THIS FILE.
|
|
|
|
*/
|
|
|
|
class <proxyClassName> extends \<className> implements \Doctrine\ORM\Proxy\Proxy
|
2010-03-19 00:30:09 +03:00
|
|
|
{
|
2010-03-19 07:19:15 +03:00
|
|
|
private $_entityPersister;
|
|
|
|
private $_identifier;
|
|
|
|
public $__isInitialized__ = false;
|
|
|
|
public function __construct($entityPersister, $identifier)
|
2010-03-19 00:30:09 +03:00
|
|
|
{
|
2010-03-19 07:19:15 +03:00
|
|
|
$this->_entityPersister = $entityPersister;
|
|
|
|
$this->_identifier = $identifier;
|
|
|
|
}
|
2011-06-05 10:44:38 +04:00
|
|
|
/** @private */
|
|
|
|
public function __load()
|
2010-03-19 07:19:15 +03:00
|
|
|
{
|
|
|
|
if (!$this->__isInitialized__ && $this->_entityPersister) {
|
|
|
|
$this->__isInitialized__ = true;
|
2011-07-09 14:12:44 +04:00
|
|
|
|
|
|
|
if (method_exists($this, "__wakeup")) {
|
|
|
|
// call this after __isInitialized__to avoid infinite recursion
|
|
|
|
// but before loading to emulate what ClassMetadata::newInstance()
|
|
|
|
// provides.
|
|
|
|
$this->__wakeup();
|
|
|
|
}
|
|
|
|
|
2010-03-19 07:19:15 +03:00
|
|
|
if ($this->_entityPersister->load($this->_identifier, $this) === null) {
|
|
|
|
throw new \Doctrine\ORM\EntityNotFoundException();
|
2009-10-15 00:18:36 +04:00
|
|
|
}
|
2010-07-30 00:27:00 +04:00
|
|
|
unset($this->_entityPersister, $this->_identifier);
|
2009-10-15 00:18:36 +04:00
|
|
|
}
|
2010-03-19 07:19:15 +03:00
|
|
|
}
|
2011-08-19 07:11:58 +04:00
|
|
|
|
2012-01-16 13:57:29 +04:00
|
|
|
/** @private */
|
|
|
|
public function __isInitialized()
|
|
|
|
{
|
|
|
|
return $this->__isInitialized__;
|
|
|
|
}
|
|
|
|
|
2010-03-19 07:19:15 +03:00
|
|
|
<methods>
|
2009-10-15 00:18:36 +04:00
|
|
|
|
2010-03-19 07:19:15 +03:00
|
|
|
public function __sleep()
|
|
|
|
{
|
|
|
|
<sleepImpl>
|
2009-10-15 00:18:36 +04:00
|
|
|
}
|
2011-02-26 14:47:59 +03:00
|
|
|
|
|
|
|
public function __clone()
|
|
|
|
{
|
|
|
|
if (!$this->__isInitialized__ && $this->_entityPersister) {
|
|
|
|
$this->__isInitialized__ = true;
|
|
|
|
$class = $this->_entityPersister->getClassMetadata();
|
|
|
|
$original = $this->_entityPersister->load($this->_identifier);
|
|
|
|
if ($original === null) {
|
|
|
|
throw new \Doctrine\ORM\EntityNotFoundException();
|
|
|
|
}
|
|
|
|
foreach ($class->reflFields AS $field => $reflProperty) {
|
|
|
|
$reflProperty->setValue($this, $reflProperty->getValue($original));
|
|
|
|
}
|
|
|
|
unset($this->_entityPersister, $this->_identifier);
|
|
|
|
}
|
|
|
|
<cloneImpl>
|
|
|
|
}
|
2009-10-15 00:18:36 +04:00
|
|
|
}';
|
2009-07-16 17:29:15 +04:00
|
|
|
}
|