1
0
mirror of synced 2024-12-13 22:56:04 +03:00

[AnnotationDriver] compatibility with Doctrine Common 3.x

This commit is contained in:
Johannes Schmitt 2011-05-22 22:10:13 +02:00 committed by Benjamin Eberlei
parent 6d724ad9ff
commit a0d79b03e7

View File

@ -62,13 +62,13 @@ class AnnotationDriver implements Driver
* @param array * @param array
*/ */
protected $_classNames; protected $_classNames;
/** /**
* Initializes a new AnnotationDriver that uses the given AnnotationReader for reading * Initializes a new AnnotationDriver that uses the given AnnotationReader for reading
* docblock annotations. * docblock annotations.
* *
* @param AnnotationReader $reader The AnnotationReader to use, duck-typed. * @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) public function __construct($reader, $paths = null)
{ {
@ -77,7 +77,7 @@ class AnnotationDriver implements Driver
$this->addPaths((array) $paths); $this->addPaths((array) $paths);
} }
} }
/** /**
* Append lookup paths to metadata driver. * Append lookup paths to metadata driver.
* *
@ -128,6 +128,13 @@ class AnnotationDriver implements Driver
$classAnnotations = $this->_reader->getClassAnnotations($class); $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 // Evaluate Entity annotation
if (isset($classAnnotations['Doctrine\ORM\Mapping\Entity'])) { if (isset($classAnnotations['Doctrine\ORM\Mapping\Entity'])) {
$entityAnnot = $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) { if ($method->isPublic() && $method->getDeclaringClass()->getName() == $class->name) {
$annotations = $this->_reader->getMethodAnnotations($method); $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'])) { if (isset($annotations['Doctrine\ORM\Mapping\PrePersist'])) {
$metadata->addLifecycleCallback($method->getName(), \Doctrine\ORM\Events::prePersist); $metadata->addLifecycleCallback($method->getName(), \Doctrine\ORM\Events::prePersist);
} }
@ -442,6 +456,20 @@ class AnnotationDriver implements Driver
{ {
$classAnnotations = $this->_reader->getClassAnnotations(new \ReflectionClass($className)); $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']) && return ! isset($classAnnotations['Doctrine\ORM\Mapping\Entity']) &&
! isset($classAnnotations['Doctrine\ORM\Mapping\MappedSuperclass']); ! isset($classAnnotations['Doctrine\ORM\Mapping\MappedSuperclass']);
} }
@ -500,7 +528,7 @@ class AnnotationDriver implements Driver
/** /**
* Factory method for the Annotation Driver * Factory method for the Annotation Driver
* *
* @param array|string $paths * @param array|string $paths
* @param AnnotationReader $reader * @param AnnotationReader $reader
* @return AnnotationDriver * @return AnnotationDriver