Updating to reflect latest Doctrine Common changes
Also, changing logic so that the SimpleAnnotationReader is no more the default one. An additional parameter for the method will allow using it. The CS fixes that were additionally implemented (along with other minor changes that do not affect BC compatibility are caused by a CS sniff via IDE.
This commit is contained in:
parent
5adc8bec58
commit
86dbddd596
@ -28,7 +28,9 @@ use Doctrine\Common\Cache\Cache,
|
||||
Doctrine\ORM\Mapping\QuoteStrategy,
|
||||
Doctrine\ORM\Mapping\DefaultQuoteStrategy,
|
||||
Doctrine\ORM\Mapping\NamingStrategy,
|
||||
Doctrine\ORM\Mapping\DefaultNamingStrategy;
|
||||
Doctrine\ORM\Mapping\DefaultNamingStrategy,
|
||||
Doctrine\Common\Annotations\SimpleAnnotationReader,
|
||||
Doctrine\Common\Annotations\CachedReader;
|
||||
|
||||
/**
|
||||
* Configuration container for all configuration options of Doctrine.
|
||||
@ -124,45 +126,29 @@ class Configuration extends \Doctrine\DBAL\Configuration
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new default annotation driver with a correctly configured annotation reader.
|
||||
* Add a new default annotation driver with a correctly configured annotation reader. If $useDefaultNamespace is
|
||||
* to true, the notation `@Entity` will work, otherwise, the notation `@ORM\Entity` will be supported.
|
||||
*
|
||||
* @param array $paths
|
||||
* @return Mapping\Driver\AnnotationDriver
|
||||
* @param bool $useDefaultNamespace
|
||||
* @return AnnotationDriver
|
||||
*/
|
||||
public function newDefaultAnnotationDriver($paths = array())
|
||||
public function newDefaultAnnotationDriver($paths = array(), $useDefaultNamespace = false)
|
||||
{
|
||||
switch (true) {
|
||||
case (version_compare(\Doctrine\Common\Version::VERSION, '2.2.0-DEV', '>=')):
|
||||
// Register the ORM Annotations in the AnnotationRegistry
|
||||
AnnotationRegistry::registerFile(__DIR__ . '/Mapping/Driver/DoctrineAnnotations.php');
|
||||
|
||||
$reader = new \Doctrine\Common\Annotations\SimpleAnnotationReader();
|
||||
if ($useDefaultNamespace) {
|
||||
// Register the ORM Annotations in the AnnotationRegistry
|
||||
$reader = new SimpleAnnotationReader();
|
||||
$reader->addNamespace('Doctrine\ORM\Mapping');
|
||||
|
||||
$reader = new \Doctrine\Common\Annotations\CachedReader($reader, new ArrayCache());
|
||||
break;
|
||||
|
||||
case (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()
|
||||
);
|
||||
break;
|
||||
|
||||
default:
|
||||
$reader = new AnnotationReader();
|
||||
$reader->setDefaultAnnotationNamespace('Doctrine\ORM\Mapping\\');
|
||||
break;
|
||||
$cachedReader = new CachedReader($reader, new ArrayCache());
|
||||
return new AnnotationDriver($cachedReader, (array) $paths);
|
||||
}
|
||||
|
||||
return new AnnotationDriver($reader, (array) $paths);
|
||||
return new AnnotationDriver(
|
||||
new CachedReader(new AnnotationReader(), new ArrayCache()),
|
||||
(array) $paths
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -180,8 +166,8 @@ class Configuration extends \Doctrine\DBAL\Configuration
|
||||
* Resolves a registered namespace alias to the full namespace.
|
||||
*
|
||||
* @param string $entityNamespaceAlias
|
||||
* @throws ORMException
|
||||
* @return string
|
||||
* @throws MappingException
|
||||
*/
|
||||
public function getEntityNamespace($entityNamespaceAlias)
|
||||
{
|
||||
@ -195,8 +181,7 @@ class Configuration extends \Doctrine\DBAL\Configuration
|
||||
/**
|
||||
* Set the entity alias map
|
||||
*
|
||||
* @param array $entityAliasMap
|
||||
* @return void
|
||||
* @param array $entityNamespaces
|
||||
*/
|
||||
public function setEntityNamespaces(array $entityNamespaces)
|
||||
{
|
||||
@ -307,6 +292,7 @@ class Configuration extends \Doctrine\DBAL\Configuration
|
||||
* Gets a previously registered named DQL query.
|
||||
*
|
||||
* @param string $name The name of the query.
|
||||
* @throws ORMException
|
||||
* @return string The DQL query.
|
||||
*/
|
||||
public function getNamedQuery($name)
|
||||
@ -323,7 +309,7 @@ class Configuration extends \Doctrine\DBAL\Configuration
|
||||
*
|
||||
* @param string $name The name of the query.
|
||||
* @param string $sql The native SQL query string.
|
||||
* @param ResultSetMapping $rsm The ResultSetMapping used for the results of the SQL query.
|
||||
* @param Query\ResultSetMapping $rsm The ResultSetMapping used for the results of the SQL query.
|
||||
*/
|
||||
public function addNamedNativeQuery($name, $sql, Query\ResultSetMapping $rsm)
|
||||
{
|
||||
@ -334,6 +320,7 @@ class Configuration extends \Doctrine\DBAL\Configuration
|
||||
* Gets the components of a previously registered named native query.
|
||||
*
|
||||
* @param string $name The name of the query.
|
||||
* @throws ORMException
|
||||
* @return array A tuple with the first element being the SQL string and the second
|
||||
* element being the ResultSetMapping.
|
||||
*/
|
||||
@ -377,6 +364,7 @@ class Configuration extends \Doctrine\DBAL\Configuration
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $className
|
||||
* @throws ORMException
|
||||
*/
|
||||
public function addCustomStringFunction($name, $className)
|
||||
{
|
||||
@ -428,6 +416,7 @@ class Configuration extends \Doctrine\DBAL\Configuration
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $className
|
||||
* @throws ORMException
|
||||
*/
|
||||
public function addCustomNumericFunction($name, $className)
|
||||
{
|
||||
@ -479,6 +468,7 @@ class Configuration extends \Doctrine\DBAL\Configuration
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $className
|
||||
* @throws ORMException
|
||||
*/
|
||||
public function addCustomDatetimeFunction($name, $className)
|
||||
{
|
||||
@ -548,7 +538,7 @@ class Configuration extends \Doctrine\DBAL\Configuration
|
||||
/**
|
||||
* Set a class metadata factory.
|
||||
*
|
||||
* @param string $cmf
|
||||
* @param string $cmfName
|
||||
*/
|
||||
public function setClassMetadataFactoryName($cmfName)
|
||||
{
|
||||
|
@ -32,7 +32,17 @@ class ORMException extends Exception
|
||||
public static function missingMappingDriverImpl()
|
||||
{
|
||||
return new self("It's a requirement to specify a Metadata Driver and pass it ".
|
||||
"to Doctrine\ORM\Configuration::setMetadataDriverImpl().");
|
||||
"to Doctrine\\ORM\\Configuration::setMetadataDriverImpl().");
|
||||
}
|
||||
|
||||
public static function namedQueryNotFound($queryName)
|
||||
{
|
||||
return new self('Could not find a named query by the name "' . $queryName . '"');
|
||||
}
|
||||
|
||||
public static function namedNativeQueryNotFound($nativeQueryName)
|
||||
{
|
||||
return new self('Could not find a named native query by the name "' . $nativeQueryName . '"');
|
||||
}
|
||||
|
||||
public static function entityMissingForeignAssignedId($entity, $relatedEntity)
|
||||
@ -54,6 +64,7 @@ class ORMException extends Exception
|
||||
"you need to adjust the metadata mapping accordingly."
|
||||
);
|
||||
}
|
||||
|
||||
public static function unrecognizedField($field)
|
||||
{
|
||||
return new self("Unrecognized field: $field");
|
||||
@ -110,7 +121,7 @@ class ORMException extends Exception
|
||||
}
|
||||
|
||||
public static function invalidResultCacheDriver() {
|
||||
return new self("Invalid result cache driver; it must implement \Doctrine\Common\Cache\Cache.");
|
||||
return new self("Invalid result cache driver; it must implement Doctrine\\Common\\Cache\\Cache.");
|
||||
}
|
||||
|
||||
public static function notSupported() {
|
||||
@ -142,7 +153,7 @@ class ORMException extends Exception
|
||||
public static function invalidEntityRepository($className)
|
||||
{
|
||||
return new self("Invalid repository class '".$className."'. ".
|
||||
"it must be a Doctrine\ORM\EntityRepository.");
|
||||
"it must be a Doctrine\\ORM\\EntityRepository.");
|
||||
}
|
||||
|
||||
public static function missingIdentifierField($className, $fieldName)
|
||||
|
@ -78,7 +78,7 @@ class EntityManagerMock extends \Doctrine\ORM\EntityManager
|
||||
$config = new \Doctrine\ORM\Configuration();
|
||||
$config->setProxyDir(__DIR__ . '/../Proxies');
|
||||
$config->setProxyNamespace('Doctrine\Tests\Proxies');
|
||||
$config->setMetadataDriverImpl($config->newDefaultAnnotationDriver());
|
||||
$config->setMetadataDriverImpl($config->newDefaultAnnotationDriver(array(), true));
|
||||
}
|
||||
if (is_null($eventManager)) {
|
||||
$eventManager = new \Doctrine\Common\EventManager();
|
||||
|
@ -95,7 +95,7 @@ class LockAgentWorker
|
||||
$config->setProxyNamespace('MyProject\Proxies');
|
||||
$config->setAutoGenerateProxyClasses(true);
|
||||
|
||||
$annotDriver = $config->newDefaultAnnotationDriver(array(__DIR__ . '/../../../Models/'));
|
||||
$annotDriver = $config->newDefaultAnnotationDriver(array(__DIR__ . '/../../../Models/'), true);
|
||||
$config->setMetadataDriverImpl($annotDriver);
|
||||
|
||||
$cache = new \Doctrine\Common\Cache\ArrayCache();
|
||||
|
@ -342,7 +342,7 @@ abstract class OrmFunctionalTestCase extends OrmTestCase
|
||||
$config->setProxyDir(__DIR__ . '/Proxies');
|
||||
$config->setProxyNamespace('Doctrine\Tests\Proxies');
|
||||
|
||||
$config->setMetadataDriverImpl($config->newDefaultAnnotationDriver());
|
||||
$config->setMetadataDriverImpl($config->newDefaultAnnotationDriver(array(), true));
|
||||
|
||||
$conn = static::$_sharedConn;
|
||||
$conn->getConfiguration()->setSQLLogger($this->_sqlLoggerStack);
|
||||
|
@ -76,7 +76,7 @@ abstract class OrmTestCase extends DoctrineTestCase
|
||||
$config = new \Doctrine\ORM\Configuration();
|
||||
|
||||
$config->setMetadataCacheImpl($metadataCache);
|
||||
$config->setMetadataDriverImpl($config->newDefaultAnnotationDriver());
|
||||
$config->setMetadataDriverImpl($config->newDefaultAnnotationDriver(array(), true));
|
||||
$config->setQueryCacheImpl(self::getSharedQueryCacheImpl());
|
||||
$config->setProxyDir(__DIR__ . '/Proxies');
|
||||
$config->setProxyNamespace('Doctrine\Tests\Proxies');
|
||||
|
Loading…
x
Reference in New Issue
Block a user