From 6b54cceed71368be7a8a2e6a1b50d9dfc775f0fa Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Sun, 3 Jul 2011 12:21:04 +0200 Subject: [PATCH] Moved AnnotationRegistry::registerFile() call to Configuration#newDefaultAnnotationDriver() and documented the migration in UPGRADE_TO_2_1 --- UPGRADE_TO_2_1 | 2 ++ lib/Doctrine/ORM/Configuration.php | 21 +++++++++++++------ .../ORM/Mapping/Driver/AnnotationDriver.php | 1 - 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/UPGRADE_TO_2_1 b/UPGRADE_TO_2_1 index 69dee07dc..8b289ecd4 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 4ea7809b3..a7219da8b 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 @@ class Configuration extends \Doctrine\DBAL\Configuration 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 @@ class Configuration extends \Doctrine\DBAL\Configuration 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 cb30e1cbf..4de9520d1 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); }