1
0
mirror of synced 2025-01-19 06:51:40 +03:00

Merge branch 'NewAnnotations'

This commit is contained in:
Benjamin Eberlei 2011-05-25 00:36:10 +02:00
commit ca6ea65b1f
2 changed files with 37 additions and 6 deletions

View File

@ -121,7 +121,10 @@ class Configuration extends \Doctrine\DBAL\Configuration
*/ */
public function newDefaultAnnotationDriver($paths = array()) public function newDefaultAnnotationDriver($paths = array())
{ {
if (version_compare(\Doctrine\Common\Version::VERSION, '2.1.0-BETA3-DEV', '>=')) { if (version_compare(\Doctrine\Common\Version::VERSION, '3.0.0-DEV', '>=')) {
$reader = new \Doctrine\Common\Annotations\AnnotationReader();
$reader = new \Doctrine\Common\Annotations\CachedReader($reader, new ArrayCache());
} else if (version_compare(\Doctrine\Common\Version::VERSION, '2.1.0-BETA3-DEV', '>=')) {
$reader = new \Doctrine\Common\Annotations\AnnotationReader(); $reader = new \Doctrine\Common\Annotations\AnnotationReader();
$reader->setDefaultAnnotationNamespace('Doctrine\ORM\Mapping\\'); $reader->setDefaultAnnotationNamespace('Doctrine\ORM\Mapping\\');
$reader->setIgnoreNotImportedAnnotations(true); $reader->setIgnoreNotImportedAnnotations(true);

View File

@ -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']);
} }