123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684 |
- <?php
-
-
- namespace Doctrine\ORM;
-
- use Doctrine\Common\Cache\Cache,
- Doctrine\Common\Cache\ArrayCache,
- Doctrine\Common\Annotations\AnnotationRegistry,
- Doctrine\Common\Annotations\AnnotationReader,
- Doctrine\Common\Persistence\Mapping\Driver\MappingDriver,
- Doctrine\ORM\Mapping\Driver\AnnotationDriver,
- Doctrine\ORM\Mapping\QuoteStrategy,
- Doctrine\ORM\Mapping\DefaultQuoteStrategy,
- Doctrine\ORM\Mapping\NamingStrategy,
- Doctrine\ORM\Mapping\DefaultNamingStrategy,
- Doctrine\Common\Annotations\SimpleAnnotationReader,
- Doctrine\Common\Annotations\CachedReader;
-
-
- class Configuration extends \Doctrine\DBAL\Configuration
- {
-
-
- public function setProxyDir($dir)
- {
- $this->_attributes['proxyDir'] = $dir;
- }
-
-
-
- public function getProxyDir()
- {
- return isset($this->_attributes['proxyDir'])
- ? $this->_attributes['proxyDir']
- : null;
- }
-
-
-
- public function getAutoGenerateProxyClasses()
- {
- return isset($this->_attributes['autoGenerateProxyClasses'])
- ? $this->_attributes['autoGenerateProxyClasses']
- : true;
- }
-
-
-
- public function setAutoGenerateProxyClasses($bool)
- {
- $this->_attributes['autoGenerateProxyClasses'] = $bool;
- }
-
-
-
- public function getProxyNamespace()
- {
- return isset($this->_attributes['proxyNamespace'])
- ? $this->_attributes['proxyNamespace']
- : null;
- }
-
-
-
- public function setProxyNamespace($ns)
- {
- $this->_attributes['proxyNamespace'] = $ns;
- }
-
-
-
- public function setMetadataDriverImpl(MappingDriver $driverImpl)
- {
- $this->_attributes['metadataDriverImpl'] = $driverImpl;
- }
-
-
-
- public function newDefaultAnnotationDriver($paths = array(), $useSimpleAnnotationReader = true)
- {
- AnnotationRegistry::registerFile(__DIR__ . '/Mapping/Driver/DoctrineAnnotations.php');
-
- if ($useSimpleAnnotationReader) {
-
- $reader = new SimpleAnnotationReader();
- $reader->addNamespace('Doctrine\ORM\Mapping');
- $cachedReader = new CachedReader($reader, new ArrayCache());
-
- return new AnnotationDriver($cachedReader, (array) $paths);
- }
-
- return new AnnotationDriver(
- new CachedReader(new AnnotationReader(), new ArrayCache()),
- (array) $paths
- );
- }
-
-
-
- public function addEntityNamespace($alias, $namespace)
- {
- $this->_attributes['entityNamespaces'][$alias] = $namespace;
- }
-
-
-
- public function getEntityNamespace($entityNamespaceAlias)
- {
- if ( ! isset($this->_attributes['entityNamespaces'][$entityNamespaceAlias])) {
- throw ORMException::unknownEntityNamespace($entityNamespaceAlias);
- }
-
- return trim($this->_attributes['entityNamespaces'][$entityNamespaceAlias], '\\');
- }
-
-
-
- public function setEntityNamespaces(array $entityNamespaces)
- {
- $this->_attributes['entityNamespaces'] = $entityNamespaces;
- }
-
-
-
- public function getEntityNamespaces()
- {
- return $this->_attributes['entityNamespaces'];
- }
-
-
-
- public function getMetadataDriverImpl()
- {
- return isset($this->_attributes['metadataDriverImpl'])
- ? $this->_attributes['metadataDriverImpl']
- : null;
- }
-
-
-
- public function getQueryCacheImpl()
- {
- return isset($this->_attributes['queryCacheImpl'])
- ? $this->_attributes['queryCacheImpl']
- : null;
- }
-
-
-
- public function setQueryCacheImpl(Cache $cacheImpl)
- {
- $this->_attributes['queryCacheImpl'] = $cacheImpl;
- }
-
-
-
- public function getHydrationCacheImpl()
- {
- return isset($this->_attributes['hydrationCacheImpl'])
- ? $this->_attributes['hydrationCacheImpl']
- : null;
- }
-
-
-
- public function setHydrationCacheImpl(Cache $cacheImpl)
- {
- $this->_attributes['hydrationCacheImpl'] = $cacheImpl;
- }
-
-
-
- public function getMetadataCacheImpl()
- {
- return isset($this->_attributes['metadataCacheImpl'])
- ? $this->_attributes['metadataCacheImpl']
- : null;
- }
-
-
-
- public function setMetadataCacheImpl(Cache $cacheImpl)
- {
- $this->_attributes['metadataCacheImpl'] = $cacheImpl;
- }
-
-
-
- public function addNamedQuery($name, $dql)
- {
- $this->_attributes['namedQueries'][$name] = $dql;
- }
-
-
-
- public function getNamedQuery($name)
- {
- if ( ! isset($this->_attributes['namedQueries'][$name])) {
- throw ORMException::namedQueryNotFound($name);
- }
-
- return $this->_attributes['namedQueries'][$name];
- }
-
-
-
- public function addNamedNativeQuery($name, $sql, Query\ResultSetMapping $rsm)
- {
- $this->_attributes['namedNativeQueries'][$name] = array($sql, $rsm);
- }
-
-
-
- public function getNamedNativeQuery($name)
- {
- if ( ! isset($this->_attributes['namedNativeQueries'][$name])) {
- throw ORMException::namedNativeQueryNotFound($name);
- }
-
- return $this->_attributes['namedNativeQueries'][$name];
- }
-
-
-
- public function ensureProductionSettings()
- {
- if ( ! $this->getQueryCacheImpl()) {
- throw ORMException::queryCacheNotConfigured();
- }
-
- if ( ! $this->getMetadataCacheImpl()) {
- throw ORMException::metadataCacheNotConfigured();
- }
-
- if ($this->getAutoGenerateProxyClasses()) {
- throw ORMException::proxyClassesAlwaysRegenerating();
- }
- }
-
-
-
- public function addCustomStringFunction($name, $className)
- {
- if (Query\Parser::isInternalFunction($name)) {
- throw ORMException::overwriteInternalDQLFunctionNotAllowed($name);
- }
-
- $this->_attributes['customStringFunctions'][strtolower($name)] = $className;
- }
-
-
-
- public function getCustomStringFunction($name)
- {
- $name = strtolower($name);
-
- return isset($this->_attributes['customStringFunctions'][$name])
- ? $this->_attributes['customStringFunctions'][$name]
- : null;
- }
-
-
-
- public function setCustomStringFunctions(array $functions)
- {
- foreach ($functions as $name => $className) {
- $this->addCustomStringFunction($name, $className);
- }
- }
-
-
-
- public function addCustomNumericFunction($name, $className)
- {
- if (Query\Parser::isInternalFunction($name)) {
- throw ORMException::overwriteInternalDQLFunctionNotAllowed($name);
- }
-
- $this->_attributes['customNumericFunctions'][strtolower($name)] = $className;
- }
-
-
-
- public function getCustomNumericFunction($name)
- {
- $name = strtolower($name);
-
- return isset($this->_attributes['customNumericFunctions'][$name])
- ? $this->_attributes['customNumericFunctions'][$name]
- : null;
- }
-
-
-
- public function setCustomNumericFunctions(array $functions)
- {
- foreach ($functions as $name => $className) {
- $this->addCustomNumericFunction($name, $className);
- }
- }
-
-
-
- public function addCustomDatetimeFunction($name, $className)
- {
- if (Query\Parser::isInternalFunction($name)) {
- throw ORMException::overwriteInternalDQLFunctionNotAllowed($name);
- }
-
- $this->_attributes['customDatetimeFunctions'][strtolower($name)] = $className;
- }
-
-
-
- public function getCustomDatetimeFunction($name)
- {
- $name = strtolower($name);
-
- return isset($this->_attributes['customDatetimeFunctions'][$name])
- ? $this->_attributes['customDatetimeFunctions'][$name]
- : null;
- }
-
-
-
- public function setCustomDatetimeFunctions(array $functions)
- {
- foreach ($functions as $name => $className) {
- $this->addCustomDatetimeFunction($name, $className);
- }
- }
-
-
-
- public function setCustomHydrationModes($modes)
- {
- $this->_attributes['customHydrationModes'] = array();
-
- foreach ($modes as $modeName => $hydrator) {
- $this->addCustomHydrationMode($modeName, $hydrator);
- }
- }
-
-
-
- public function getCustomHydrationMode($modeName)
- {
- return isset($this->_attributes['customHydrationModes'][$modeName])
- ? $this->_attributes['customHydrationModes'][$modeName]
- : null;
- }
-
-
-
- public function addCustomHydrationMode($modeName, $hydrator)
- {
- $this->_attributes['customHydrationModes'][$modeName] = $hydrator;
- }
-
-
-
- public function setClassMetadataFactoryName($cmfName)
- {
- $this->_attributes['classMetadataFactoryName'] = $cmfName;
- }
-
-
-
- public function getClassMetadataFactoryName()
- {
- if ( ! isset($this->_attributes['classMetadataFactoryName'])) {
- $this->_attributes['classMetadataFactoryName'] = 'Doctrine\ORM\Mapping\ClassMetadataFactory';
- }
-
- return $this->_attributes['classMetadataFactoryName'];
- }
-
-
-
- public function addFilter($name, $className)
- {
- $this->_attributes['filters'][$name] = $className;
- }
-
-
-
- public function getFilterClassName($name)
- {
- return isset($this->_attributes['filters'][$name])
- ? $this->_attributes['filters'][$name]
- : null;
- }
-
-
-
- public function setDefaultRepositoryClassName($className)
- {
- $reflectionClass = new \ReflectionClass($className);
-
- if ( ! $reflectionClass->implementsInterface('Doctrine\Common\Persistence\ObjectRepository')) {
- throw ORMException::invalidEntityRepository($className);
- }
-
- $this->_attributes['defaultRepositoryClassName'] = $className;
- }
-
-
-
- public function getDefaultRepositoryClassName()
- {
- return isset($this->_attributes['defaultRepositoryClassName'])
- ? $this->_attributes['defaultRepositoryClassName']
- : 'Doctrine\ORM\EntityRepository';
- }
-
-
-
- public function setNamingStrategy(NamingStrategy $namingStrategy)
- {
- $this->_attributes['namingStrategy'] = $namingStrategy;
- }
-
-
-
- public function getNamingStrategy()
- {
- if ( ! isset($this->_attributes['namingStrategy'])) {
- $this->_attributes['namingStrategy'] = new DefaultNamingStrategy();
- }
-
- return $this->_attributes['namingStrategy'];
- }
-
-
-
- public function setQuoteStrategy(QuoteStrategy $quoteStrategy)
- {
- $this->_attributes['quoteStrategy'] = $quoteStrategy;
- }
-
-
-
- public function getQuoteStrategy()
- {
- if ( ! isset($this->_attributes['quoteStrategy'])) {
- $this->_attributes['quoteStrategy'] = new DefaultQuoteStrategy();
- }
-
- return $this->_attributes['quoteStrategy'];
- }
- }
|