vendor/doctrine/orm/lib/Doctrine/ORM/Configuration.php line 683

Open in your IDE?
  1. <?php
  2. /*
  3.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  4.  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  5.  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  6.  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  7.  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  8.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  9.  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  10.  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  11.  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  12.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  13.  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  14.  *
  15.  * This software consists of voluntary contributions made by many individuals
  16.  * and is licensed under the MIT license. For more information, see
  17.  * <http://www.doctrine-project.org>.
  18.  */
  19. namespace Doctrine\ORM;
  20. use Doctrine\Common\Annotations\AnnotationReader;
  21. use Doctrine\Common\Annotations\AnnotationRegistry;
  22. use Doctrine\Common\Annotations\CachedReader;
  23. use Doctrine\Common\Annotations\SimpleAnnotationReader;
  24. use Doctrine\Common\Cache\ArrayCache;
  25. use Doctrine\Common\Cache\Cache as CacheDriver;
  26. use Doctrine\Common\Persistence\Mapping\Driver\MappingDriver;
  27. use Doctrine\Common\Persistence\ObjectRepository;
  28. use Doctrine\Common\Proxy\AbstractProxyFactory;
  29. use Doctrine\ORM\Cache\CacheConfiguration;
  30. use Doctrine\ORM\Mapping\ClassMetadataFactory;
  31. use Doctrine\ORM\Mapping\DefaultEntityListenerResolver;
  32. use Doctrine\ORM\Mapping\DefaultNamingStrategy;
  33. use Doctrine\ORM\Mapping\DefaultQuoteStrategy;
  34. use Doctrine\ORM\Mapping\Driver\AnnotationDriver;
  35. use Doctrine\ORM\Mapping\EntityListenerResolver;
  36. use Doctrine\ORM\Mapping\NamingStrategy;
  37. use Doctrine\ORM\Mapping\QuoteStrategy;
  38. use Doctrine\ORM\Repository\DefaultRepositoryFactory;
  39. use Doctrine\ORM\Repository\RepositoryFactory;
  40. /**
  41.  * Configuration container for all configuration options of Doctrine.
  42.  * It combines all configuration options from DBAL & ORM.
  43.  *
  44.  * Internal note: When adding a new configuration option just write a getter/setter pair.
  45.  *
  46.  * @since 2.0
  47.  * @author  Benjamin Eberlei <kontakt@beberlei.de>
  48.  * @author  Guilherme Blanco <guilhermeblanco@hotmail.com>
  49.  * @author  Jonathan Wage <jonwage@gmail.com>
  50.  * @author  Roman Borschel <roman@code-factory.org>
  51.  */
  52. class Configuration extends \Doctrine\DBAL\Configuration
  53. {
  54.     /**
  55.      * Sets the directory where Doctrine generates any necessary proxy class files.
  56.      *
  57.      * @param string $dir
  58.      *
  59.      * @return void
  60.      */
  61.     public function setProxyDir($dir)
  62.     {
  63.         $this->_attributes['proxyDir'] = $dir;
  64.     }
  65.     /**
  66.      * Gets the directory where Doctrine generates any necessary proxy class files.
  67.      *
  68.      * @return string|null
  69.      *
  70.      * @deprecated 2.7 We're switch to `ocramius/proxy-manager` and this method isn't applicable any longer
  71.      * @see https://github.com/Ocramius/ProxyManager
  72.      */
  73.     public function getProxyDir()
  74.     {
  75.         return isset($this->_attributes['proxyDir'])
  76.             ? $this->_attributes['proxyDir']
  77.             : null;
  78.     }
  79.     /**
  80.      * Gets the strategy for automatically generating proxy classes.
  81.      *
  82.      * @return int Possible values are constants of Doctrine\Common\Proxy\AbstractProxyFactory.
  83.      *
  84.      * @deprecated 2.7 We're switch to `ocramius/proxy-manager` and this method isn't applicable any longer
  85.      * @see https://github.com/Ocramius/ProxyManager
  86.      */
  87.     public function getAutoGenerateProxyClasses()
  88.     {
  89.         return isset($this->_attributes['autoGenerateProxyClasses'])
  90.             ? $this->_attributes['autoGenerateProxyClasses']
  91.             : AbstractProxyFactory::AUTOGENERATE_ALWAYS;
  92.     }
  93.     /**
  94.      * Sets the strategy for automatically generating proxy classes.
  95.      *
  96.      * @param boolean|int $autoGenerate Possible values are constants of Doctrine\Common\Proxy\AbstractProxyFactory.
  97.      *                                  True is converted to AUTOGENERATE_ALWAYS, false to AUTOGENERATE_NEVER.
  98.      *
  99.      * @return void
  100.      */
  101.     public function setAutoGenerateProxyClasses($autoGenerate)
  102.     {
  103.         $this->_attributes['autoGenerateProxyClasses'] = (int) $autoGenerate;
  104.     }
  105.     /**
  106.      * Gets the namespace where proxy classes reside.
  107.      *
  108.      * @return string|null
  109.      *
  110.      * @deprecated 2.7 We're switch to `ocramius/proxy-manager` and this method isn't applicable any longer
  111.      * @see https://github.com/Ocramius/ProxyManager
  112.      */
  113.     public function getProxyNamespace()
  114.     {
  115.         return isset($this->_attributes['proxyNamespace'])
  116.             ? $this->_attributes['proxyNamespace']
  117.             : null;
  118.     }
  119.     /**
  120.      * Sets the namespace where proxy classes reside.
  121.      *
  122.      * @param string $ns
  123.      *
  124.      * @return void
  125.      */
  126.     public function setProxyNamespace($ns)
  127.     {
  128.         $this->_attributes['proxyNamespace'] = $ns;
  129.     }
  130.     /**
  131.      * Sets the cache driver implementation that is used for metadata caching.
  132.      *
  133.      * @param MappingDriver $driverImpl
  134.      *
  135.      * @return void
  136.      *
  137.      * @todo Force parameter to be a Closure to ensure lazy evaluation
  138.      *       (as soon as a metadata cache is in effect, the driver never needs to initialize).
  139.      */
  140.     public function setMetadataDriverImpl(MappingDriver $driverImpl)
  141.     {
  142.         $this->_attributes['metadataDriverImpl'] = $driverImpl;
  143.     }
  144.     /**
  145.      * Adds a new default annotation driver with a correctly configured annotation reader. If $useSimpleAnnotationReader
  146.      * is true, the notation `@Entity` will work, otherwise, the notation `@ORM\Entity` will be supported.
  147.      *
  148.      * @param array $paths
  149.      * @param bool  $useSimpleAnnotationReader
  150.      *
  151.      * @return AnnotationDriver
  152.      */
  153.     public function newDefaultAnnotationDriver($paths = [], $useSimpleAnnotationReader true)
  154.     {
  155.         AnnotationRegistry::registerFile(__DIR__ '/Mapping/Driver/DoctrineAnnotations.php');
  156.         if ($useSimpleAnnotationReader) {
  157.             // Register the ORM Annotations in the AnnotationRegistry
  158.             $reader = new SimpleAnnotationReader();
  159.             $reader->addNamespace('Doctrine\ORM\Mapping');
  160.             $cachedReader = new CachedReader($reader, new ArrayCache());
  161.             return new AnnotationDriver($cachedReader, (array) $paths);
  162.         }
  163.         return new AnnotationDriver(
  164.             new CachedReader(new AnnotationReader(), new ArrayCache()),
  165.             (array) $paths
  166.         );
  167.     }
  168.     /**
  169.      * Adds a namespace under a certain alias.
  170.      *
  171.      * @param string $alias
  172.      * @param string $namespace
  173.      *
  174.      * @return void
  175.      */
  176.     public function addEntityNamespace($alias$namespace)
  177.     {
  178.         $this->_attributes['entityNamespaces'][$alias] = $namespace;
  179.     }
  180.     /**
  181.      * Resolves a registered namespace alias to the full namespace.
  182.      *
  183.      * @param string $entityNamespaceAlias
  184.      *
  185.      * @return string
  186.      *
  187.      * @throws ORMException
  188.      */
  189.     public function getEntityNamespace($entityNamespaceAlias)
  190.     {
  191.         if ( ! isset($this->_attributes['entityNamespaces'][$entityNamespaceAlias])) {
  192.             throw ORMException::unknownEntityNamespace($entityNamespaceAlias);
  193.         }
  194.         return trim($this->_attributes['entityNamespaces'][$entityNamespaceAlias], '\\');
  195.     }
  196.     /**
  197.      * Sets the entity alias map.
  198.      *
  199.      * @param array $entityNamespaces
  200.      *
  201.      * @return void
  202.      */
  203.     public function setEntityNamespaces(array $entityNamespaces)
  204.     {
  205.         $this->_attributes['entityNamespaces'] = $entityNamespaces;
  206.     }
  207.     /**
  208.      * Retrieves the list of registered entity namespace aliases.
  209.      *
  210.      * @return array
  211.      */
  212.     public function getEntityNamespaces()
  213.     {
  214.         return $this->_attributes['entityNamespaces'];
  215.     }
  216.     /**
  217.      * Gets the cache driver implementation that is used for the mapping metadata.
  218.      *
  219.      * @return MappingDriver|null
  220.      *
  221.      * @throws ORMException
  222.      */
  223.     public function getMetadataDriverImpl()
  224.     {
  225.         return isset($this->_attributes['metadataDriverImpl'])
  226.             ? $this->_attributes['metadataDriverImpl']
  227.             : null;
  228.     }
  229.     /**
  230.      * Gets the cache driver implementation that is used for the query cache (SQL cache).
  231.      *
  232.      * @return \Doctrine\Common\Cache\Cache|null
  233.      */
  234.     public function getQueryCacheImpl()
  235.     {
  236.         return isset($this->_attributes['queryCacheImpl'])
  237.             ? $this->_attributes['queryCacheImpl']
  238.             : null;
  239.     }
  240.     /**
  241.      * Sets the cache driver implementation that is used for the query cache (SQL cache).
  242.      *
  243.      * @param \Doctrine\Common\Cache\Cache $cacheImpl
  244.      *
  245.      * @return void
  246.      */
  247.     public function setQueryCacheImpl(CacheDriver $cacheImpl)
  248.     {
  249.         $this->_attributes['queryCacheImpl'] = $cacheImpl;
  250.     }
  251.     /**
  252.      * Gets the cache driver implementation that is used for the hydration cache (SQL cache).
  253.      *
  254.      * @return \Doctrine\Common\Cache\Cache|null
  255.      */
  256.     public function getHydrationCacheImpl()
  257.     {
  258.         return isset($this->_attributes['hydrationCacheImpl'])
  259.             ? $this->_attributes['hydrationCacheImpl']
  260.             : null;
  261.     }
  262.     /**
  263.      * Sets the cache driver implementation that is used for the hydration cache (SQL cache).
  264.      *
  265.      * @param \Doctrine\Common\Cache\Cache $cacheImpl
  266.      *
  267.      * @return void
  268.      */
  269.     public function setHydrationCacheImpl(CacheDriver $cacheImpl)
  270.     {
  271.         $this->_attributes['hydrationCacheImpl'] = $cacheImpl;
  272.     }
  273.     /**
  274.      * Gets the cache driver implementation that is used for metadata caching.
  275.      *
  276.      * @return \Doctrine\Common\Cache\Cache|null
  277.      */
  278.     public function getMetadataCacheImpl()
  279.     {
  280.         return isset($this->_attributes['metadataCacheImpl'])
  281.             ? $this->_attributes['metadataCacheImpl']
  282.             : null;
  283.     }
  284.     /**
  285.      * Sets the cache driver implementation that is used for metadata caching.
  286.      *
  287.      * @param \Doctrine\Common\Cache\Cache $cacheImpl
  288.      *
  289.      * @return void
  290.      */
  291.     public function setMetadataCacheImpl(CacheDriver $cacheImpl)
  292.     {
  293.         $this->_attributes['metadataCacheImpl'] = $cacheImpl;
  294.     }
  295.     /**
  296.      * Adds a named DQL query to the configuration.
  297.      *
  298.      * @param string $name The name of the query.
  299.      * @param string $dql  The DQL query string.
  300.      *
  301.      * @return void
  302.      */
  303.     public function addNamedQuery($name$dql)
  304.     {
  305.         $this->_attributes['namedQueries'][$name] = $dql;
  306.     }
  307.     /**
  308.      * Gets a previously registered named DQL query.
  309.      *
  310.      * @param string $name The name of the query.
  311.      *
  312.      * @return string The DQL query.
  313.      *
  314.      * @throws ORMException
  315.      */
  316.     public function getNamedQuery($name)
  317.     {
  318.         if ( ! isset($this->_attributes['namedQueries'][$name])) {
  319.             throw ORMException::namedQueryNotFound($name);
  320.         }
  321.         return $this->_attributes['namedQueries'][$name];
  322.     }
  323.     /**
  324.      * Adds a named native query to the configuration.
  325.      *
  326.      * @param string                 $name The name of the query.
  327.      * @param string                 $sql  The native SQL query string.
  328.      * @param Query\ResultSetMapping $rsm  The ResultSetMapping used for the results of the SQL query.
  329.      *
  330.      * @return void
  331.      */
  332.     public function addNamedNativeQuery($name$sqlQuery\ResultSetMapping $rsm)
  333.     {
  334.         $this->_attributes['namedNativeQueries'][$name] = [$sql$rsm];
  335.     }
  336.     /**
  337.      * Gets the components of a previously registered named native query.
  338.      *
  339.      * @param string $name The name of the query.
  340.      *
  341.      * @return array A tuple with the first element being the SQL string and the second
  342.      *               element being the ResultSetMapping.
  343.      *
  344.      * @throws ORMException
  345.      */
  346.     public function getNamedNativeQuery($name)
  347.     {
  348.         if ( ! isset($this->_attributes['namedNativeQueries'][$name])) {
  349.             throw ORMException::namedNativeQueryNotFound($name);
  350.         }
  351.         return $this->_attributes['namedNativeQueries'][$name];
  352.     }
  353.     /**
  354.      * Ensures that this Configuration instance contains settings that are
  355.      * suitable for a production environment.
  356.      *
  357.      * @return void
  358.      *
  359.      * @throws ORMException If a configuration setting has a value that is not
  360.      *                      suitable for a production environment.
  361.      */
  362.     public function ensureProductionSettings()
  363.     {
  364.         $queryCacheImpl $this->getQueryCacheImpl();
  365.         if ( ! $queryCacheImpl) {
  366.             throw ORMException::queryCacheNotConfigured();
  367.         }
  368.         if ($queryCacheImpl instanceof ArrayCache) {
  369.             throw ORMException::queryCacheUsesNonPersistentCache($queryCacheImpl);
  370.         }
  371.         $metadataCacheImpl $this->getMetadataCacheImpl();
  372.         if ( ! $metadataCacheImpl) {
  373.             throw ORMException::metadataCacheNotConfigured();
  374.         }
  375.         if ($metadataCacheImpl instanceof ArrayCache) {
  376.             throw ORMException::metadataCacheUsesNonPersistentCache($metadataCacheImpl);
  377.         }
  378.         if ($this->getAutoGenerateProxyClasses()) {
  379.             throw ORMException::proxyClassesAlwaysRegenerating();
  380.         }
  381.     }
  382.     /**
  383.      * Registers a custom DQL function that produces a string value.
  384.      * Such a function can then be used in any DQL statement in any place where string
  385.      * functions are allowed.
  386.      *
  387.      * DQL function names are case-insensitive.
  388.      *
  389.      * @param string          $name      Function name.
  390.      * @param string|callable $className Class name or a callable that returns the function.
  391.      *
  392.      * @return void
  393.      */
  394.     public function addCustomStringFunction($name$className)
  395.     {
  396.         $this->_attributes['customStringFunctions'][strtolower($name)] = $className;
  397.     }
  398.     /**
  399.      * Gets the implementation class name of a registered custom string DQL function.
  400.      *
  401.      * @param string $name
  402.      *
  403.      * @return string|null
  404.      */
  405.     public function getCustomStringFunction($name)
  406.     {
  407.         $name strtolower($name);
  408.         return isset($this->_attributes['customStringFunctions'][$name])
  409.             ? $this->_attributes['customStringFunctions'][$name]
  410.             : null;
  411.     }
  412.     /**
  413.      * Sets a map of custom DQL string functions.
  414.      *
  415.      * Keys must be function names and values the FQCN of the implementing class.
  416.      * The function names will be case-insensitive in DQL.
  417.      *
  418.      * Any previously added string functions are discarded.
  419.      *
  420.      * @param array $functions The map of custom DQL string functions.
  421.      *
  422.      * @return void
  423.      */
  424.     public function setCustomStringFunctions(array $functions)
  425.     {
  426.         foreach ($functions as $name => $className) {
  427.             $this->addCustomStringFunction($name$className);
  428.         }
  429.     }
  430.     /**
  431.      * Registers a custom DQL function that produces a numeric value.
  432.      * Such a function can then be used in any DQL statement in any place where numeric
  433.      * functions are allowed.
  434.      *
  435.      * DQL function names are case-insensitive.
  436.      *
  437.      * @param string          $name      Function name.
  438.      * @param string|callable $className Class name or a callable that returns the function.
  439.      *
  440.      * @return void
  441.      */
  442.     public function addCustomNumericFunction($name$className)
  443.     {
  444.         $this->_attributes['customNumericFunctions'][strtolower($name)] = $className;
  445.     }
  446.     /**
  447.      * Gets the implementation class name of a registered custom numeric DQL function.
  448.      *
  449.      * @param string $name
  450.      *
  451.      * @return string|null
  452.      */
  453.     public function getCustomNumericFunction($name)
  454.     {
  455.         $name strtolower($name);
  456.         return isset($this->_attributes['customNumericFunctions'][$name])
  457.             ? $this->_attributes['customNumericFunctions'][$name]
  458.             : null;
  459.     }
  460.     /**
  461.      * Sets a map of custom DQL numeric functions.
  462.      *
  463.      * Keys must be function names and values the FQCN of the implementing class.
  464.      * The function names will be case-insensitive in DQL.
  465.      *
  466.      * Any previously added numeric functions are discarded.
  467.      *
  468.      * @param array $functions The map of custom DQL numeric functions.
  469.      *
  470.      * @return void
  471.      */
  472.     public function setCustomNumericFunctions(array $functions)
  473.     {
  474.         foreach ($functions as $name => $className) {
  475.             $this->addCustomNumericFunction($name$className);
  476.         }
  477.     }
  478.     /**
  479.      * Registers a custom DQL function that produces a date/time value.
  480.      * Such a function can then be used in any DQL statement in any place where date/time
  481.      * functions are allowed.
  482.      *
  483.      * DQL function names are case-insensitive.
  484.      *
  485.      * @param string          $name      Function name.
  486.      * @param string|callable $className Class name or a callable that returns the function.
  487.      *
  488.      * @return void
  489.      */
  490.     public function addCustomDatetimeFunction($name$className)
  491.     {
  492.         $this->_attributes['customDatetimeFunctions'][strtolower($name)] = $className;
  493.     }
  494.     /**
  495.      * Gets the implementation class name of a registered custom date/time DQL function.
  496.      *
  497.      * @param string $name
  498.      *
  499.      * @return string|null
  500.      */
  501.     public function getCustomDatetimeFunction($name)
  502.     {
  503.         $name strtolower($name);
  504.         return isset($this->_attributes['customDatetimeFunctions'][$name])
  505.             ? $this->_attributes['customDatetimeFunctions'][$name]
  506.             : null;
  507.     }
  508.     /**
  509.      * Sets a map of custom DQL date/time functions.
  510.      *
  511.      * Keys must be function names and values the FQCN of the implementing class.
  512.      * The function names will be case-insensitive in DQL.
  513.      *
  514.      * Any previously added date/time functions are discarded.
  515.      *
  516.      * @param array $functions The map of custom DQL date/time functions.
  517.      *
  518.      * @return void
  519.      */
  520.     public function setCustomDatetimeFunctions(array $functions)
  521.     {
  522.         foreach ($functions as $name => $className) {
  523.             $this->addCustomDatetimeFunction($name$className);
  524.         }
  525.     }
  526.     /**
  527.      * Sets the custom hydrator modes in one pass.
  528.      *
  529.      * @param array $modes An array of ($modeName => $hydrator).
  530.      *
  531.      * @return void
  532.      */
  533.     public function setCustomHydrationModes($modes)
  534.     {
  535.         $this->_attributes['customHydrationModes'] = [];
  536.         foreach ($modes as $modeName => $hydrator) {
  537.             $this->addCustomHydrationMode($modeName$hydrator);
  538.         }
  539.     }
  540.     /**
  541.      * Gets the hydrator class for the given hydration mode name.
  542.      *
  543.      * @param string $modeName The hydration mode name.
  544.      *
  545.      * @return string|null The hydrator class name.
  546.      */
  547.     public function getCustomHydrationMode($modeName)
  548.     {
  549.         return isset($this->_attributes['customHydrationModes'][$modeName])
  550.             ? $this->_attributes['customHydrationModes'][$modeName]
  551.             : null;
  552.     }
  553.     /**
  554.      * Adds a custom hydration mode.
  555.      *
  556.      * @param string $modeName The hydration mode name.
  557.      * @param string $hydrator The hydrator class name.
  558.      *
  559.      * @return void
  560.      */
  561.     public function addCustomHydrationMode($modeName$hydrator)
  562.     {
  563.         $this->_attributes['customHydrationModes'][$modeName] = $hydrator;
  564.     }
  565.     /**
  566.      * Sets a class metadata factory.
  567.      *
  568.      * @param string $cmfName
  569.      *
  570.      * @return void
  571.      */
  572.     public function setClassMetadataFactoryName($cmfName)
  573.     {
  574.         $this->_attributes['classMetadataFactoryName'] = $cmfName;
  575.     }
  576.     /**
  577.      * @return string
  578.      */
  579.     public function getClassMetadataFactoryName()
  580.     {
  581.         if ( ! isset($this->_attributes['classMetadataFactoryName'])) {
  582.             $this->_attributes['classMetadataFactoryName'] = ClassMetadataFactory::class;
  583.         }
  584.         return $this->_attributes['classMetadataFactoryName'];
  585.     }
  586.     /**
  587.      * Adds a filter to the list of possible filters.
  588.      *
  589.      * @param string $name      The name of the filter.
  590.      * @param string $className The class name of the filter.
  591.      */
  592.     public function addFilter($name$className)
  593.     {
  594.         $this->_attributes['filters'][$name] = $className;
  595.     }
  596.     /**
  597.      * Gets the class name for a given filter name.
  598.      *
  599.      * @param string $name The name of the filter.
  600.      *
  601.      * @return string The class name of the filter, or null if it is not
  602.      *  defined.
  603.      */
  604.     public function getFilterClassName($name)
  605.     {
  606.         return isset($this->_attributes['filters'][$name])
  607.             ? $this->_attributes['filters'][$name]
  608.             : null;
  609.     }
  610.     /**
  611.      * Sets default repository class.
  612.      *
  613.      * @since 2.2
  614.      *
  615.      * @param string $className
  616.      *
  617.      * @return void
  618.      *
  619.      * @throws ORMException If not is a \Doctrine\Common\Persistence\ObjectRepository
  620.      */
  621.     public function setDefaultRepositoryClassName($className)
  622.     {
  623.         $reflectionClass = new \ReflectionClass($className);
  624.         if ( ! $reflectionClass->implementsInterface(ObjectRepository::class)) {
  625.             throw ORMException::invalidEntityRepository($className);
  626.         }
  627.         $this->_attributes['defaultRepositoryClassName'] = $className;
  628.     }
  629.     /**
  630.      * Get default repository class.
  631.      *
  632.      * @since 2.2
  633.      *
  634.      * @return string
  635.      */
  636.     public function getDefaultRepositoryClassName()
  637.     {
  638.         return isset($this->_attributes['defaultRepositoryClassName'])
  639.             ? $this->_attributes['defaultRepositoryClassName']
  640.             : EntityRepository::class;
  641.     }
  642.     /**
  643.      * Sets naming strategy.
  644.      *
  645.      * @since 2.3
  646.      *
  647.      * @param NamingStrategy $namingStrategy
  648.      *
  649.      * @return void
  650.      */
  651.     public function setNamingStrategy(NamingStrategy $namingStrategy)
  652.     {
  653.         $this->_attributes['namingStrategy'] = $namingStrategy;
  654.     }
  655.     /**
  656.      * Gets naming strategy..
  657.      *
  658.      * @since 2.3
  659.      *
  660.      * @return NamingStrategy
  661.      */
  662.     public function getNamingStrategy()
  663.     {
  664.         if ( ! isset($this->_attributes['namingStrategy'])) {
  665.             $this->_attributes['namingStrategy'] = new DefaultNamingStrategy();
  666.         }
  667.         return $this->_attributes['namingStrategy'];
  668.     }
  669.     /**
  670.      * Sets quote strategy.
  671.      *
  672.      * @since 2.3
  673.      *
  674.      * @param \Doctrine\ORM\Mapping\QuoteStrategy $quoteStrategy
  675.      *
  676.      * @return void
  677.      */
  678.     public function setQuoteStrategy(QuoteStrategy $quoteStrategy)
  679.     {
  680.         $this->_attributes['quoteStrategy'] = $quoteStrategy;
  681.     }
  682.     /**
  683.      * Gets quote strategy.
  684.      *
  685.      * @since 2.3
  686.      *
  687.      * @return \Doctrine\ORM\Mapping\QuoteStrategy
  688.      */
  689.     public function getQuoteStrategy()
  690.     {
  691.         if ( ! isset($this->_attributes['quoteStrategy'])) {
  692.             $this->_attributes['quoteStrategy'] = new DefaultQuoteStrategy();
  693.         }
  694.         return $this->_attributes['quoteStrategy'];
  695.     }
  696.     /**
  697.      * Set the entity listener resolver.
  698.      *
  699.      * @since 2.4
  700.      * @param \Doctrine\ORM\Mapping\EntityListenerResolver $resolver
  701.      */
  702.     public function setEntityListenerResolver(EntityListenerResolver $resolver)
  703.     {
  704.         $this->_attributes['entityListenerResolver'] = $resolver;
  705.     }
  706.     /**
  707.      * Get the entity listener resolver.
  708.      *
  709.      * @since 2.4
  710.      * @return \Doctrine\ORM\Mapping\EntityListenerResolver
  711.      */
  712.     public function getEntityListenerResolver()
  713.     {
  714.         if ( ! isset($this->_attributes['entityListenerResolver'])) {
  715.             $this->_attributes['entityListenerResolver'] = new DefaultEntityListenerResolver();
  716.         }
  717.         return $this->_attributes['entityListenerResolver'];
  718.     }
  719.     /**
  720.      * Set the entity repository factory.
  721.      *
  722.      * @since 2.4
  723.      * @param \Doctrine\ORM\Repository\RepositoryFactory $repositoryFactory
  724.      */
  725.     public function setRepositoryFactory(RepositoryFactory $repositoryFactory)
  726.     {
  727.         $this->_attributes['repositoryFactory'] = $repositoryFactory;
  728.     }
  729.     /**
  730.      * Get the entity repository factory.
  731.      *
  732.      * @since 2.4
  733.      * @return \Doctrine\ORM\Repository\RepositoryFactory
  734.      */
  735.     public function getRepositoryFactory()
  736.     {
  737.         return isset($this->_attributes['repositoryFactory'])
  738.             ? $this->_attributes['repositoryFactory']
  739.             : new DefaultRepositoryFactory();
  740.     }
  741.     /**
  742.      * @since 2.5
  743.      *
  744.      * @return boolean
  745.      */
  746.     public function isSecondLevelCacheEnabled()
  747.     {
  748.         return isset($this->_attributes['isSecondLevelCacheEnabled'])
  749.             ? $this->_attributes['isSecondLevelCacheEnabled']
  750.             : false;
  751.     }
  752.     /**
  753.      * @since 2.5
  754.      *
  755.      * @param boolean $flag
  756.      *
  757.      * @return void
  758.      */
  759.     public function setSecondLevelCacheEnabled($flag true)
  760.     {
  761.         $this->_attributes['isSecondLevelCacheEnabled'] = (boolean) $flag;
  762.     }
  763.     /**
  764.      * @since 2.5
  765.      *
  766.      * @param \Doctrine\ORM\Cache\CacheConfiguration $cacheConfig
  767.      *
  768.      * @return void
  769.      */
  770.     public function setSecondLevelCacheConfiguration(CacheConfiguration $cacheConfig)
  771.     {
  772.         $this->_attributes['secondLevelCacheConfiguration'] = $cacheConfig;
  773.     }
  774.     /**
  775.      * @since 2.5
  776.      *
  777.      * @return  \Doctrine\ORM\Cache\CacheConfiguration|null
  778.      */
  779.     public function getSecondLevelCacheConfiguration()
  780.     {
  781.         if ( ! isset($this->_attributes['secondLevelCacheConfiguration']) && $this->isSecondLevelCacheEnabled()) {
  782.             $this->_attributes['secondLevelCacheConfiguration'] = new CacheConfiguration();
  783.         }
  784.         return isset($this->_attributes['secondLevelCacheConfiguration'])
  785.             ? $this->_attributes['secondLevelCacheConfiguration']
  786.             : null;
  787.     }
  788.     /**
  789.      * Returns query hints, which will be applied to every query in application
  790.      *
  791.      * @since 2.5
  792.      *
  793.      * @return array
  794.      */
  795.     public function getDefaultQueryHints()
  796.     {
  797.         return isset($this->_attributes['defaultQueryHints']) ? $this->_attributes['defaultQueryHints'] : [];
  798.     }
  799.     /**
  800.      * Sets array of query hints, which will be applied to every query in application
  801.      *
  802.      * @since 2.5
  803.      *
  804.      * @param array $defaultQueryHints
  805.      */
  806.     public function setDefaultQueryHints(array $defaultQueryHints)
  807.     {
  808.         $this->_attributes['defaultQueryHints'] = $defaultQueryHints;
  809.     }
  810.     /**
  811.      * Gets the value of a default query hint. If the hint name is not recognized, FALSE is returned.
  812.      *
  813.      * @since 2.5
  814.      *
  815.      * @param string $name The name of the hint.
  816.      *
  817.      * @return mixed The value of the hint or FALSE, if the hint name is not recognized.
  818.      */
  819.     public function getDefaultQueryHint($name)
  820.     {
  821.         return isset($this->_attributes['defaultQueryHints'][$name])
  822.             ? $this->_attributes['defaultQueryHints'][$name]
  823.             : false;
  824.     }
  825.     /**
  826.      * Sets a default query hint. If the hint name is not recognized, it is silently ignored.
  827.      *
  828.      * @since 2.5
  829.      *
  830.      * @param string $name  The name of the hint.
  831.      * @param mixed  $value The value of the hint.
  832.      */
  833.     public function setDefaultQueryHint($name$value)
  834.     {
  835.         $this->_attributes['defaultQueryHints'][$name] = $value;
  836.     }
  837. }