From a0d79b03e7c7070ab00df2c9ca6fe9b98439de64 Mon Sep 17 00:00:00 2001 From: Johannes Schmitt Date: Sun, 22 May 2011 22:10:13 +0200 Subject: [PATCH] [AnnotationDriver] compatibility with Doctrine Common 3.x --- .../ORM/Mapping/Driver/AnnotationDriver.php | 38 ++++++++++++++++--- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php b/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php index 22e6d4d7e..cbf06fe7b 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php @@ -62,13 +62,13 @@ class AnnotationDriver implements Driver * @param array */ protected $_classNames; - + /** * Initializes a new AnnotationDriver that uses the given AnnotationReader for reading * docblock annotations. - * + * * @param AnnotationReader $reader The AnnotationReader to use, duck-typed. - * @param string|array $paths One or multiple paths where mapping classes can be found. + * @param string|array $paths One or multiple paths where mapping classes can be found. */ public function __construct($reader, $paths = null) { @@ -77,7 +77,7 @@ class AnnotationDriver implements Driver $this->addPaths((array) $paths); } } - + /** * Append lookup paths to metadata driver. * @@ -128,6 +128,13 @@ class AnnotationDriver implements Driver $classAnnotations = $this->_reader->getClassAnnotations($class); + // Compatibility with Doctrine Common 3.x + if ($classAnnotations && is_int(key($classAnnotations))) { + foreach ($classAnnotations as $annot) { + $classAnnotations[get_class($annot)] = $annot; + } + } + // Evaluate Entity annotation if (isset($classAnnotations['Doctrine\ORM\Mapping\Entity'])) { $entityAnnot = $classAnnotations['Doctrine\ORM\Mapping\Entity']; @@ -397,6 +404,13 @@ class AnnotationDriver implements Driver if ($method->isPublic() && $method->getDeclaringClass()->getName() == $class->name) { $annotations = $this->_reader->getMethodAnnotations($method); + // Compatibility with Doctrine Common 3.x + if ($annotations && is_int(key($annotations))) { + foreach ($annotations as $annot) { + $annotations[get_class($annot)] = $annot; + } + } + if (isset($annotations['Doctrine\ORM\Mapping\PrePersist'])) { $metadata->addLifecycleCallback($method->getName(), \Doctrine\ORM\Events::prePersist); } @@ -442,6 +456,20 @@ class AnnotationDriver implements Driver { $classAnnotations = $this->_reader->getClassAnnotations(new \ReflectionClass($className)); + // Compatibility with Doctrine Common 3.x + if ($classAnnotations && is_int(key($classAnnotations))) { + foreach ($classAnnotations as $annot) { + if ($annot instanceof \Doctrine\ORM\Mapping\Entity) { + return false; + } + if ($annot instanceof \Doctrine\ORM\Mapping\MappedSuperclass) { + return false; + } + } + + return true; + } + return ! isset($classAnnotations['Doctrine\ORM\Mapping\Entity']) && ! isset($classAnnotations['Doctrine\ORM\Mapping\MappedSuperclass']); } @@ -500,7 +528,7 @@ class AnnotationDriver implements Driver /** * Factory method for the Annotation Driver - * + * * @param array|string $paths * @param AnnotationReader $reader * @return AnnotationDriver