diff --git a/UPGRADE_TO_2_1 b/UPGRADE_TO_2_1 index 69dee07dc54..8b289ecd4d5 100644 --- a/UPGRADE_TO_2_1 +++ b/UPGRADE_TO_2_1 @@ -9,6 +9,8 @@ The EntityRepository now has an interface Doctrine\Common\Persistence\ObjectRepo The annotation reader was heavily refactored between 2.0 and 2.1-RC1. In theory the operation of the new reader should be backwards compatible, but it has to be setup differently to work that way: + \Doctrine\Common\Annotations\AnnotationRegistry::registerFile('/doctrine-src/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php'); + $reader = new \Doctrine\Common\Annotations\AnnotationReader(); $reader->setDefaultAnnotationNamespace('Doctrine\ORM\Mapping\\'); // new code necessary starting here diff --git a/lib/Doctrine/ORM/Configuration.php b/lib/Doctrine/ORM/Configuration.php index 4ea7809b3c3..a7219da8bb4 100644 --- a/lib/Doctrine/ORM/Configuration.php +++ b/lib/Doctrine/ORM/Configuration.php @@ -20,8 +20,11 @@ namespace Doctrine\ORM; use Doctrine\Common\Cache\Cache, + Doctrine\Common\Cache\ArrayCache, + Doctrine\Common\Annotations\AnnotationRegistry, + Doctrine\Common\Annotations\AnnotationReader, Doctrine\ORM\Mapping\Driver\Driver, - Doctrine\Common\Cache\ArrayCache; + Doctrine\ORM\Mapping\Driver\AnnotationDriver; /** * Configuration container for all configuration options of Doctrine. @@ -122,10 +125,16 @@ public function setMetadataDriverImpl(Driver $driverImpl) public function newDefaultAnnotationDriver($paths = array()) { if (version_compare(\Doctrine\Common\Version::VERSION, '3.0.0-DEV', '>=')) { - $reader = new \Doctrine\Common\Annotations\AnnotationReader(); + // Register the ORM Annotations in the AnnotationRegistry + AnnotationRegistry::registerFile(__DIR__ . '/Mapping/Driver/DoctrineAnnotations.php'); + + $reader = new 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(); + } else if (version_compare(\Doctrine\Common\Version::VERSION, '2.1.0-DEV', '>=')) { + // Register the ORM Annotations in the AnnotationRegistry + AnnotationRegistry::registerFile(__DIR__ . '/Mapping/Driver/DoctrineAnnotations.php'); + + $reader = new AnnotationReader(); $reader->setDefaultAnnotationNamespace('Doctrine\ORM\Mapping\\'); $reader->setIgnoreNotImportedAnnotations(true); $reader->setEnableParsePhpImports(false); @@ -133,10 +142,10 @@ public function newDefaultAnnotationDriver($paths = array()) new \Doctrine\Common\Annotations\IndexedReader($reader), new ArrayCache() ); } else { - $reader = new \Doctrine\Common\Annotations\AnnotationReader(); + $reader = new AnnotationReader(); $reader->setDefaultAnnotationNamespace('Doctrine\ORM\Mapping\\'); } - return new \Doctrine\ORM\Mapping\Driver\AnnotationDriver($reader, (array)$paths); + return new AnnotationDriver($reader, (array)$paths); } /** diff --git a/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php b/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php index cb30e1cbf37..4de9520d1bd 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php @@ -72,7 +72,6 @@ class AnnotationDriver implements Driver public function __construct($reader, $paths = null) { $this->_reader = $reader; - AnnotationRegistry::registerFile(__DIR__ . '/DoctrineAnnotations.php'); if ($paths) { $this->addPaths((array) $paths); }