Skip to content

Commit

Permalink
Moved AnnotationRegistry::registerFile() call to Configuration#newDef…
Browse files Browse the repository at this point in the history
…aultAnnotationDriver() and documented the migration in UPGRADE_TO_2_1
  • Loading branch information
beberlei committed Jul 3, 2011
1 parent 73f908f commit 6b54cce
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
2 changes: 2 additions & 0 deletions UPGRADE_TO_2_1
Expand Up @@ -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
Expand Down
21 changes: 15 additions & 6 deletions lib/Doctrine/ORM/Configuration.php
Expand Up @@ -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.
Expand Down Expand Up @@ -122,21 +125,27 @@ 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);
$reader = new \Doctrine\Common\Annotations\CachedReader(
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);
}

/**
Expand Down
1 change: 0 additions & 1 deletion lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php
Expand Up @@ -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);
}
Expand Down

0 comments on commit 6b54cce

Please sign in to comment.