From 6f1ddb6f4e154829c7cfa19006c34b7e25e07d08 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 25 Dec 2011 05:27:30 +0100 Subject: [PATCH 01/14] Generated proxies must be compatible with Doctrine\Common\Persistence\Proxy interface --- lib/Doctrine/ODM/PHPCR/Proxy/ProxyFactory.php | 683 +++++++++--------- 1 file changed, 344 insertions(+), 339 deletions(-) diff --git a/lib/Doctrine/ODM/PHPCR/Proxy/ProxyFactory.php b/lib/Doctrine/ODM/PHPCR/Proxy/ProxyFactory.php index fb83fcda6..cd634ec09 100644 --- a/lib/Doctrine/ODM/PHPCR/Proxy/ProxyFactory.php +++ b/lib/Doctrine/ODM/PHPCR/Proxy/ProxyFactory.php @@ -1,339 +1,344 @@ -. - */ - -namespace Doctrine\ODM\PHPCR\Proxy; - -use Doctrine\ODM\PHPCR\DocumentManager, - Doctrine\ODM\PHPCR\Mapping\ClassMetadata; - -/** - * This factory is used to create proxy objects for entities at runtime. - * - * @author Roman Borschel - * @author Giorgio Sironi - * @author Nils Adermann - * @author Johannes Stark - * @author David Buchmann - * - * This whole thing is copy & pasted from ORM - should really be slightly - * refactored to generate - */ -class ProxyFactory -{ - /** The DocumentManager this factory is bound to. */ - private $dm; - /** 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; - - /** - * Initializes a new instance of the ProxyFactory class that is - * connected to the given DocumentManager. - * - * @param DocumentManager $dm The DocumentManager 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. - */ - public function __construct(DocumentManager $dm, $proxyDir, $proxyNs, $autoGenerate = false) - { - if (!$proxyDir) { - throw ProxyException::proxyDirectoryRequired(); - } - if (!$proxyNs) { - throw ProxyException::proxyNamespaceRequired(); - } - $this->dm = $dm; - $this->proxyDir = $proxyDir; - $this->autoGenerate = $autoGenerate; - $this->proxyNamespace = $proxyNs; - } - - /** - * Gets a reference proxy instance for the entity of the given type and identified by - * the given identifier. - * - * @param string $className - * @param mixed $identifier - * @return object - */ - public function getProxy($className, $identifier) - { - $proxyClassName = str_replace('\\', '', $className) . 'ReferenceProxy'; - $fqn = $this->proxyNamespace . '\\' . $proxyClassName; - - if ($this->autoGenerate && !class_exists($fqn, false)) { - $fileName = $this->proxyDir . DIRECTORY_SEPARATOR . $proxyClassName . '.php'; - $this->generateProxyClass($this->dm->getClassMetadata($className), $proxyClassName, $fileName, self::$proxyClassTemplate); - require $fileName; - } - - if (!$this->dm->getMetadataFactory()->hasMetadataFor($fqn)) { - $this->dm->getMetadataFactory()->setMetadataFor($fqn, $this->dm->getClassMetadata($className)); - } - - return new $fqn($this->dm, $identifier); - } - - /** - * Generates proxy classes for all given classes. - * - * @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 DocumentManager 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) { - /* @var $class ClassMetadata */ - if ($class->isMappedSuperclass) { - continue; - } - - $proxyClassName = str_replace('\\', '', $class->name) . 'ReferenceProxy'; - $proxyFileName = $proxyDir . $proxyClassName . '.php'; - $this->generateProxyClass($class, $proxyClassName, $proxyFileName, self::$proxyClassTemplate); - } - } - - /** - * Generates a proxy class file. - * - * @param $class - * @param $originalClassName - * @param $proxyClassName - * @param $file The path of the file to write to. - */ - private function generateProxyClass($class, $proxyClassName, $fileName, $file) - { - $methods = $this->generateMethods($class); - $unsetAttributes = $this->getUnsetAttributes($class); - $sleepImpl = $this->generateSleep($class); - - $placeholders = array( - '', - '', '', - '', - '', '' - ); - - if (substr($class->name, 0, 1) == "\\") { - $className = substr($class->name, 1); - } else { - $className = $class->name; - } - - $replacements = array( - $this->proxyNamespace, - $proxyClassName, $className, - $unsetAttributes, - $methods, $sleepImpl - ); - - $file = str_replace($placeholders, $replacements, $file); - - file_put_contents($fileName, $file, LOCK_EX); - } - - /** - * Get the attributes of the document class - * - * @param ClassMetadata $class - * @return string The unset command for all document attributes - */ - private function getUnsetAttributes(ClassMetadata $class) - { - $attributes = ""; - foreach ($class->fieldMappings as $field) { - $attributes .= '$this->'.$field["fieldName"]; - $attributes .= ", "; - } - - foreach ($class->associationsMappings as $field) { - $attributes .= '$this->'.$field["fieldName"]; - $attributes .= ", "; - } - - foreach ($class->referrersMappings as $field) { - $attributes .= '$this->'.$field["fieldName"]; - $attributes .= ", "; - } - - foreach ($class->childrenMappings as $field) { - $attributes .= '$this->'.$field["fieldName"]; - $attributes .= ", "; - } - - foreach ($class->childMappings as $field) { - $attributes .= '$this->'.$field["fieldName"]; - $attributes .= ", "; - } - - $attributes .= '$this->id'; - - return "unset(".$attributes.");"; - } - - /** - * Generates the methods of a proxy class. - * - * @param ClassMetadata $class - * @return string The code of the generated methods. - */ - private function generateMethods(ClassMetadata $class) - { - $methods = ''; - - foreach ($class->reflClass->getMethods() as $method) { - /* @var $method ReflectionMethod */ - if ($method->isConstructor() || strtolower($method->getName()) == "__sleep") { - continue; - } - - if ($method->isPublic() && !$method->isFinal() && !$method->isStatic()) { - $methods .= PHP_EOL . ' public function '; - if ($method->returnsReference()) { - $methods .= '&'; - } - $methods .= $method->getName() . '('; - $firstParam = true; - $parameterString = $argumentString = ''; - - foreach ($method->getParameters() as $param) { - if ($firstParam) { - $firstParam = false; - } else { - $parameterString .= ', '; - $argumentString .= ', '; - } - - // We need to pick the type hint class too - if (($paramClass = $param->getClass()) !== null) { - $parameterString .= '\\' . $paramClass->getName() . ' '; - } elseif ($param->isArray()) { - $parameterString .= 'array '; - } - - if ($param->isPassedByReference()) { - $parameterString .= '&'; - } - - $parameterString .= '$' . $param->getName(); - $argumentString .= '$' . $param->getName(); - - if ($param->isDefaultValueAvailable()) { - $parameterString .= ' = ' . var_export($param->getDefaultValue(), true); - } - } - - $methods .= $parameterString . ')'; - $methods .= PHP_EOL . ' {' . PHP_EOL; - $methods .= ' $this->__load();' . PHP_EOL; - $methods .= ' return parent::' . $method->getName() . '(' . $argumentString . ');'; - $methods .= PHP_EOL . ' }' . PHP_EOL; - } - } - - return $methods; - } - - /** - * Generates the code for the __sleep method for a proxy class. - * - * @param $class - * @return string - */ - private function generateSleep(ClassMetadata $class) - { - $sleepImpl = ''; - - if ($class->reflClass->hasMethod('__sleep')) { - $sleepImpl .= "return array_merge(array('__isInitialized__'), parent::__sleep());"; - } else { - $sleepImpl .= "return array('__isInitialized__', "; - - $properties = array(); - foreach ($class->fieldMappings as $name => $prop) { - $properties[] = "'$name'"; - } - - $sleepImpl .= implode(',', $properties) . ');'; - } - - return $sleepImpl; - } - - /** Proxy class code template */ - private static $proxyClassTemplate = <<<'PHP' -; - -/** - * THIS CLASS WAS GENERATED BY THE DOCTRINE ORM. DO NOT EDIT THIS FILE. - */ -class extends \ implements \Doctrine\ODM\PHPCR\Proxy\Proxy -{ - private $__doctrineDocumentManager__; - private $__doctrineIdentifier__; - public $__isInitialized__ = false; - public function __construct($documentManager, $identifier) - { - - $this->__doctrineDocumentManager__ = $documentManager; - } - - public function __load() - { - if (!$this->__isInitialized__ && $this->__doctrineDocumentManager__) { - $this->__isInitialized__ = true; - $this->__doctrineDocumentManager__->getRepository(get_class($this))->refreshDocumentForProxy($this); - unset($this->__doctrineDocumentManager__); - } - } - - - - public function __sleep() - { - - } - - public function __set($name, $value) - { - $this->__load(); - $this->$name = $value; - } - - public function &__get($name) - { - $this->__load(); - return $this->$name; - } - -} -PHP; -} - +. + */ + +namespace Doctrine\ODM\PHPCR\Proxy; + +use Doctrine\ODM\PHPCR\DocumentManager, + Doctrine\ODM\PHPCR\Mapping\ClassMetadata; + +/** + * This factory is used to create proxy objects for entities at runtime. + * + * @author Roman Borschel + * @author Giorgio Sironi + * @author Nils Adermann + * @author Johannes Stark + * @author David Buchmann + * + * This whole thing is copy & pasted from ORM - should really be slightly + * refactored to generate + */ +class ProxyFactory +{ + /** The DocumentManager this factory is bound to. */ + private $dm; + /** 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; + + /** + * Initializes a new instance of the ProxyFactory class that is + * connected to the given DocumentManager. + * + * @param DocumentManager $dm The DocumentManager 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. + */ + public function __construct(DocumentManager $dm, $proxyDir, $proxyNs, $autoGenerate = false) + { + if (!$proxyDir) { + throw ProxyException::proxyDirectoryRequired(); + } + if (!$proxyNs) { + throw ProxyException::proxyNamespaceRequired(); + } + $this->dm = $dm; + $this->proxyDir = $proxyDir; + $this->autoGenerate = $autoGenerate; + $this->proxyNamespace = $proxyNs; + } + + /** + * Gets a reference proxy instance for the entity of the given type and identified by + * the given identifier. + * + * @param string $className + * @param mixed $identifier + * @return object + */ + public function getProxy($className, $identifier) + { + $proxyClassName = str_replace('\\', '', $className) . 'ReferenceProxy'; + $fqn = $this->proxyNamespace . '\\' . $proxyClassName; + + if ($this->autoGenerate && !class_exists($fqn, false)) { + $fileName = $this->proxyDir . DIRECTORY_SEPARATOR . $proxyClassName . '.php'; + $this->generateProxyClass($this->dm->getClassMetadata($className), $proxyClassName, $fileName, self::$proxyClassTemplate); + require $fileName; + } + + if (!$this->dm->getMetadataFactory()->hasMetadataFor($fqn)) { + $this->dm->getMetadataFactory()->setMetadataFor($fqn, $this->dm->getClassMetadata($className)); + } + + return new $fqn($this->dm, $identifier); + } + + /** + * Generates proxy classes for all given classes. + * + * @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 DocumentManager 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) { + /* @var $class ClassMetadata */ + if ($class->isMappedSuperclass) { + continue; + } + + $proxyClassName = str_replace('\\', '', $class->name) . 'ReferenceProxy'; + $proxyFileName = $proxyDir . $proxyClassName . '.php'; + $this->generateProxyClass($class, $proxyClassName, $proxyFileName, self::$proxyClassTemplate); + } + } + + /** + * Generates a proxy class file. + * + * @param $class + * @param $originalClassName + * @param $proxyClassName + * @param $file The path of the file to write to. + */ + private function generateProxyClass($class, $proxyClassName, $fileName, $file) + { + $methods = $this->generateMethods($class); + $unsetAttributes = $this->getUnsetAttributes($class); + $sleepImpl = $this->generateSleep($class); + + $placeholders = array( + '', + '', '', + '', + '', '' + ); + + if (substr($class->name, 0, 1) == "\\") { + $className = substr($class->name, 1); + } else { + $className = $class->name; + } + + $replacements = array( + $this->proxyNamespace, + $proxyClassName, $className, + $unsetAttributes, + $methods, $sleepImpl + ); + + $file = str_replace($placeholders, $replacements, $file); + + file_put_contents($fileName, $file, LOCK_EX); + } + + /** + * Get the attributes of the document class + * + * @param ClassMetadata $class + * @return string The unset command for all document attributes + */ + private function getUnsetAttributes(ClassMetadata $class) + { + $attributes = ""; + foreach ($class->fieldMappings as $field) { + $attributes .= '$this->'.$field["fieldName"]; + $attributes .= ", "; + } + + foreach ($class->associationsMappings as $field) { + $attributes .= '$this->'.$field["fieldName"]; + $attributes .= ", "; + } + + foreach ($class->referrersMappings as $field) { + $attributes .= '$this->'.$field["fieldName"]; + $attributes .= ", "; + } + + foreach ($class->childrenMappings as $field) { + $attributes .= '$this->'.$field["fieldName"]; + $attributes .= ", "; + } + + foreach ($class->childMappings as $field) { + $attributes .= '$this->'.$field["fieldName"]; + $attributes .= ", "; + } + + $attributes .= '$this->id'; + + return "unset(".$attributes.");"; + } + + /** + * Generates the methods of a proxy class. + * + * @param ClassMetadata $class + * @return string The code of the generated methods. + */ + private function generateMethods(ClassMetadata $class) + { + $methods = ''; + + foreach ($class->reflClass->getMethods() as $method) { + /* @var $method ReflectionMethod */ + if ($method->isConstructor() || strtolower($method->getName()) == "__sleep") { + continue; + } + + if ($method->isPublic() && !$method->isFinal() && !$method->isStatic()) { + $methods .= PHP_EOL . ' public function '; + if ($method->returnsReference()) { + $methods .= '&'; + } + $methods .= $method->getName() . '('; + $firstParam = true; + $parameterString = $argumentString = ''; + + foreach ($method->getParameters() as $param) { + if ($firstParam) { + $firstParam = false; + } else { + $parameterString .= ', '; + $argumentString .= ', '; + } + + // We need to pick the type hint class too + if (($paramClass = $param->getClass()) !== null) { + $parameterString .= '\\' . $paramClass->getName() . ' '; + } elseif ($param->isArray()) { + $parameterString .= 'array '; + } + + if ($param->isPassedByReference()) { + $parameterString .= '&'; + } + + $parameterString .= '$' . $param->getName(); + $argumentString .= '$' . $param->getName(); + + if ($param->isDefaultValueAvailable()) { + $parameterString .= ' = ' . var_export($param->getDefaultValue(), true); + } + } + + $methods .= $parameterString . ')'; + $methods .= PHP_EOL . ' {' . PHP_EOL; + $methods .= ' $this->__load();' . PHP_EOL; + $methods .= ' return parent::' . $method->getName() . '(' . $argumentString . ');'; + $methods .= PHP_EOL . ' }' . PHP_EOL; + } + } + + return $methods; + } + + /** + * Generates the code for the __sleep method for a proxy class. + * + * @param $class + * @return string + */ + private function generateSleep(ClassMetadata $class) + { + $sleepImpl = ''; + + if ($class->reflClass->hasMethod('__sleep')) { + $sleepImpl .= "return array_merge(array('__isInitialized__'), parent::__sleep());"; + } else { + $sleepImpl .= "return array('__isInitialized__', "; + + $properties = array(); + foreach ($class->fieldMappings as $name => $prop) { + $properties[] = "'$name'"; + } + + $sleepImpl .= implode(',', $properties) . ');'; + } + + return $sleepImpl; + } + + /** Proxy class code template */ + private static $proxyClassTemplate = <<<'PHP' +; + +/** + * THIS CLASS WAS GENERATED BY THE DOCTRINE ORM. DO NOT EDIT THIS FILE. + */ +class extends \ implements \Doctrine\ODM\PHPCR\Proxy\Proxy +{ + private $__doctrineDocumentManager__; + private $__doctrineIdentifier__; + public $__isInitialized__ = false; + public function __construct($documentManager, $identifier) + { + + $this->__doctrineDocumentManager__ = $documentManager; + } + + public function __load() + { + if (!$this->__isInitialized__ && $this->__doctrineDocumentManager__) { + $this->__isInitialized__ = true; + $this->__doctrineDocumentManager__->getRepository(get_class($this))->refreshDocumentForProxy($this); + unset($this->__doctrineDocumentManager__); + } + } + + + + public function __sleep() + { + + } + + public function __set($name, $value) + { + $this->__load(); + $this->$name = $value; + } + + public function &__get($name) + { + $this->__load(); + return $this->$name; + } + + public function __isInitialized() + { + return $this->__isInitialized__; + } + +} +PHP; +} + From 6ded1d308899f0e42dbcad00c9216a7120382dd5 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 25 Dec 2011 05:31:15 +0100 Subject: [PATCH 02/14] Generated proxies must be compatible with Doctrine\Common\Persistence\Proxy interface From 26c931a290ce6923a1717cb4d2eeaeda4a7997b3 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 25 Dec 2011 05:35:56 +0100 Subject: [PATCH 03/14] Better exceptions for non-mapped classes --- .../ODM/PHPCR/Mapping/MappingException.php | 176 +++++++++--------- 1 file changed, 88 insertions(+), 88 deletions(-) diff --git a/lib/Doctrine/ODM/PHPCR/Mapping/MappingException.php b/lib/Doctrine/ODM/PHPCR/Mapping/MappingException.php index 1f0ebc732..ac2c5a524 100644 --- a/lib/Doctrine/ODM/PHPCR/Mapping/MappingException.php +++ b/lib/Doctrine/ODM/PHPCR/Mapping/MappingException.php @@ -1,88 +1,88 @@ -. - */ - -namespace Doctrine\ODM\PHPCR\Mapping; - -/** - * Mapping exception class - * - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @link www.doctrine-project.com - * @since 1.0 - * @author Benjamin Eberlei - * @author Lukas Kahwe Smith - */ -class MappingException extends \Exception -{ - public static function classNotFound($className) - { - return new self('The class: ' . $className . ' could not be found'); - } - - public static function classIsNotAValidDocument($className) - { - return new self('Class '.$className.' is not a valid document or mapped super class.'); - } - - public static function reflectionFailure($document, \ReflectionException $previousException) - { - return new self('An error occurred in ' . $document, 0, $previousException); - } - - /** - * @param string $document The document's name - * @param string $fieldName The name of the field that was already declared - */ - public static function duplicateFieldMapping($document, $fieldName) { - return new self('Property "'.$fieldName.'" in "'.$document.'" was already declared, but it must be declared only once'); - } - - /** - * @param string $document The document's name - * @param string $fieldName The name of the field that was already declared - */ - public static function missingTypeDefinition($document, $fieldName) { - return new self('Property "'.$fieldName.'" in "'.$document.'" must have a type attribute defined'); - } - - public static function fileMappingDriversRequireConfiguredDirectoryPath() - { - return new self('File mapping drivers must have a valid directory path, however the given path seems to be incorrect!'); - } - - public static function aliasIsNotSpecified($document) - { - return new self('Document '.$document.' must specify an alias'); - } - - public static function classNotMapped() - { - return new self(); - } - - public static function noTypeSpecified() - { - return new self(); - } - - public static function mappingNotFound($className, $fieldName) - { - return new self("No mapping found for field '$fieldName' in class '$className'."); - } -} +. + */ + +namespace Doctrine\ODM\PHPCR\Mapping; + +/** + * Mapping exception class + * + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @link www.doctrine-project.com + * @since 1.0 + * @author Benjamin Eberlei + * @author Lukas Kahwe Smith + */ +class MappingException extends \Exception +{ + public static function classNotFound($className) + { + return new self('The class: ' . $className . ' could not be found'); + } + + public static function classIsNotAValidDocument($className) + { + return new self('Class '.$className.' is not a valid document or mapped super class.'); + } + + public static function reflectionFailure($document, \ReflectionException $previousException) + { + return new self('An error occurred in ' . $document, 0, $previousException); + } + + /** + * @param string $document The document's name + * @param string $fieldName The name of the field that was already declared + */ + public static function duplicateFieldMapping($document, $fieldName) { + return new self('Property "'.$fieldName.'" in "'.$document.'" was already declared, but it must be declared only once'); + } + + /** + * @param string $document The document's name + * @param string $fieldName The name of the field that was already declared + */ + public static function missingTypeDefinition($document, $fieldName) { + return new self('Property "'.$fieldName.'" in "'.$document.'" must have a type attribute defined'); + } + + public static function fileMappingDriversRequireConfiguredDirectoryPath() + { + return new self('File mapping drivers must have a valid directory path, however the given path seems to be incorrect!'); + } + + public static function aliasIsNotSpecified($document) + { + return new self('Document '.$document.' must specify an alias'); + } + + public static function classNotMapped($className) + { + return new self('Class ' . $className . ' is not mapped to a document'); + } + + public static function noTypeSpecified() + { + return new self(); + } + + public static function mappingNotFound($className, $fieldName) + { + return new self("No mapping found for field '$fieldName' in class '$className'."); + } +} From d705bbe8e32a1a3b9cc3334444f72fb10c1f8b11 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 25 Dec 2011 05:46:40 +0100 Subject: [PATCH 04/14] First cleanup of code that is duplicate of what is inherited by Doctrine\Common\Persistence\ClassMetadataFactory Removing explicit public API that allowed loading metadata for alias. Fixing "use" coding conventions - still not ready for merge - --- .../PHPCR/Mapping/ClassMetadataFactory.php | 417 ++++++------------ 1 file changed, 139 insertions(+), 278 deletions(-) diff --git a/lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadataFactory.php b/lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadataFactory.php index 449d20f49..dde01ebe1 100644 --- a/lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadataFactory.php +++ b/lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadataFactory.php @@ -1,278 +1,139 @@ -. - */ - -namespace Doctrine\ODM\PHPCR\Mapping; - -use Doctrine\ODM\PHPCR\DocumentManager, - Doctrine\ODM\PHPCR\Mapping\ClassMetadata, - Doctrine\ODM\PHPCR\PHPCRException, - Doctrine\Common\Cache\Cache; - -/** - * The ClassMetadataFactory is used to create ClassMetadata objects that contain all the - * metadata mapping information of a class which describes how a class should be mapped - * to a document database. - - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @link www.doctrine-project.com - * @since 1.0 - * @author Benjamin Eberlei - * @author Lukas Kahwe Smith - */ -class ClassMetadataFactory -{ - /** - * @var DocumentManager - */ - private $dm; - - /** - * @var array - */ - private $loadedMetadata = array(); - - /** - * @var array - */ - private $loadedAliases = array(); - - /** - * The used metadata driver. - * - * @var Doctrine\ODM\PHPCR\Mapping\Driver\Driver - */ - private $driver; - - /** - * The used cache driver. - * - * @var Cache - */ - private $cacheDriver; - - /** - * Creates a new factory instance that uses the given DocumentManager instance. - * - * @param $dm The DocumentManager instance - */ - public function __construct(DocumentManager $dm) - { - $this->dm = $dm; - $this->driver = $this->dm->getConfiguration()->getMetadataDriverImpl(); - } - - /** - * Sets the cache driver used by the factory to cache ClassMetadata instances. - * - * @param Doctrine\Common\Cache\Cache $cacheDriver - */ - public function setCacheDriver($cacheDriver) - { - $this->cacheDriver = $cacheDriver; - } - - /** - * Gets the cache driver used by the factory to cache ClassMetadata instances. - * - * @return Doctrine\Common\Cache\Cache - */ - public function getCacheDriver() - { - return $this->cacheDriver; - } - - /** - * Gets the array of loaded ClassMetadata instances. - * - * @return array $loadedMetadata The loaded metadata. - */ - public function getLoadedMetadata() - { - return $this->loadedMetadata; - } - - /** - * Forces the factory to load the metadata of all classes known to the underlying - * mapping driver. - * - * @return array The ClassMetadata instances of all mapped classes. - */ - public function getAllMetadata() - { - $metadata = array(); - foreach ($this->driver->getAllClassNames() as $className) { - $metadata[] = $this->getMetadataFor($className); - } - - return $metadata; - } - - public function getMetadataForAlias($alias) - { - if (isset($this->loadedAliases[$alias])) { - return $this->loadedAliases[$alias]; - } - - if ($this->cacheDriver && ($cached = $this->cacheDriver->fetch("$alias\$PHPCRODMALIAS")) !== false) { - return $this->loadedAliases[$alias] = $cached; - } - - foreach ($this->loadedMetadata as $metadata) { - if ($metadata->alias === $alias) { - $this->loadedAliases[$alias] = $metadata; - if ($this->cacheDriver) { - $this->cacheDriver->save( - "$alias\$PHPCRODMALIAS", $this->loadedAliases[$alias], null - ); - } - return $metadata; - } - } - - foreach ($this->driver->getAllClassNames() as $className) { - $metadata = $this->getMetadataFor($className); - if ($metadata->alias === $alias) { - $this->loadedAliases[$alias] = $metadata; - if ($this->cacheDriver) { - $this->cacheDriver->save( - "$alias\$PHPCRODMALIAS", $this->loadedAliases[$alias], null - ); - } - return $metadata; - } - } - - throw new MappingException('Alias '.$alias.' could not be resolved to a document class name'); - } - - /** - * Gets the class metadata descriptor for a class. - * - * @param string $className The name of the class. - * @return Doctrine\ODM\PHPCR\Mapping\ClassMetadata - */ - public function getMetadataFor($className) - { - if (!isset($this->loadedMetadata[$className])) { - $realClassName = $className; - - // Check for namespace alias - if (strpos($className, ':') !== false) { - list($namespaceAlias, $simpleClassName) = explode(':', $className); - $realClassName = $this->dm->getConfiguration()->getDocumentNamespace($namespaceAlias) . '\\' . $simpleClassName; - - if (isset($this->loadedMetadata[$realClassName])) { - // We do not have the alias name in the map, include it - $this->loadedMetadata[$className] = $this->loadedMetadata[$realClassName]; - - return $this->loadedMetadata[$realClassName]; - } - } - - if ($this->cacheDriver) { - if (($cached = $this->cacheDriver->fetch("$realClassName\$PHPCRODMCLASSMETADATA")) !== false) { - $this->loadedMetadata[$realClassName] = $cached; - } else { - foreach ($this->loadMetadata($realClassName) as $loadedClassName) { - $this->cacheDriver->save( - "$loadedClassName\$PHPCRODMCLASSMETADATA", $this->loadedMetadata[$loadedClassName], null - ); - } - } - } else { - $this->loadMetadata($realClassName); - } - - if ($className != $realClassName) { - // We do not have the alias name in the map, include it - $this->loadedMetadata[$className] = $this->loadedMetadata[$realClassName]; - } - } - - if (!isset($this->loadedMetadata[$className])) { - throw MappingException::classNotMapped(); - } - - return $this->loadedMetadata[$className]; - } - - /** - * Loads the metadata of the class in question and all it's ancestors whose metadata - * is still not loaded. - * - * @param string $className The name of the class for which the metadata should get loaded. - */ - private function loadMetadata($className) - { - if (!class_exists($className)) { - throw MappingException::classNotFound($className); - } - - $this->loadedMetadata[$className] = new ClassMetadata($className); - $this->driver->loadMetadataForClass($className, $this->loadedMetadata[$className]); - } - - /** - * Checks whether the factory has the metadata for a class loaded already. - * - * @param string $className - * @return boolean TRUE if the metadata of the class in question is already loaded, FALSE otherwise. - */ - public function hasMetadataFor($className) - { - return isset($this->loadedMetadata[$className]); - } - - /** - * Sets the metadata descriptor for a specific class. - * - * NOTE: This is only useful in very special cases, like when generating proxy classes. - * - * @param string $className - * @param ClassMetadata $class - */ - public function setMetadataFor($className, $class) - { - $this->loadedMetadata[$className] = $class; - } - - /** - * Creates a new ClassMetadata instance for the given class name. - * - * @param string $className - * @return Doctrine\ODM\PHPCR\Mapping\ClassMetadata - */ - protected function newClassMetadataInstance($className) - { - return new ClassMetadata($className); - } - - /** - * Whether the class with the specified name should have its metadata loaded. - * This is only the case if it is either mapped as an Entity or a - * MappedSuperclass. - * - * @param string $className - * @return boolean - */ - public function isTransient($className) - { - return $this->driver->isTransient($className); - } -} +. + */ + +namespace Doctrine\ODM\PHPCR\Mapping; + +use Doctrine\ODM\PHPCR\DocumentManager; +use Doctrine\ODM\PHPCR\Mapping\ClassMetadata; +use Doctrine\ODM\PHPCR\PHPCRException; +use Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory; + +/** + * The ClassMetadataFactory is used to create ClassMetadata objects that contain all the + * metadata mapping information of a class which describes how a class should be mapped + * to a document database. + + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @link www.doctrine-project.com + * @since 1.0 + * @author Benjamin Eberlei + * @author Lukas Kahwe Smith + */ +class ClassMetadataFactory extends AbstractClassMetadataFactory +{ + + /** + * {@inheritdoc} + */ + protected $cacheSalt = '\$PHPCRODMCLASSMETADATA'; + + /** + * @var DocumentManager + */ + private $dm; + + /** + * The used metadata driver. + * + * @var \Doctrine\ODM\PHPCR\Mapping\Driver\Driver + */ + private $driver; + + /** + * Creates a new factory instance that uses the given DocumentManager instance. + * + * @param $dm The DocumentManager instance + */ + public function __construct(DocumentManager $dm) + { + $this->dm = $dm; + $this->driver = $this->dm->getConfiguration()->getMetadataDriverImpl(); + } + + /** + * {@inheritdoc} + * + * @throws MappingException + */ + public function getMetadataFor($className) + { + if ($metadata = parent::getMetadataFor($className)) { + return $metadata; + } + throw MappingException::classNotMapped($className); + } + + /** + * {@inheritdoc} + * + * @throws MappingException + */ + function loadMetadata($className) + { + if (class_exists($className)) { + return parent::loadMetadata($className); + } + throw MappingException::classNotFound($className); + } + + + /** + * {@inheritdoc} + */ + protected function newClassMetadataInstance($className) + { + return new ClassMetadata($className); + } + + /** + * {@inheritdoc} + */ + protected function getFqcnFromAlias($namespaceAlias, $simpleClassName) + { + return $this->dm->getConfiguration()->getDocumentNamespace($namespaceAlias) + . '\\' . $simpleClassName; + } + + /** + * {@inheritdoc} + * + * @todo unclear usage of rootEntityFound + */ + protected function doLoadMetadata($class, $parent, $rootEntityFound) { + if ($parent) { + $this->getDriver()->loadMetadataForClass($parent->name, $parent); + } + $this->getDriver()->loadMetadataForClass($class->name, $class); + } + + /** + * {@inheritdoc} + */ + protected function getDriver() { + return $this->driver; + } + + /** + * {@inheritdoc} + */ + protected function initialize() { + $this->initialized = true; + } + +} From 8b8e4f6f1e12224c965805e34c0e47562c0cffdc Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 25 Dec 2011 05:56:29 +0100 Subject: [PATCH 05/14] Fixing doctrine-common version (using current master) --- lib/vendor/doctrine-common | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/vendor/doctrine-common b/lib/vendor/doctrine-common index 583b0e1d4..16b2385b3 160000 --- a/lib/vendor/doctrine-common +++ b/lib/vendor/doctrine-common @@ -1 +1 @@ -Subproject commit 583b0e1d461d63d928cbf5ca18a6a408eeaaf1e9 +Subproject commit 16b2385b3ce5319d88969f18694e4b36533bd258 From ac21cd185f1b65b386fc10920a701233eb008171 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Mon, 26 Dec 2011 01:42:08 +0100 Subject: [PATCH 06/14] Updating drivers for compatibility with latest Doctrine Common master --- .../PHPCR/Mapping/Driver/AnnotationDriver.php | 229 ++++-------------- .../Mapping/Driver/BuiltinDocumentsDriver.php | 2 +- .../ODM/PHPCR/Mapping/Driver/Driver.php | 27 +-- .../ODM/PHPCR/Mapping/Driver/DriverChain.php | 2 +- .../ODM/PHPCR/Mapping/Driver/PHPDriver.php | 2 +- .../ODM/PHPCR/Mapping/Driver/XmlDriver.php | 2 +- .../ODM/PHPCR/Mapping/Driver/YamlDriver.php | 4 +- 7 files changed, 57 insertions(+), 211 deletions(-) diff --git a/lib/Doctrine/ODM/PHPCR/Mapping/Driver/AnnotationDriver.php b/lib/Doctrine/ODM/PHPCR/Mapping/Driver/AnnotationDriver.php index 5c4614776..109feae53 100644 --- a/lib/Doctrine/ODM/PHPCR/Mapping/Driver/AnnotationDriver.php +++ b/lib/Doctrine/ODM/PHPCR/Mapping/Driver/AnnotationDriver.php @@ -21,9 +21,10 @@ use Doctrine\Common\Annotations\AnnotationReader, Doctrine\Common\Annotations\Reader, + Doctrine\Common\Persistence\Mapping\Driver\AnnotationDriver as AbstractAnnotationDriver, + Doctrine\Common\Persistence\Mapping\ClassMetadata, Doctrine\ODM\PHPCR\Event, Doctrine\ODM\PHPCR\Mapping\Annotations as ODM, - Doctrine\ODM\PHPCR\Mapping\ClassMetadata, Doctrine\ODM\PHPCR\Mapping\MappingException; /** @@ -37,87 +38,29 @@ * @author Daniel Barsotti * @author David Buchmann */ -class AnnotationDriver implements Driver +class AnnotationDriver extends AbstractAnnotationDriver implements Driver { - /** - * The AnnotationReader. - * - * @var AnnotationReader - */ - private $reader; - - /** - * The paths where to look for mapping files. - * - * @var array - */ - private $paths = array(); - - /** - * The file extension of mapping documents. - * - * @var string - */ - private $fileExtension = '.php'; - - /** - * @param array - */ - private $classNames; /** + * {@inheritdoc} + * * Document annotation classes, ordered by precedence. */ - static private $documentAnnotationClasses = array( - 'Doctrine\\ODM\\PHPCR\\Mapping\\Annotations\\Document', - 'Doctrine\\ODM\\PHPCR\\Mapping\\Annotations\\MappedSuperclass', + protected $entityAnnotationClasses = array( + 'Doctrine\\ODM\\PHPCR\\Mapping\\Annotations\\Document' => 0, + 'Doctrine\\ODM\\PHPCR\\Mapping\\Annotations\\MappedSuperclass' => 1, ); - /** - * Initializes a new AnnotationDriver that uses the given AnnotationReader for reading - * docblock annotations. - * - * @param $reader The AnnotationReader to use. - * @param string|array $paths One or multiple paths where mapping classes can be found. - */ - public function __construct(Reader $reader, $paths = null) - { - $this->reader = $reader; - if ($paths) { - $this->addPaths((array) $paths); - } - } - - /** - * Append lookup paths to metadata driver. - * - * @param array $paths - */ - public function addPaths(array $paths) - { - $this->paths = array_unique(array_merge($this->paths, $paths)); - } - - /** - * Retrieve the defined metadata lookup paths. - * - * @return array - */ - public function getPaths() - { - return $this->paths; - } - /** * {@inheritdoc} */ - public function loadMetadataForClass($className, ClassMetadata $class) + public function loadMetadataForClass($className, ClassMetadata $metadata) { - $reflClass = $class->getReflectionClass(); + $reflClass = $metadata->getReflectionClass(); $documentAnnots = array(); foreach ($this->reader->getClassAnnotations($reflClass) as $annot) { - foreach (self::$documentAnnotationClasses as $i => $annotClass) { + foreach ($this->entityAnnotationClasses as $annotClass => $i) { if ($annot instanceof $annotClass) { $documentAnnots[$i] = $annot; } @@ -135,22 +78,22 @@ public function loadMetadataForClass($className, ClassMetadata $class) throw new MappingException("Alias must be specified in the Document() annotation mapping of $className"); } - $class->setAlias($documentAnnot->alias); + $metadata->setAlias($documentAnnot->alias); if (isset($documentAnnot->versionable) && $documentAnnot->versionable) { - $class->setVersioned(true); + $metadata->setVersioned(true); } - $class->setNodeType($documentAnnot->nodeType); + $metadata->setNodeType($documentAnnot->nodeType); if (isset($documentAnnot->referenceable) && $documentAnnot->referenceable) { - $class->setReferenceable(true); + $metadata->setReferenceable(true); } if ($documentAnnot->repositoryClass) { - $class->setCustomRepositoryClassName($documentAnnot->repositoryClass); + $metadata->setCustomRepositoryClassName($documentAnnot->repositoryClass); } if ($documentAnnot->translator) { - $class->setTranslator($documentAnnot->translator); + $metadata->setTranslator($documentAnnot->translator); } foreach ($reflClass->getProperties() as $property) { @@ -158,39 +101,39 @@ public function loadMetadataForClass($className, ClassMetadata $class) $mapping['fieldName'] = $property->getName(); foreach ($this->reader->getPropertyAnnotations($property) as $fieldAnnot) { - if ($fieldAnnot instanceof \Doctrine\ODM\PHPCR\Mapping\Annotations\Property) { + if ($fieldAnnot instanceof ODM\Property) { $mapping = array_merge($mapping, (array) $fieldAnnot); - $class->mapField($mapping); - } elseif ($fieldAnnot instanceof \Doctrine\ODM\PHPCR\Mapping\Annotations\Id) { + $metadata->mapField($mapping); + } elseif ($fieldAnnot instanceof ODM\Id) { $mapping = array_merge($mapping, (array) $fieldAnnot); - $class->mapId($mapping); - } elseif ($fieldAnnot instanceof \Doctrine\ODM\PHPCR\Mapping\Annotations\Node) { + $metadata->mapId($mapping); + } elseif ($fieldAnnot instanceof ODM\Node) { $mapping = array_merge($mapping, (array) $fieldAnnot); - $class->mapNode($mapping); - } elseif ($fieldAnnot instanceof \Doctrine\ODM\PHPCR\Mapping\Annotations\Nodename) { + $metadata->mapNode($mapping); + } elseif ($fieldAnnot instanceof ODM\Nodename) { $mapping = array_merge($mapping, (array) $fieldAnnot); - $class->mapNodename($mapping); - } elseif ($fieldAnnot instanceof \Doctrine\ODM\PHPCR\Mapping\Annotations\ParentDocument) { + $metadata->mapNodename($mapping); + } elseif ($fieldAnnot instanceof ODM\ParentDocument) { $mapping = array_merge($mapping, (array) $fieldAnnot); - $class->mapParentDocument($mapping); - } elseif ($fieldAnnot instanceof \Doctrine\ODM\PHPCR\Mapping\Annotations\Child) { + $metadata->mapParentDocument($mapping); + } elseif ($fieldAnnot instanceof ODM\Child) { $mapping = array_merge($mapping, (array) $fieldAnnot); - $class->mapChild($mapping); - } elseif ($fieldAnnot instanceof \Doctrine\ODM\PHPCR\Mapping\Annotations\Children) { + $metadata->mapChild($mapping); + } elseif ($fieldAnnot instanceof ODM\Children) { $mapping = array_merge($mapping, (array) $fieldAnnot); - $class->mapChildren($mapping); - } elseif ($fieldAnnot instanceof \Doctrine\ODM\PHPCR\Mapping\Annotations\ReferenceOne) { + $metadata->mapChildren($mapping); + } elseif ($fieldAnnot instanceof ODM\ReferenceOne) { $mapping = array_merge($mapping, (array) $fieldAnnot); - $class->mapManyToOne($mapping); - } elseif ($fieldAnnot instanceof \Doctrine\ODM\PHPCR\Mapping\Annotations\ReferenceMany) { + $metadata->mapManyToOne($mapping); + } elseif ($fieldAnnot instanceof ODM\ReferenceMany) { $mapping = array_merge($mapping, (array) $fieldAnnot); - $class->mapManyToMany($mapping); - } elseif ($fieldAnnot instanceof \Doctrine\ODM\PHPCR\Mapping\Annotations\Referrers) { + $metadata->mapManyToMany($mapping); + } elseif ($fieldAnnot instanceof ODM\Referrers) { $mapping = array_merge($mapping, (array) $fieldAnnot); - $class->mapReferrers($mapping); - } elseif ($fieldAnnot instanceof \Doctrine\ODM\PHPCR\Mapping\Annotations\Locale) { + $metadata->mapReferrers($mapping); + } elseif ($fieldAnnot instanceof ODM\Locale) { $mapping = array_merge($mapping, (array) $fieldAnnot); - $class->mapLocale($mapping); + $metadata->mapLocale($mapping); } if (!isset($mapping['name'])) { @@ -203,106 +146,32 @@ public function loadMetadataForClass($className, ClassMetadata $class) if ($method->isPublic()) { foreach ($this->reader->getMethodAnnotations($method) as $annot) { if ($annot instanceof ODM\PrePersist) { - $class->addLifecycleCallback($method->getName(), \Doctrine\ODM\PHPCR\Event::prePersist); + $metadata->addLifecycleCallback($method->getName(), Event::prePersist); } elseif ($annot instanceof ODM\PostPersist) { - $class->addLifecycleCallback($method->getName(), \Doctrine\ODM\PHPCR\Event::postPersist); + $metadata->addLifecycleCallback($method->getName(), Event::postPersist); } elseif ($annot instanceof ODM\PreUpdate) { - $class->addLifecycleCallback($method->getName(), \Doctrine\ODM\PHPCR\Event::preUpdate); + $metadata->addLifecycleCallback($method->getName(), Event::preUpdate); } elseif ($annot instanceof ODM\PostUpdate) { - $class->addLifecycleCallback($method->getName(), \Doctrine\ODM\PHPCR\Event::postUpdate); + $metadata->addLifecycleCallback($method->getName(), Event::postUpdate); } elseif ($annot instanceof ODM\PreRemove) { - $class->addLifecycleCallback($method->getName(), \Doctrine\ODM\PHPCR\Event::preRemove); + $metadata->addLifecycleCallback($method->getName(), Event::preRemove); } elseif ($annot instanceof ODM\PostRemove) { - $class->addLifecycleCallback($method->getName(), \Doctrine\ODM\PHPCR\Event::postRemove); + $metadata->addLifecycleCallback($method->getName(), Event::postRemove); } elseif ($annot instanceof ODM\PreLoad) { - $class->addLifecycleCallback($method->getName(), \Doctrine\ODM\PHPCR\Event::preLoad); + $metadata->addLifecycleCallback($method->getName(), Event::preLoad); } elseif ($annot instanceof ODM\PostLoad) { - $class->addLifecycleCallback($method->getName(), \Doctrine\ODM\PHPCR\Event::postLoad); + $metadata->addLifecycleCallback($method->getName(), Event::postLoad); } } } } // Check there is a @Locale annotation for translatable documents - if (count($class->translatableFields)) { - if (!isset($class->localeMapping)) { + if (count($metadata->translatableFields)) { + if (!isset($metadata->localeMapping)) { throw new MappingException("You must define a @Locale field for translatable document '$className'"); } } } - /** - * Whether the class with the specified name is transient. Only non-transient - * classes, that is entities and mapped superclasses, should have their metadata loaded. - * A class is non-transient if it is annotated with either @Entity or - * @MappedSuperclass in the class doc block. - * - * @param string $className - * @return boolean - */ - public function isTransient($className) - { - $rc = new \ReflectionClass($className); - - if ($this->reader->getClassAnnotation($rc, 'Doctrine\ODM\PHPCR\Mapping\Annotations\Document')) { - return false; - } - - if ($this->reader->getClassAnnotation($rc, 'Doctrine\ODM\PHPCR\Mapping\Annotations\MappedSuperclass')) { - return false; - } - - return true; - } - - /** - * {@inheritDoc} - */ - public function getAllClassNames() - { - if ($this->classNames !== null) { - return $this->classNames; - } - - if (!$this->paths) { - throw MappingException::pathRequired(); - } - - $classes = array(); - $includedFiles = array(); - - foreach ($this->paths as $path) { - if (!is_dir($path)) { - throw MappingException::fileMappingDriversRequireConfiguredDirectoryPath(); - } - - $iterator = new \RecursiveIteratorIterator( - new \RecursiveDirectoryIterator($path), - \RecursiveIteratorIterator::LEAVES_ONLY - ); - - foreach ($iterator as $file) { - if (($file->getBasename($this->fileExtension)) == $file->getBasename()) { - continue; - } - - $sourceFile = realpath($file->getPathName()); - require_once $sourceFile; - $includedFiles[] = $sourceFile; - } - } - - $declared = get_declared_classes(); - - foreach ($declared as $className) { - $rc = new \ReflectionClass($className); - $sourceFile = $rc->getFileName(); - if (in_array($sourceFile, $includedFiles) && !$this->isTransient($className)) { - $classes[] = $className; - } - } - $this->classNames = $classes; - - return $classes; - } } diff --git a/lib/Doctrine/ODM/PHPCR/Mapping/Driver/BuiltinDocumentsDriver.php b/lib/Doctrine/ODM/PHPCR/Mapping/Driver/BuiltinDocumentsDriver.php index 502b7c87b..90938b4b9 100644 --- a/lib/Doctrine/ODM/PHPCR/Mapping/Driver/BuiltinDocumentsDriver.php +++ b/lib/Doctrine/ODM/PHPCR/Mapping/Driver/BuiltinDocumentsDriver.php @@ -3,7 +3,7 @@ namespace Doctrine\ODM\PHPCR\Mapping\Driver; use Doctrine\Common\Annotations\AnnotationReader; -use Doctrine\ODM\PHPCR\Mapping\ClassMetadata; +use Doctrine\Common\Persistence\Mapping\ClassMetadata; use Doctrine\ODM\PHPCR\Mapping\MappingException; use Doctrine\ODM\PHPCR\Mapping\Driver\AnnotationDriver; diff --git a/lib/Doctrine/ODM/PHPCR/Mapping/Driver/Driver.php b/lib/Doctrine/ODM/PHPCR/Mapping/Driver/Driver.php index a82d8d4f5..1a5ff9fd0 100644 --- a/lib/Doctrine/ODM/PHPCR/Mapping/Driver/Driver.php +++ b/lib/Doctrine/ODM/PHPCR/Mapping/Driver/Driver.php @@ -19,7 +19,7 @@ namespace Doctrine\ODM\PHPCR\Mapping\Driver; -use Doctrine\ODM\PHPCR\Mapping\ClassMetadata; +use Doctrine\Common\Persistence\Mapping\Driver\MappingDriver; /** * Contract for metadata drivers. @@ -30,30 +30,7 @@ * @author Jonathan H. Wage * @author Roman Borschel */ -interface Driver +interface Driver extends MappingDriver { - /** - * Loads the metadata for the specified class into the provided container. - * - * @param string $className - * @param ClassMetadataInfo $metadata - */ - function loadMetadataForClass($className, ClassMetadata $metadata); - /** - * Gets the names of all mapped classes known to this driver. - * - * @return array The names of all mapped classes known to this driver. - */ - function getAllClassNames(); - - /** - * Whether the class with the specified name should have its metadata loaded. - * This is only the case if it is either mapped as an Document or a - * MappedSuperclass. - * - * @param string $className - * @return boolean - */ - function isTransient($className); } diff --git a/lib/Doctrine/ODM/PHPCR/Mapping/Driver/DriverChain.php b/lib/Doctrine/ODM/PHPCR/Mapping/Driver/DriverChain.php index 63600d6c2..4e0a7656e 100644 --- a/lib/Doctrine/ODM/PHPCR/Mapping/Driver/DriverChain.php +++ b/lib/Doctrine/ODM/PHPCR/Mapping/Driver/DriverChain.php @@ -2,7 +2,7 @@ namespace Doctrine\ODM\PHPCR\Mapping\Driver; -use Doctrine\ODM\PHPCR\Mapping\ClassMetadata; +use Doctrine\Common\Persistence\Mapping\ClassMetadata; use Doctrine\ODM\PHPCR\Mapping\MappingException; /** diff --git a/lib/Doctrine/ODM/PHPCR/Mapping/Driver/PHPDriver.php b/lib/Doctrine/ODM/PHPCR/Mapping/Driver/PHPDriver.php index 8362808e8..4ef141ada 100644 --- a/lib/Doctrine/ODM/PHPCR/Mapping/Driver/PHPDriver.php +++ b/lib/Doctrine/ODM/PHPCR/Mapping/Driver/PHPDriver.php @@ -19,7 +19,7 @@ namespace Doctrine\ODM\PHPCR\Mapping\Driver; -use Doctrine\ODM\PHPCR\Mapping\ClassMetadata; +use Doctrine\Common\Persistence\Mapping\ClassMetadata; /** * The PHPDriver invokes a static PHP function on the document class itself passing diff --git a/lib/Doctrine/ODM/PHPCR/Mapping/Driver/XmlDriver.php b/lib/Doctrine/ODM/PHPCR/Mapping/Driver/XmlDriver.php index 0c6487f21..e0f7d919f 100644 --- a/lib/Doctrine/ODM/PHPCR/Mapping/Driver/XmlDriver.php +++ b/lib/Doctrine/ODM/PHPCR/Mapping/Driver/XmlDriver.php @@ -19,7 +19,7 @@ namespace Doctrine\ODM\PHPCR\Mapping\Driver; -use Doctrine\ODM\PHPCR\Mapping\ClassMetadata; +use Doctrine\Common\Persistence\Mapping\ClassMetadata; use Doctrine\ODM\PHPCR\Mapping\MappingException; use SimpleXmlElement; diff --git a/lib/Doctrine/ODM/PHPCR/Mapping/Driver/YamlDriver.php b/lib/Doctrine/ODM/PHPCR/Mapping/Driver/YamlDriver.php index 41bf6a23c..0fa2fed3e 100644 --- a/lib/Doctrine/ODM/PHPCR/Mapping/Driver/YamlDriver.php +++ b/lib/Doctrine/ODM/PHPCR/Mapping/Driver/YamlDriver.php @@ -19,8 +19,8 @@ namespace Doctrine\ODM\PHPCR\Mapping\Driver; -use Doctrine\ODM\PHPCR\Mapping\ClassMetadata, - Doctrine\ODM\PHPCR\Mapping\MappingException; +use Doctrine\Common\Persistence\Mapping\ClassMetadata; +use Doctrine\ODM\PHPCR\Mapping\MappingException; /** * The YamlDriver reads the mapping metadata from yaml schema files. From f4a54434c8a54c1cf43f093a78f9991eb09adec5 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Mon, 26 Dec 2011 02:03:21 +0100 Subject: [PATCH 07/14] Adding support for metadata caching in ClassMetadataFactory and Configuration --- lib/Doctrine/ODM/PHPCR/Configuration.php | 31 +++++++++++++++++-- .../PHPCR/Mapping/ClassMetadataFactory.php | 4 ++- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/lib/Doctrine/ODM/PHPCR/Configuration.php b/lib/Doctrine/ODM/PHPCR/Configuration.php index b8e32fd53..22e0772fe 100644 --- a/lib/Doctrine/ODM/PHPCR/Configuration.php +++ b/lib/Doctrine/ODM/PHPCR/Configuration.php @@ -19,6 +19,7 @@ namespace Doctrine\ODM\PHPCR; +use Doctrine\Common\Cache\Cache; use Doctrine\ODM\PHPCR\Mapping\Driver\Driver; use Doctrine\ODM\PHPCR\Mapping\Driver\BuiltinDocumentsDriver; use Doctrine\ODM\PHPCR\DocumentClassMapperInterface; @@ -44,9 +45,10 @@ class Configuration 'writeDoctrineMetadata' => true, 'validateDoctrineMetadata' => true, 'metadataDriverImpl' => null, + 'metadataCacheImpl' => null, 'documentClassMapper' => null, 'proxyNamespace' => 'MyPHPCRProxyNS', - 'autoGenerateProxyClasses' => true + 'autoGenerateProxyClasses' => true, ); /** @@ -128,7 +130,7 @@ public function setDocumentNamespaces(array $documentNamespaces) } /** - * Sets the cache driver implementation that is used for metadata caching. + * Sets the driver implementation that is used to retrieve mapping metadata. * * @param Driver $driverImpl * @todo Force parameter to be a Closure to ensure lazy evaluation @@ -140,7 +142,7 @@ public function setMetadataDriverImpl(Driver $driverImpl) } /** - * Gets the cache driver implementation that is used for the mapping metadata. + * Gets the driver implementation that is used to retrieve mapping metadata. * * @return Mapping\Driver\Driver */ @@ -149,6 +151,29 @@ public function getMetadataDriverImpl() return $this->attributes['metadataDriverImpl']; } + /** + * Sets the cache driver implementation that is used for metadata caching. + * + * @param Cache $metadataCacheImpl + */ + public function setMetadataCacheImpl(Cache $metadataCacheImpl) + { + $this->attributes['metadataCacheImpl'] = $metadataCacheImpl; + } + + /** + * Gets the cache driver implementation that is used for the mapping metadata. + * + * @return Cache|null + */ + public function getMetadataCacheImpl() + { + if($this->attributes['metadataCacheImpl'] === null) { + $this->setMetadataCacheImpl(new \Doctrine\Common\Cache\ArrayCache()); + } + return $this->attributes['metadataCacheImpl']; + } + /** * Gets the cache driver implementation that is used for metadata caching. * diff --git a/lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadataFactory.php b/lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadataFactory.php index dde01ebe1..972c758bf 100644 --- a/lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadataFactory.php +++ b/lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadataFactory.php @@ -63,7 +63,9 @@ class ClassMetadataFactory extends AbstractClassMetadataFactory public function __construct(DocumentManager $dm) { $this->dm = $dm; - $this->driver = $this->dm->getConfiguration()->getMetadataDriverImpl(); + $conf = $this->dm->getConfiguration(); + $this->setCacheDriver($conf->getMetadataCacheImpl()); + $this->driver = $conf->getMetadataDriverImpl(); } /** From 4328de409eed041a0dafda3371cf5e2c9aa5b9b0 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Mon, 26 Dec 2011 02:31:26 +0100 Subject: [PATCH 08/14] Removing default caching (used during development) --- lib/Doctrine/ODM/PHPCR/Configuration.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/Doctrine/ODM/PHPCR/Configuration.php b/lib/Doctrine/ODM/PHPCR/Configuration.php index 22e0772fe..922628205 100644 --- a/lib/Doctrine/ODM/PHPCR/Configuration.php +++ b/lib/Doctrine/ODM/PHPCR/Configuration.php @@ -168,9 +168,6 @@ public function setMetadataCacheImpl(Cache $metadataCacheImpl) */ public function getMetadataCacheImpl() { - if($this->attributes['metadataCacheImpl'] === null) { - $this->setMetadataCacheImpl(new \Doctrine\Common\Cache\ArrayCache()); - } return $this->attributes['metadataCacheImpl']; } From 2fdfeeadb914c1072841156a5d4f6a7832f5bc8f Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Mon, 26 Dec 2011 02:40:39 +0100 Subject: [PATCH 09/14] Fixing coding conventions --- .../ODM/PHPCR/Mapping/ClassMetadataFactory.php | 11 +++++++---- lib/Doctrine/ODM/PHPCR/Mapping/MappingException.php | 6 ++++-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadataFactory.php b/lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadataFactory.php index 972c758bf..36e6716b8 100644 --- a/lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadataFactory.php +++ b/lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadataFactory.php @@ -62,7 +62,7 @@ class ClassMetadataFactory extends AbstractClassMetadataFactory */ public function __construct(DocumentManager $dm) { - $this->dm = $dm; + $this->dm = $dm; $conf = $this->dm->getConfiguration(); $this->setCacheDriver($conf->getMetadataCacheImpl()); $this->driver = $conf->getMetadataDriverImpl(); @@ -117,7 +117,8 @@ protected function getFqcnFromAlias($namespaceAlias, $simpleClassName) * * @todo unclear usage of rootEntityFound */ - protected function doLoadMetadata($class, $parent, $rootEntityFound) { + protected function doLoadMetadata($class, $parent, $rootEntityFound) + { if ($parent) { $this->getDriver()->loadMetadataForClass($parent->name, $parent); } @@ -127,14 +128,16 @@ protected function doLoadMetadata($class, $parent, $rootEntityFound) { /** * {@inheritdoc} */ - protected function getDriver() { + protected function getDriver() + { return $this->driver; } /** * {@inheritdoc} */ - protected function initialize() { + protected function initialize() + { $this->initialized = true; } diff --git a/lib/Doctrine/ODM/PHPCR/Mapping/MappingException.php b/lib/Doctrine/ODM/PHPCR/Mapping/MappingException.php index ac2c5a524..49bff0772 100644 --- a/lib/Doctrine/ODM/PHPCR/Mapping/MappingException.php +++ b/lib/Doctrine/ODM/PHPCR/Mapping/MappingException.php @@ -49,7 +49,8 @@ public static function reflectionFailure($document, \ReflectionException $previo * @param string $document The document's name * @param string $fieldName The name of the field that was already declared */ - public static function duplicateFieldMapping($document, $fieldName) { + public static function duplicateFieldMapping($document, $fieldName) + { return new self('Property "'.$fieldName.'" in "'.$document.'" was already declared, but it must be declared only once'); } @@ -57,7 +58,8 @@ public static function duplicateFieldMapping($document, $fieldName) { * @param string $document The document's name * @param string $fieldName The name of the field that was already declared */ - public static function missingTypeDefinition($document, $fieldName) { + public static function missingTypeDefinition($document, $fieldName) + { return new self('Property "'.$fieldName.'" in "'.$document.'" must have a type attribute defined'); } From 3d79e8fa27e19c695226d6c2effb3a600725968a Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Mon, 26 Dec 2011 19:06:54 +0100 Subject: [PATCH 10/14] Fixing line endings --- .../PHPCR/Mapping/ClassMetadataFactory.php | 288 ++++---- .../ODM/PHPCR/Mapping/MappingException.php | 180 ++--- lib/Doctrine/ODM/PHPCR/Proxy/ProxyFactory.php | 688 +++++++++--------- 3 files changed, 578 insertions(+), 578 deletions(-) diff --git a/lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadataFactory.php b/lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadataFactory.php index 36e6716b8..2d28cb8c7 100644 --- a/lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadataFactory.php +++ b/lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadataFactory.php @@ -1,144 +1,144 @@ -. - */ - -namespace Doctrine\ODM\PHPCR\Mapping; - -use Doctrine\ODM\PHPCR\DocumentManager; -use Doctrine\ODM\PHPCR\Mapping\ClassMetadata; -use Doctrine\ODM\PHPCR\PHPCRException; -use Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory; - -/** - * The ClassMetadataFactory is used to create ClassMetadata objects that contain all the - * metadata mapping information of a class which describes how a class should be mapped - * to a document database. - - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @link www.doctrine-project.com - * @since 1.0 - * @author Benjamin Eberlei - * @author Lukas Kahwe Smith - */ -class ClassMetadataFactory extends AbstractClassMetadataFactory -{ - - /** - * {@inheritdoc} - */ - protected $cacheSalt = '\$PHPCRODMCLASSMETADATA'; - - /** - * @var DocumentManager - */ - private $dm; - - /** - * The used metadata driver. - * - * @var \Doctrine\ODM\PHPCR\Mapping\Driver\Driver - */ - private $driver; - - /** - * Creates a new factory instance that uses the given DocumentManager instance. - * - * @param $dm The DocumentManager instance - */ - public function __construct(DocumentManager $dm) - { - $this->dm = $dm; - $conf = $this->dm->getConfiguration(); - $this->setCacheDriver($conf->getMetadataCacheImpl()); - $this->driver = $conf->getMetadataDriverImpl(); - } - - /** - * {@inheritdoc} - * - * @throws MappingException - */ - public function getMetadataFor($className) - { - if ($metadata = parent::getMetadataFor($className)) { - return $metadata; - } - throw MappingException::classNotMapped($className); - } - - /** - * {@inheritdoc} - * - * @throws MappingException - */ - function loadMetadata($className) - { - if (class_exists($className)) { - return parent::loadMetadata($className); - } - throw MappingException::classNotFound($className); - } - - - /** - * {@inheritdoc} - */ - protected function newClassMetadataInstance($className) - { - return new ClassMetadata($className); - } - - /** - * {@inheritdoc} - */ - protected function getFqcnFromAlias($namespaceAlias, $simpleClassName) - { - return $this->dm->getConfiguration()->getDocumentNamespace($namespaceAlias) - . '\\' . $simpleClassName; - } - - /** - * {@inheritdoc} - * - * @todo unclear usage of rootEntityFound - */ - protected function doLoadMetadata($class, $parent, $rootEntityFound) - { - if ($parent) { - $this->getDriver()->loadMetadataForClass($parent->name, $parent); - } - $this->getDriver()->loadMetadataForClass($class->name, $class); - } - - /** - * {@inheritdoc} - */ - protected function getDriver() - { - return $this->driver; - } - - /** - * {@inheritdoc} - */ - protected function initialize() - { - $this->initialized = true; - } - -} +. + */ + +namespace Doctrine\ODM\PHPCR\Mapping; + +use Doctrine\ODM\PHPCR\DocumentManager; +use Doctrine\ODM\PHPCR\Mapping\ClassMetadata; +use Doctrine\ODM\PHPCR\PHPCRException; +use Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory; + +/** + * The ClassMetadataFactory is used to create ClassMetadata objects that contain all the + * metadata mapping information of a class which describes how a class should be mapped + * to a document database. + + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @link www.doctrine-project.com + * @since 1.0 + * @author Benjamin Eberlei + * @author Lukas Kahwe Smith + */ +class ClassMetadataFactory extends AbstractClassMetadataFactory +{ + + /** + * {@inheritdoc} + */ + protected $cacheSalt = '\$PHPCRODMCLASSMETADATA'; + + /** + * @var DocumentManager + */ + private $dm; + + /** + * The used metadata driver. + * + * @var \Doctrine\ODM\PHPCR\Mapping\Driver\Driver + */ + private $driver; + + /** + * Creates a new factory instance that uses the given DocumentManager instance. + * + * @param $dm The DocumentManager instance + */ + public function __construct(DocumentManager $dm) + { + $this->dm = $dm; + $conf = $this->dm->getConfiguration(); + $this->setCacheDriver($conf->getMetadataCacheImpl()); + $this->driver = $conf->getMetadataDriverImpl(); + } + + /** + * {@inheritdoc} + * + * @throws MappingException + */ + public function getMetadataFor($className) + { + if ($metadata = parent::getMetadataFor($className)) { + return $metadata; + } + throw MappingException::classNotMapped($className); + } + + /** + * {@inheritdoc} + * + * @throws MappingException + */ + function loadMetadata($className) + { + if (class_exists($className)) { + return parent::loadMetadata($className); + } + throw MappingException::classNotFound($className); + } + + + /** + * {@inheritdoc} + */ + protected function newClassMetadataInstance($className) + { + return new ClassMetadata($className); + } + + /** + * {@inheritdoc} + */ + protected function getFqcnFromAlias($namespaceAlias, $simpleClassName) + { + return $this->dm->getConfiguration()->getDocumentNamespace($namespaceAlias) + . '\\' . $simpleClassName; + } + + /** + * {@inheritdoc} + * + * @todo unclear usage of rootEntityFound + */ + protected function doLoadMetadata($class, $parent, $rootEntityFound) + { + if ($parent) { + $this->getDriver()->loadMetadataForClass($parent->name, $parent); + } + $this->getDriver()->loadMetadataForClass($class->name, $class); + } + + /** + * {@inheritdoc} + */ + protected function getDriver() + { + return $this->driver; + } + + /** + * {@inheritdoc} + */ + protected function initialize() + { + $this->initialized = true; + } + +} diff --git a/lib/Doctrine/ODM/PHPCR/Mapping/MappingException.php b/lib/Doctrine/ODM/PHPCR/Mapping/MappingException.php index 49bff0772..c19e45afe 100644 --- a/lib/Doctrine/ODM/PHPCR/Mapping/MappingException.php +++ b/lib/Doctrine/ODM/PHPCR/Mapping/MappingException.php @@ -1,90 +1,90 @@ -. - */ - -namespace Doctrine\ODM\PHPCR\Mapping; - -/** - * Mapping exception class - * - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @link www.doctrine-project.com - * @since 1.0 - * @author Benjamin Eberlei - * @author Lukas Kahwe Smith - */ -class MappingException extends \Exception -{ - public static function classNotFound($className) - { - return new self('The class: ' . $className . ' could not be found'); - } - - public static function classIsNotAValidDocument($className) - { - return new self('Class '.$className.' is not a valid document or mapped super class.'); - } - - public static function reflectionFailure($document, \ReflectionException $previousException) - { - return new self('An error occurred in ' . $document, 0, $previousException); - } - - /** - * @param string $document The document's name - * @param string $fieldName The name of the field that was already declared - */ - public static function duplicateFieldMapping($document, $fieldName) - { - return new self('Property "'.$fieldName.'" in "'.$document.'" was already declared, but it must be declared only once'); - } - - /** - * @param string $document The document's name - * @param string $fieldName The name of the field that was already declared - */ - public static function missingTypeDefinition($document, $fieldName) - { - return new self('Property "'.$fieldName.'" in "'.$document.'" must have a type attribute defined'); - } - - public static function fileMappingDriversRequireConfiguredDirectoryPath() - { - return new self('File mapping drivers must have a valid directory path, however the given path seems to be incorrect!'); - } - - public static function aliasIsNotSpecified($document) - { - return new self('Document '.$document.' must specify an alias'); - } - - public static function classNotMapped($className) - { - return new self('Class ' . $className . ' is not mapped to a document'); - } - - public static function noTypeSpecified() - { - return new self(); - } - - public static function mappingNotFound($className, $fieldName) - { - return new self("No mapping found for field '$fieldName' in class '$className'."); - } -} +. + */ + +namespace Doctrine\ODM\PHPCR\Mapping; + +/** + * Mapping exception class + * + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @link www.doctrine-project.com + * @since 1.0 + * @author Benjamin Eberlei + * @author Lukas Kahwe Smith + */ +class MappingException extends \Exception +{ + public static function classNotFound($className) + { + return new self('The class: ' . $className . ' could not be found'); + } + + public static function classIsNotAValidDocument($className) + { + return new self('Class '.$className.' is not a valid document or mapped super class.'); + } + + public static function reflectionFailure($document, \ReflectionException $previousException) + { + return new self('An error occurred in ' . $document, 0, $previousException); + } + + /** + * @param string $document The document's name + * @param string $fieldName The name of the field that was already declared + */ + public static function duplicateFieldMapping($document, $fieldName) + { + return new self('Property "'.$fieldName.'" in "'.$document.'" was already declared, but it must be declared only once'); + } + + /** + * @param string $document The document's name + * @param string $fieldName The name of the field that was already declared + */ + public static function missingTypeDefinition($document, $fieldName) + { + return new self('Property "'.$fieldName.'" in "'.$document.'" must have a type attribute defined'); + } + + public static function fileMappingDriversRequireConfiguredDirectoryPath() + { + return new self('File mapping drivers must have a valid directory path, however the given path seems to be incorrect!'); + } + + public static function aliasIsNotSpecified($document) + { + return new self('Document '.$document.' must specify an alias'); + } + + public static function classNotMapped($className) + { + return new self('Class ' . $className . ' is not mapped to a document'); + } + + public static function noTypeSpecified() + { + return new self(); + } + + public static function mappingNotFound($className, $fieldName) + { + return new self("No mapping found for field '$fieldName' in class '$className'."); + } +} diff --git a/lib/Doctrine/ODM/PHPCR/Proxy/ProxyFactory.php b/lib/Doctrine/ODM/PHPCR/Proxy/ProxyFactory.php index cd634ec09..d9a0b6297 100644 --- a/lib/Doctrine/ODM/PHPCR/Proxy/ProxyFactory.php +++ b/lib/Doctrine/ODM/PHPCR/Proxy/ProxyFactory.php @@ -1,344 +1,344 @@ -. - */ - -namespace Doctrine\ODM\PHPCR\Proxy; - -use Doctrine\ODM\PHPCR\DocumentManager, - Doctrine\ODM\PHPCR\Mapping\ClassMetadata; - -/** - * This factory is used to create proxy objects for entities at runtime. - * - * @author Roman Borschel - * @author Giorgio Sironi - * @author Nils Adermann - * @author Johannes Stark - * @author David Buchmann - * - * This whole thing is copy & pasted from ORM - should really be slightly - * refactored to generate - */ -class ProxyFactory -{ - /** The DocumentManager this factory is bound to. */ - private $dm; - /** 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; - - /** - * Initializes a new instance of the ProxyFactory class that is - * connected to the given DocumentManager. - * - * @param DocumentManager $dm The DocumentManager 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. - */ - public function __construct(DocumentManager $dm, $proxyDir, $proxyNs, $autoGenerate = false) - { - if (!$proxyDir) { - throw ProxyException::proxyDirectoryRequired(); - } - if (!$proxyNs) { - throw ProxyException::proxyNamespaceRequired(); - } - $this->dm = $dm; - $this->proxyDir = $proxyDir; - $this->autoGenerate = $autoGenerate; - $this->proxyNamespace = $proxyNs; - } - - /** - * Gets a reference proxy instance for the entity of the given type and identified by - * the given identifier. - * - * @param string $className - * @param mixed $identifier - * @return object - */ - public function getProxy($className, $identifier) - { - $proxyClassName = str_replace('\\', '', $className) . 'ReferenceProxy'; - $fqn = $this->proxyNamespace . '\\' . $proxyClassName; - - if ($this->autoGenerate && !class_exists($fqn, false)) { - $fileName = $this->proxyDir . DIRECTORY_SEPARATOR . $proxyClassName . '.php'; - $this->generateProxyClass($this->dm->getClassMetadata($className), $proxyClassName, $fileName, self::$proxyClassTemplate); - require $fileName; - } - - if (!$this->dm->getMetadataFactory()->hasMetadataFor($fqn)) { - $this->dm->getMetadataFactory()->setMetadataFor($fqn, $this->dm->getClassMetadata($className)); - } - - return new $fqn($this->dm, $identifier); - } - - /** - * Generates proxy classes for all given classes. - * - * @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 DocumentManager 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) { - /* @var $class ClassMetadata */ - if ($class->isMappedSuperclass) { - continue; - } - - $proxyClassName = str_replace('\\', '', $class->name) . 'ReferenceProxy'; - $proxyFileName = $proxyDir . $proxyClassName . '.php'; - $this->generateProxyClass($class, $proxyClassName, $proxyFileName, self::$proxyClassTemplate); - } - } - - /** - * Generates a proxy class file. - * - * @param $class - * @param $originalClassName - * @param $proxyClassName - * @param $file The path of the file to write to. - */ - private function generateProxyClass($class, $proxyClassName, $fileName, $file) - { - $methods = $this->generateMethods($class); - $unsetAttributes = $this->getUnsetAttributes($class); - $sleepImpl = $this->generateSleep($class); - - $placeholders = array( - '', - '', '', - '', - '', '' - ); - - if (substr($class->name, 0, 1) == "\\") { - $className = substr($class->name, 1); - } else { - $className = $class->name; - } - - $replacements = array( - $this->proxyNamespace, - $proxyClassName, $className, - $unsetAttributes, - $methods, $sleepImpl - ); - - $file = str_replace($placeholders, $replacements, $file); - - file_put_contents($fileName, $file, LOCK_EX); - } - - /** - * Get the attributes of the document class - * - * @param ClassMetadata $class - * @return string The unset command for all document attributes - */ - private function getUnsetAttributes(ClassMetadata $class) - { - $attributes = ""; - foreach ($class->fieldMappings as $field) { - $attributes .= '$this->'.$field["fieldName"]; - $attributes .= ", "; - } - - foreach ($class->associationsMappings as $field) { - $attributes .= '$this->'.$field["fieldName"]; - $attributes .= ", "; - } - - foreach ($class->referrersMappings as $field) { - $attributes .= '$this->'.$field["fieldName"]; - $attributes .= ", "; - } - - foreach ($class->childrenMappings as $field) { - $attributes .= '$this->'.$field["fieldName"]; - $attributes .= ", "; - } - - foreach ($class->childMappings as $field) { - $attributes .= '$this->'.$field["fieldName"]; - $attributes .= ", "; - } - - $attributes .= '$this->id'; - - return "unset(".$attributes.");"; - } - - /** - * Generates the methods of a proxy class. - * - * @param ClassMetadata $class - * @return string The code of the generated methods. - */ - private function generateMethods(ClassMetadata $class) - { - $methods = ''; - - foreach ($class->reflClass->getMethods() as $method) { - /* @var $method ReflectionMethod */ - if ($method->isConstructor() || strtolower($method->getName()) == "__sleep") { - continue; - } - - if ($method->isPublic() && !$method->isFinal() && !$method->isStatic()) { - $methods .= PHP_EOL . ' public function '; - if ($method->returnsReference()) { - $methods .= '&'; - } - $methods .= $method->getName() . '('; - $firstParam = true; - $parameterString = $argumentString = ''; - - foreach ($method->getParameters() as $param) { - if ($firstParam) { - $firstParam = false; - } else { - $parameterString .= ', '; - $argumentString .= ', '; - } - - // We need to pick the type hint class too - if (($paramClass = $param->getClass()) !== null) { - $parameterString .= '\\' . $paramClass->getName() . ' '; - } elseif ($param->isArray()) { - $parameterString .= 'array '; - } - - if ($param->isPassedByReference()) { - $parameterString .= '&'; - } - - $parameterString .= '$' . $param->getName(); - $argumentString .= '$' . $param->getName(); - - if ($param->isDefaultValueAvailable()) { - $parameterString .= ' = ' . var_export($param->getDefaultValue(), true); - } - } - - $methods .= $parameterString . ')'; - $methods .= PHP_EOL . ' {' . PHP_EOL; - $methods .= ' $this->__load();' . PHP_EOL; - $methods .= ' return parent::' . $method->getName() . '(' . $argumentString . ');'; - $methods .= PHP_EOL . ' }' . PHP_EOL; - } - } - - return $methods; - } - - /** - * Generates the code for the __sleep method for a proxy class. - * - * @param $class - * @return string - */ - private function generateSleep(ClassMetadata $class) - { - $sleepImpl = ''; - - if ($class->reflClass->hasMethod('__sleep')) { - $sleepImpl .= "return array_merge(array('__isInitialized__'), parent::__sleep());"; - } else { - $sleepImpl .= "return array('__isInitialized__', "; - - $properties = array(); - foreach ($class->fieldMappings as $name => $prop) { - $properties[] = "'$name'"; - } - - $sleepImpl .= implode(',', $properties) . ');'; - } - - return $sleepImpl; - } - - /** Proxy class code template */ - private static $proxyClassTemplate = <<<'PHP' -; - -/** - * THIS CLASS WAS GENERATED BY THE DOCTRINE ORM. DO NOT EDIT THIS FILE. - */ -class extends \ implements \Doctrine\ODM\PHPCR\Proxy\Proxy -{ - private $__doctrineDocumentManager__; - private $__doctrineIdentifier__; - public $__isInitialized__ = false; - public function __construct($documentManager, $identifier) - { - - $this->__doctrineDocumentManager__ = $documentManager; - } - - public function __load() - { - if (!$this->__isInitialized__ && $this->__doctrineDocumentManager__) { - $this->__isInitialized__ = true; - $this->__doctrineDocumentManager__->getRepository(get_class($this))->refreshDocumentForProxy($this); - unset($this->__doctrineDocumentManager__); - } - } - - - - public function __sleep() - { - - } - - public function __set($name, $value) - { - $this->__load(); - $this->$name = $value; - } - - public function &__get($name) - { - $this->__load(); - return $this->$name; - } - - public function __isInitialized() - { - return $this->__isInitialized__; - } - -} -PHP; -} - +. + */ + +namespace Doctrine\ODM\PHPCR\Proxy; + +use Doctrine\ODM\PHPCR\DocumentManager, + Doctrine\ODM\PHPCR\Mapping\ClassMetadata; + +/** + * This factory is used to create proxy objects for entities at runtime. + * + * @author Roman Borschel + * @author Giorgio Sironi + * @author Nils Adermann + * @author Johannes Stark + * @author David Buchmann + * + * This whole thing is copy & pasted from ORM - should really be slightly + * refactored to generate + */ +class ProxyFactory +{ + /** The DocumentManager this factory is bound to. */ + private $dm; + /** 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; + + /** + * Initializes a new instance of the ProxyFactory class that is + * connected to the given DocumentManager. + * + * @param DocumentManager $dm The DocumentManager 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. + */ + public function __construct(DocumentManager $dm, $proxyDir, $proxyNs, $autoGenerate = false) + { + if (!$proxyDir) { + throw ProxyException::proxyDirectoryRequired(); + } + if (!$proxyNs) { + throw ProxyException::proxyNamespaceRequired(); + } + $this->dm = $dm; + $this->proxyDir = $proxyDir; + $this->autoGenerate = $autoGenerate; + $this->proxyNamespace = $proxyNs; + } + + /** + * Gets a reference proxy instance for the entity of the given type and identified by + * the given identifier. + * + * @param string $className + * @param mixed $identifier + * @return object + */ + public function getProxy($className, $identifier) + { + $proxyClassName = str_replace('\\', '', $className) . 'ReferenceProxy'; + $fqn = $this->proxyNamespace . '\\' . $proxyClassName; + + if ($this->autoGenerate && !class_exists($fqn, false)) { + $fileName = $this->proxyDir . DIRECTORY_SEPARATOR . $proxyClassName . '.php'; + $this->generateProxyClass($this->dm->getClassMetadata($className), $proxyClassName, $fileName, self::$proxyClassTemplate); + require $fileName; + } + + if (!$this->dm->getMetadataFactory()->hasMetadataFor($fqn)) { + $this->dm->getMetadataFactory()->setMetadataFor($fqn, $this->dm->getClassMetadata($className)); + } + + return new $fqn($this->dm, $identifier); + } + + /** + * Generates proxy classes for all given classes. + * + * @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 DocumentManager 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) { + /* @var $class ClassMetadata */ + if ($class->isMappedSuperclass) { + continue; + } + + $proxyClassName = str_replace('\\', '', $class->name) . 'ReferenceProxy'; + $proxyFileName = $proxyDir . $proxyClassName . '.php'; + $this->generateProxyClass($class, $proxyClassName, $proxyFileName, self::$proxyClassTemplate); + } + } + + /** + * Generates a proxy class file. + * + * @param $class + * @param $originalClassName + * @param $proxyClassName + * @param $file The path of the file to write to. + */ + private function generateProxyClass($class, $proxyClassName, $fileName, $file) + { + $methods = $this->generateMethods($class); + $unsetAttributes = $this->getUnsetAttributes($class); + $sleepImpl = $this->generateSleep($class); + + $placeholders = array( + '', + '', '', + '', + '', '' + ); + + if (substr($class->name, 0, 1) == "\\") { + $className = substr($class->name, 1); + } else { + $className = $class->name; + } + + $replacements = array( + $this->proxyNamespace, + $proxyClassName, $className, + $unsetAttributes, + $methods, $sleepImpl + ); + + $file = str_replace($placeholders, $replacements, $file); + + file_put_contents($fileName, $file, LOCK_EX); + } + + /** + * Get the attributes of the document class + * + * @param ClassMetadata $class + * @return string The unset command for all document attributes + */ + private function getUnsetAttributes(ClassMetadata $class) + { + $attributes = ""; + foreach ($class->fieldMappings as $field) { + $attributes .= '$this->'.$field["fieldName"]; + $attributes .= ", "; + } + + foreach ($class->associationsMappings as $field) { + $attributes .= '$this->'.$field["fieldName"]; + $attributes .= ", "; + } + + foreach ($class->referrersMappings as $field) { + $attributes .= '$this->'.$field["fieldName"]; + $attributes .= ", "; + } + + foreach ($class->childrenMappings as $field) { + $attributes .= '$this->'.$field["fieldName"]; + $attributes .= ", "; + } + + foreach ($class->childMappings as $field) { + $attributes .= '$this->'.$field["fieldName"]; + $attributes .= ", "; + } + + $attributes .= '$this->id'; + + return "unset(".$attributes.");"; + } + + /** + * Generates the methods of a proxy class. + * + * @param ClassMetadata $class + * @return string The code of the generated methods. + */ + private function generateMethods(ClassMetadata $class) + { + $methods = ''; + + foreach ($class->reflClass->getMethods() as $method) { + /* @var $method ReflectionMethod */ + if ($method->isConstructor() || strtolower($method->getName()) == "__sleep") { + continue; + } + + if ($method->isPublic() && !$method->isFinal() && !$method->isStatic()) { + $methods .= PHP_EOL . ' public function '; + if ($method->returnsReference()) { + $methods .= '&'; + } + $methods .= $method->getName() . '('; + $firstParam = true; + $parameterString = $argumentString = ''; + + foreach ($method->getParameters() as $param) { + if ($firstParam) { + $firstParam = false; + } else { + $parameterString .= ', '; + $argumentString .= ', '; + } + + // We need to pick the type hint class too + if (($paramClass = $param->getClass()) !== null) { + $parameterString .= '\\' . $paramClass->getName() . ' '; + } elseif ($param->isArray()) { + $parameterString .= 'array '; + } + + if ($param->isPassedByReference()) { + $parameterString .= '&'; + } + + $parameterString .= '$' . $param->getName(); + $argumentString .= '$' . $param->getName(); + + if ($param->isDefaultValueAvailable()) { + $parameterString .= ' = ' . var_export($param->getDefaultValue(), true); + } + } + + $methods .= $parameterString . ')'; + $methods .= PHP_EOL . ' {' . PHP_EOL; + $methods .= ' $this->__load();' . PHP_EOL; + $methods .= ' return parent::' . $method->getName() . '(' . $argumentString . ');'; + $methods .= PHP_EOL . ' }' . PHP_EOL; + } + } + + return $methods; + } + + /** + * Generates the code for the __sleep method for a proxy class. + * + * @param $class + * @return string + */ + private function generateSleep(ClassMetadata $class) + { + $sleepImpl = ''; + + if ($class->reflClass->hasMethod('__sleep')) { + $sleepImpl .= "return array_merge(array('__isInitialized__'), parent::__sleep());"; + } else { + $sleepImpl .= "return array('__isInitialized__', "; + + $properties = array(); + foreach ($class->fieldMappings as $name => $prop) { + $properties[] = "'$name'"; + } + + $sleepImpl .= implode(',', $properties) . ');'; + } + + return $sleepImpl; + } + + /** Proxy class code template */ + private static $proxyClassTemplate = <<<'PHP' +; + +/** + * THIS CLASS WAS GENERATED BY THE DOCTRINE ORM. DO NOT EDIT THIS FILE. + */ +class extends \ implements \Doctrine\ODM\PHPCR\Proxy\Proxy +{ + private $__doctrineDocumentManager__; + private $__doctrineIdentifier__; + public $__isInitialized__ = false; + public function __construct($documentManager, $identifier) + { + + $this->__doctrineDocumentManager__ = $documentManager; + } + + public function __load() + { + if (!$this->__isInitialized__ && $this->__doctrineDocumentManager__) { + $this->__isInitialized__ = true; + $this->__doctrineDocumentManager__->getRepository(get_class($this))->refreshDocumentForProxy($this); + unset($this->__doctrineDocumentManager__); + } + } + + + + public function __sleep() + { + + } + + public function __set($name, $value) + { + $this->__load(); + $this->$name = $value; + } + + public function &__get($name) + { + $this->__load(); + return $this->$name; + } + + public function __isInitialized() + { + return $this->__isInitialized__; + } + +} +PHP; +} + From faea546338e30d1eb760bec5967b604237ab03cf Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Tue, 27 Dec 2011 01:22:24 +0100 Subject: [PATCH 11/14] Removing newlines at the end of modified files --- lib/Doctrine/ODM/PHPCR/Configuration.php | 2 +- lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadataFactory.php | 2 +- lib/Doctrine/ODM/PHPCR/Mapping/Driver/AnnotationDriver.php | 2 +- .../ODM/PHPCR/Mapping/Driver/BuiltinDocumentsDriver.php | 2 +- lib/Doctrine/ODM/PHPCR/Mapping/Driver/Driver.php | 2 +- lib/Doctrine/ODM/PHPCR/Mapping/Driver/DriverChain.php | 2 +- lib/Doctrine/ODM/PHPCR/Mapping/Driver/XmlDriver.php | 2 +- lib/Doctrine/ODM/PHPCR/Mapping/Driver/YamlDriver.php | 2 +- lib/Doctrine/ODM/PHPCR/Mapping/MappingException.php | 2 +- lib/Doctrine/ODM/PHPCR/Proxy/ProxyFactory.php | 3 +-- 10 files changed, 10 insertions(+), 11 deletions(-) diff --git a/lib/Doctrine/ODM/PHPCR/Configuration.php b/lib/Doctrine/ODM/PHPCR/Configuration.php index 922628205..9502ecea2 100644 --- a/lib/Doctrine/ODM/PHPCR/Configuration.php +++ b/lib/Doctrine/ODM/PHPCR/Configuration.php @@ -259,4 +259,4 @@ public function getAutoGenerateProxyClasses() { return $this->attributes['autoGenerateProxyClasses']; } -} +} \ No newline at end of file diff --git a/lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadataFactory.php b/lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadataFactory.php index 2d28cb8c7..f408487d2 100644 --- a/lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadataFactory.php +++ b/lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadataFactory.php @@ -141,4 +141,4 @@ protected function initialize() $this->initialized = true; } -} +} \ No newline at end of file diff --git a/lib/Doctrine/ODM/PHPCR/Mapping/Driver/AnnotationDriver.php b/lib/Doctrine/ODM/PHPCR/Mapping/Driver/AnnotationDriver.php index 109feae53..dc05ccd37 100644 --- a/lib/Doctrine/ODM/PHPCR/Mapping/Driver/AnnotationDriver.php +++ b/lib/Doctrine/ODM/PHPCR/Mapping/Driver/AnnotationDriver.php @@ -174,4 +174,4 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) } } -} +} \ No newline at end of file diff --git a/lib/Doctrine/ODM/PHPCR/Mapping/Driver/BuiltinDocumentsDriver.php b/lib/Doctrine/ODM/PHPCR/Mapping/Driver/BuiltinDocumentsDriver.php index 90938b4b9..f7fa48f0d 100644 --- a/lib/Doctrine/ODM/PHPCR/Mapping/Driver/BuiltinDocumentsDriver.php +++ b/lib/Doctrine/ODM/PHPCR/Mapping/Driver/BuiltinDocumentsDriver.php @@ -90,4 +90,4 @@ public function isTransient($className) return $this->wrappedDriver->isTransient($className); } -} +} \ No newline at end of file diff --git a/lib/Doctrine/ODM/PHPCR/Mapping/Driver/Driver.php b/lib/Doctrine/ODM/PHPCR/Mapping/Driver/Driver.php index 1a5ff9fd0..28684e885 100644 --- a/lib/Doctrine/ODM/PHPCR/Mapping/Driver/Driver.php +++ b/lib/Doctrine/ODM/PHPCR/Mapping/Driver/Driver.php @@ -33,4 +33,4 @@ interface Driver extends MappingDriver { -} +} \ No newline at end of file diff --git a/lib/Doctrine/ODM/PHPCR/Mapping/Driver/DriverChain.php b/lib/Doctrine/ODM/PHPCR/Mapping/Driver/DriverChain.php index 4e0a7656e..503def4c8 100644 --- a/lib/Doctrine/ODM/PHPCR/Mapping/Driver/DriverChain.php +++ b/lib/Doctrine/ODM/PHPCR/Mapping/Driver/DriverChain.php @@ -93,4 +93,4 @@ public function isTransient($className) // class isTransient, i.e. not an document or mapped superclass return true; } -} +} \ No newline at end of file diff --git a/lib/Doctrine/ODM/PHPCR/Mapping/Driver/XmlDriver.php b/lib/Doctrine/ODM/PHPCR/Mapping/Driver/XmlDriver.php index e0f7d919f..b15b5c313 100644 --- a/lib/Doctrine/ODM/PHPCR/Mapping/Driver/XmlDriver.php +++ b/lib/Doctrine/ODM/PHPCR/Mapping/Driver/XmlDriver.php @@ -204,4 +204,4 @@ protected function loadMappingFile($file) return $result; } -} +} \ No newline at end of file diff --git a/lib/Doctrine/ODM/PHPCR/Mapping/Driver/YamlDriver.php b/lib/Doctrine/ODM/PHPCR/Mapping/Driver/YamlDriver.php index 0fa2fed3e..b6e2a57ac 100644 --- a/lib/Doctrine/ODM/PHPCR/Mapping/Driver/YamlDriver.php +++ b/lib/Doctrine/ODM/PHPCR/Mapping/Driver/YamlDriver.php @@ -194,4 +194,4 @@ protected function loadMappingFile($file) { return \Symfony\Component\Yaml\Yaml::parse($file); } -} +} \ No newline at end of file diff --git a/lib/Doctrine/ODM/PHPCR/Mapping/MappingException.php b/lib/Doctrine/ODM/PHPCR/Mapping/MappingException.php index c19e45afe..151028a51 100644 --- a/lib/Doctrine/ODM/PHPCR/Mapping/MappingException.php +++ b/lib/Doctrine/ODM/PHPCR/Mapping/MappingException.php @@ -87,4 +87,4 @@ public static function mappingNotFound($className, $fieldName) { return new self("No mapping found for field '$fieldName' in class '$className'."); } -} +} \ No newline at end of file diff --git a/lib/Doctrine/ODM/PHPCR/Proxy/ProxyFactory.php b/lib/Doctrine/ODM/PHPCR/Proxy/ProxyFactory.php index d9a0b6297..5bfaf47ba 100644 --- a/lib/Doctrine/ODM/PHPCR/Proxy/ProxyFactory.php +++ b/lib/Doctrine/ODM/PHPCR/Proxy/ProxyFactory.php @@ -340,5 +340,4 @@ public function __isInitialized() } PHP; -} - +} \ No newline at end of file From ba7628e224d7ebec035415688daa799ca0de06b0 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Tue, 27 Dec 2011 01:28:58 +0100 Subject: [PATCH 12/14] Fixing coding conventions --- lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadataFactory.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadataFactory.php b/lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadataFactory.php index f408487d2..e97728d85 100644 --- a/lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadataFactory.php +++ b/lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadataFactory.php @@ -75,7 +75,8 @@ public function __construct(DocumentManager $dm) */ public function getMetadataFor($className) { - if ($metadata = parent::getMetadataFor($className)) { + $metadata = parent::getMetadataFor($className); + if ($metadata) { return $metadata; } throw MappingException::classNotMapped($className); From c998ced9f3dec412f5ee733a735fdd3fca937a1e Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 28 Dec 2011 09:51:11 +0100 Subject: [PATCH 13/14] Removing unused inheritance checks (will need them again when PHPCR-ODM implements support for inheritance) --- lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadataFactory.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadataFactory.php b/lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadataFactory.php index e97728d85..b0e60a5ce 100644 --- a/lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadataFactory.php +++ b/lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadataFactory.php @@ -115,14 +115,9 @@ protected function getFqcnFromAlias($namespaceAlias, $simpleClassName) /** * {@inheritdoc} - * - * @todo unclear usage of rootEntityFound */ protected function doLoadMetadata($class, $parent, $rootEntityFound) { - if ($parent) { - $this->getDriver()->loadMetadataForClass($parent->name, $parent); - } $this->getDriver()->loadMetadataForClass($class->name, $class); } From 8b5024b70e41a7d5a0ede3cf9bae0ef92fee8050 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 28 Dec 2011 09:55:27 +0100 Subject: [PATCH 14/14] Using ClassMetadata contract instead of public property --- lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadataFactory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadataFactory.php b/lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadataFactory.php index b0e60a5ce..297e268ed 100644 --- a/lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadataFactory.php +++ b/lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadataFactory.php @@ -118,7 +118,7 @@ protected function getFqcnFromAlias($namespaceAlias, $simpleClassName) */ protected function doLoadMetadata($class, $parent, $rootEntityFound) { - $this->getDriver()->loadMetadataForClass($class->name, $class); + $this->getDriver()->loadMetadataForClass($class->getName(), $class); } /**