diff --git a/lib/Doctrine/ORM/Configuration.php b/lib/Doctrine/ORM/Configuration.php index 7a3f7fdec..b0e1f0fd0 100644 --- a/lib/Doctrine/ORM/Configuration.php +++ b/lib/Doctrine/ORM/Configuration.php @@ -58,8 +58,9 @@ class Configuration extends \Doctrine\DBAL\Configuration */ public function getProxyDir() { - return isset($this->_attributes['proxyDir']) ? - $this->_attributes['proxyDir'] : null; + return isset($this->_attributes['proxyDir']) + ? $this->_attributes['proxyDir'] + : null; } /** @@ -70,8 +71,9 @@ class Configuration extends \Doctrine\DBAL\Configuration */ public function getAutoGenerateProxyClasses() { - return isset($this->_attributes['autoGenerateProxyClasses']) ? - $this->_attributes['autoGenerateProxyClasses'] : true; + return isset($this->_attributes['autoGenerateProxyClasses']) + ? $this->_attributes['autoGenerateProxyClasses'] + : true; } /** @@ -92,8 +94,9 @@ class Configuration extends \Doctrine\DBAL\Configuration */ public function getProxyNamespace() { - return isset($this->_attributes['proxyNamespace']) ? - $this->_attributes['proxyNamespace'] : null; + return isset($this->_attributes['proxyNamespace']) + ? $this->_attributes['proxyNamespace'] + : null; } /** @@ -126,29 +129,38 @@ class Configuration extends \Doctrine\DBAL\Configuration */ public function newDefaultAnnotationDriver($paths = array()) { - if (version_compare(\Doctrine\Common\Version::VERSION, '2.2.0-DEV', '>=')) { - // Register the ORM Annotations in the AnnotationRegistry - AnnotationRegistry::registerFile(__DIR__ . '/Mapping/Driver/DoctrineAnnotations.php'); + 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(); - $reader->addNamespace('Doctrine\ORM\Mapping'); - $reader = new \Doctrine\Common\Annotations\CachedReader($reader, new ArrayCache()); - } 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 \Doctrine\Common\Annotations\SimpleAnnotationReader(); + $reader->addNamespace('Doctrine\ORM\Mapping'); - $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 AnnotationReader(); - $reader->setDefaultAnnotationNamespace('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; } - return new AnnotationDriver($reader, (array)$paths); + + return new AnnotationDriver($reader, (array) $paths); } /** @@ -207,8 +219,9 @@ class Configuration extends \Doctrine\DBAL\Configuration */ public function getMetadataDriverImpl() { - return isset($this->_attributes['metadataDriverImpl']) ? - $this->_attributes['metadataDriverImpl'] : null; + return isset($this->_attributes['metadataDriverImpl']) + ? $this->_attributes['metadataDriverImpl'] + : null; } /** @@ -218,8 +231,9 @@ class Configuration extends \Doctrine\DBAL\Configuration */ public function getQueryCacheImpl() { - return isset($this->_attributes['queryCacheImpl']) ? - $this->_attributes['queryCacheImpl'] : null; + return isset($this->_attributes['queryCacheImpl']) + ? $this->_attributes['queryCacheImpl'] + : null; } /** @@ -239,8 +253,9 @@ class Configuration extends \Doctrine\DBAL\Configuration */ public function getMetadataCacheImpl() { - return isset($this->_attributes['metadataCacheImpl']) ? - $this->_attributes['metadataCacheImpl'] : null; + return isset($this->_attributes['metadataCacheImpl']) + ? $this->_attributes['metadataCacheImpl'] + : null; } /** @@ -275,6 +290,7 @@ class Configuration extends \Doctrine\DBAL\Configuration if ( ! isset($this->_attributes['namedQueries'][$name])) { throw ORMException::namedQueryNotFound($name); } + return $this->_attributes['namedQueries'][$name]; } @@ -302,6 +318,7 @@ class Configuration extends \Doctrine\DBAL\Configuration if ( ! isset($this->_attributes['namedNativeQueries'][$name])) { throw ORMException::namedNativeQueryNotFound($name); } + return $this->_attributes['namedNativeQueries'][$name]; } @@ -314,12 +331,14 @@ class Configuration extends \Doctrine\DBAL\Configuration */ public function ensureProductionSettings() { - if ( !$this->getQueryCacheImpl()) { + if ( ! $this->getQueryCacheImpl()) { throw ORMException::queryCacheNotConfigured(); } - if ( !$this->getMetadataCacheImpl()) { + + if ( ! $this->getMetadataCacheImpl()) { throw ORMException::metadataCacheNotConfigured(); } + if ($this->getAutoGenerateProxyClasses()) { throw ORMException::proxyClassesAlwaysRegenerating(); } @@ -349,8 +368,10 @@ class Configuration extends \Doctrine\DBAL\Configuration public function getCustomStringFunction($name) { $name = strtolower($name); - return isset($this->_attributes['customStringFunctions'][$name]) ? - $this->_attributes['customStringFunctions'][$name] : null; + + return isset($this->_attributes['customStringFunctions'][$name]) + ? $this->_attributes['customStringFunctions'][$name] + : null; } /** @@ -392,8 +413,10 @@ class Configuration extends \Doctrine\DBAL\Configuration public function getCustomNumericFunction($name) { $name = strtolower($name); - return isset($this->_attributes['customNumericFunctions'][$name]) ? - $this->_attributes['customNumericFunctions'][$name] : null; + + return isset($this->_attributes['customNumericFunctions'][$name]) + ? $this->_attributes['customNumericFunctions'][$name] + : null; } /** @@ -435,8 +458,10 @@ class Configuration extends \Doctrine\DBAL\Configuration public function getCustomDatetimeFunction($name) { $name = strtolower($name); - return isset($this->_attributes['customDatetimeFunctions'][$name]) ? - $this->_attributes['customDatetimeFunctions'][$name] : null; + + return isset($this->_attributes['customDatetimeFunctions'][$name]) + ? $this->_attributes['customDatetimeFunctions'][$name] + : null; } /** @@ -462,8 +487,9 @@ class Configuration extends \Doctrine\DBAL\Configuration */ public function getCustomHydrationMode($modeName) { - return isset($this->_attributes['customHydrationModes'][$modeName]) ? - $this->_attributes['customHydrationModes'][$modeName] : null; + return isset($this->_attributes['customHydrationModes'][$modeName]) + ? $this->_attributes['customHydrationModes'][$modeName] + : null; } /** @@ -492,9 +518,10 @@ class Configuration extends \Doctrine\DBAL\Configuration */ public function getClassMetadataFactoryName() { - if (!isset($this->_attributes['classMetadataFactoryName'])) { + if ( ! isset($this->_attributes['classMetadataFactoryName'])) { $this->_attributes['classMetadataFactoryName'] = 'Doctrine\ORM\Mapping\ClassMetadataFactory'; } + return $this->_attributes['classMetadataFactoryName']; } @@ -519,8 +546,9 @@ class Configuration extends \Doctrine\DBAL\Configuration */ public function getFilterClassName($name) { - return isset($this->_attributes['filters'][$name]) ? - $this->_attributes['filters'][$name] : null; + return isset($this->_attributes['filters'][$name]) + ? $this->_attributes['filters'][$name] + : null; } /** @@ -532,10 +560,12 @@ class Configuration extends \Doctrine\DBAL\Configuration */ public function setDefaultRepositoryClassName($className) { - if ($className != "Doctrine\ORM\EntityRepository" && - !is_subclass_of($className, 'Doctrine\ORM\EntityRepository')){ + $entityRepositoryClassName = 'Doctrine\ORM\EntityRepository'; + + if ($className !== $entityRepositoryClassName && ! is_subclass_of($className, $entityRepositoryClassName)) { throw ORMException::invalidEntityRepository($className); } + $this->_attributes['defaultRepositoryClassName'] = $className; } @@ -547,8 +577,9 @@ class Configuration extends \Doctrine\DBAL\Configuration */ public function getDefaultRepositoryClassName() { - return isset($this->_attributes['defaultRepositoryClassName']) ? - $this->_attributes['defaultRepositoryClassName'] : 'Doctrine\ORM\EntityRepository'; + return isset($this->_attributes['defaultRepositoryClassName']) + ? $this->_attributes['defaultRepositoryClassName'] + : 'Doctrine\ORM\EntityRepository'; } /** @@ -570,9 +601,10 @@ class Configuration extends \Doctrine\DBAL\Configuration */ public function getNamingStrategy() { - if (!isset($this->_attributes['namingStrategy'])) { + if ( ! isset($this->_attributes['namingStrategy'])) { $this->_attributes['namingStrategy'] = new DefaultNamingStrategy(); } + return $this->_attributes['namingStrategy']; } }