Failed Conditions
Pull Request — develop (#6719)
by Marco
79:37 queued 14:59
created

Configuration::setAutoGenerateProxyClasses()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 20
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 5

Importance

Changes 0
Metric Value
dl 0
loc 20
ccs 5
cts 5
cp 1
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 13
nc 5
nop 1
crap 5
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\ORM;
6
7
use Doctrine\Common\Annotations\AnnotationReader;
8
use Doctrine\Common\Annotations\AnnotationRegistry;
9
use Doctrine\Common\Annotations\CachedReader;
10
use Doctrine\Common\Cache\ArrayCache;
11
use Doctrine\Common\Cache\Cache as CacheDriver;
12
use Doctrine\Common\Persistence\ObjectRepository;
13
use Doctrine\DBAL\Configuration as DBALConfiguration;
14
use Doctrine\ORM\Cache\CacheConfiguration;
15
use Doctrine\ORM\Mapping\ClassMetadataFactory;
16
use Doctrine\ORM\Mapping\DefaultEntityListenerResolver;
17
use Doctrine\ORM\Mapping\Driver\AnnotationDriver;
18
use Doctrine\ORM\Mapping\Driver\MappingDriver;
19
use Doctrine\ORM\Mapping\EntityListenerResolver;
20
use Doctrine\ORM\Mapping\Factory\DefaultNamingStrategy;
21
use Doctrine\ORM\Mapping\Factory\NamingStrategy;
22
use Doctrine\ORM\Proxy\Factory\ProxyFactory;
23
use Doctrine\ORM\Query\ResultSetMapping;
24
use Doctrine\ORM\Repository\DefaultRepositoryFactory;
25
use Doctrine\ORM\Repository\RepositoryFactory;
26
use ProxyManager\Configuration as ProxyManagerConfiguration;
27
use ProxyManager\Factory\LazyLoadingGhostFactory;
28
use ProxyManager\FileLocator\FileLocator;
29
use ProxyManager\GeneratorStrategy\EvaluatingGeneratorStrategy;
30
use ProxyManager\GeneratorStrategy\FileWriterGeneratorStrategy;
31
32
/**
33
 * Configuration container for all configuration options of Doctrine.
34
 * It combines all configuration options from DBAL & ORM.
35
 *
36
 * Internal note: When adding a new configuration option just write a getter/setter pair.
37
 *
38
 * @since 2.0
39
 * @author  Benjamin Eberlei <[email protected]>
40
 * @author  Guilherme Blanco <[email protected]>
41
 * @author  Jonathan Wage <[email protected]>
42
 * @author  Roman Borschel <[email protected]>
43
 */
44
class Configuration extends DBALConfiguration
45
{
46
    /**
47
     * @var ProxyManagerConfiguration|null
48
     */
49
    private $proxyManagerConfiguration;
50
51
    /**
52
     * @var MappingDriver|null
53
     */
54
    private $metadataDriver;
55
56
    /**
57
     * @var CacheDriver|null
58
     */
59
    private $queryCache;
60
61
    /**
62 2296
     * @var CacheDriver|null
63
     */
64 2296
    private $hydrationCache;
65 2296
66
    /**
67
     * @var CacheDriver|null
68
     */
69
    private $metadataCache;
70
71
    /**
72 2293
     * @var string[] indexed by alias
73
     */
74 2293
    private $entityNamespaces = [];
75 2293
76 2293
    /**
77
     * @var string[] of DQL, indexed by query name
78
     */
79
    private $namedQueries = [];
80
81
    /**
82
     * @var string[][]|ResultSetMapping[][] tuples of [$sqlString, $resultSetMapping] indexed by query name
83
     */
84 2295
    private $namedNativeQueries = [];
85
86 2295
    /**
87 5
     * @var string[][]|ResultSetMapping[][] tuples of [$sqlString, $resultSetMapping] indexed by query name
88 2295
     */
89
    private $customStringFunctions = [];
90
91
    /**
92
     * @var string[][]|ResultSetMapping[][] tuples of [$sqlString, $resultSetMapping] indexed by query name
93
     */
94
    private $customNumericFunctions = [];
95
96
    /**
97
     * @var string[][]|ResultSetMapping[][] tuples of [$sqlString, $resultSetMapping] indexed by query name
98
     */
99 14
    private $customDatetimeFunctions = [];
100
101 14
    /**
102 14
     * @var string[] of hydrator class names, indexed by mode name
103
     */
104
    private $customHydrationModes = [];
105
106
    /**
107
     * @var string
108
     */
109 2292
    private $classMetadataFactoryClassName = ClassMetadataFactory::class;
110
111 2292
    /**
112 2292
     * @var string[] of filter class names, indexed by filter name
113 2292
     */
114
    private $filters;
115
116
    /**
117
     * @var string
118
     */
119
    private $defaultRepositoryClassName = EntityRepository::class;
120
121
    /**
122
     * @var NamingStrategy|null
123 2296
     */
124
    private $namingStrategy;
125 2296
126 2296
    /**
127
     * @var EntityListenerResolver|null
128
     */
129
    private $entityListenerResolver;
130
131
    /**
132
     * @var RepositoryFactory|null
133
     */
134
    private $repositoryFactory;
135
136
    /**
137
     * @var bool
138 2295
     */
139
    private $isSecondLevelCacheEnabled = false;
140 2295
141 2295
    /**
142
     * @var CacheConfiguration|null
143
     */
144
    private $secondLevelCacheConfiguration;
145
146
    /**
147
     * @var mixed[] indexed by hint name
148
     */
149
    private $defaultQueryHints = [];
150
151
    /**
152 2275
     * Sets the directory where Doctrine generates any necessary proxy class files.
153
     */
154 2275
    public function setProxyDir(string $directory) : void
155
    {
156 2275
        $this->getProxyManagerConfiguration()->setProxiesTargetDir($directory);
157
        $this->setAutoGenerateProxyClasses(ProxyFactory::AUTOGENERATE_FILE_NOT_EXISTS);
158 2275
    }
159 2275
160 2275
    /**
161
     * Sets the strategy for automatically generating proxy classes.
162 2275
     *
163
     * @param boolean|int $autoGenerate Possible values are constants of Doctrine\ORM\Proxy\Factory\ProxyFactory.
164
     *                                  True is converted to AUTOGENERATE_ALWAYS, false to AUTOGENERATE_NEVER.
165 1
     */
166 1
    public function setAutoGenerateProxyClasses($autoGenerate) : void
167 1
    {
168
        $proxyManagerConfig = $this->getProxyManagerConfiguration();
169
170
        switch ((int) $autoGenerate) {
171
            case ProxyFactory::AUTOGENERATE_ALWAYS:
172
            case ProxyFactory::AUTOGENERATE_FILE_NOT_EXISTS:
173
                $proxyManagerConfig->setGeneratorStrategy(new FileWriterGeneratorStrategy(
174
                    new FileLocator($proxyManagerConfig->getProxiesTargetDir())
175
                ));
176
177
                return;
178
            case ProxyFactory::AUTOGENERATE_NEVER:
179 8
            case ProxyFactory::AUTOGENERATE_EVAL:
180
            default:
181 8
                $proxyManagerConfig->setGeneratorStrategy(new EvaluatingGeneratorStrategy());
182 8
183
                return;
184
        }
185
    }
186
187
    /**
188
     * Sets the namespace where proxy classes reside.
189
     */
190
    public function setProxyNamespace(string $namespace) : void
191
    {
192
        $this->getProxyManagerConfiguration()->setProxiesNamespace($namespace);
193 13
    }
194
195 13
    /**
196 1
     * Sets the cache driver implementation that is used for metadata caching.
197
     *
198
     * @todo Force parameter to be a Closure to ensure lazy evaluation
199 13
     *       (as soon as a metadata cache is in effect, the driver never needs to initialize).
200
     */
201
    public function setMetadataDriverImpl(MappingDriver $metadataDriver) : void
202
    {
203
        $this->metadataDriver = $metadataDriver;
204
    }
205
206
    /**
207
     * Adds a new default annotation driver with a correctly configured annotation reader.
208
     *
209 92
     * @param string[] $paths
210
     *
211 92
     * @return AnnotationDriver
212 92
     */
213
    public function newDefaultAnnotationDriver(array $paths = []) : AnnotationDriver
214
    {
215
        AnnotationRegistry::registerFile(__DIR__ . '/Annotation/DoctrineAnnotations.php');
0 ignored issues
show
Deprecated Code introduced by
The method Doctrine\Common\Annotati...egistry::registerFile() has been deprecated with message: this method is deprecated and will be removed in doctrine/annotations 2.0 autoloading should be deferred to the globally registered autoloader by then. For now, use @example AnnotationRegistry::registerLoader('class_exists')

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
216
217
        $reader = new CachedReader(new AnnotationReader(), new ArrayCache());
218
219 1
        return new AnnotationDriver($reader, $paths);
220
    }
221 1
222
    /**
223
     * Adds a namespace under a certain alias.
224
     */
225
    public function addEntityNamespace(string $alias, string $namespace) : void
226
    {
227
        $this->entityNamespaces[$alias] = $namespace;
228
    }
229
230
    /**
231 1447
     * Resolves a registered namespace alias to the full namespace.
232
     *
233 1447
     * @throws ORMException
234 1447
     */
235 1447
    public function getEntityNamespace(string $entityNamespaceAlias) : string
236
    {
237
        if ( ! isset($this->entityNamespaces[$entityNamespaceAlias])) {
238
            throw ORMException::unknownEntityNamespace($entityNamespaceAlias);
239
        }
240
241
        return trim($this->entityNamespaces[$entityNamespaceAlias], '\\');
242
    }
243 568
244
    /**
245 568
     * Sets the entity alias map.
246 567
     *
247 568
     * @param string[] $entityNamespaces indexed by namespace alias
248
     */
249
    public function setEntityNamespaces(array $entityNamespaces) : void
250
    {
251
        $this->entityNamespaces = $entityNamespaces;
252
    }
253
254
    /**
255
     * Retrieves the list of registered entity namespace aliases.
256
     *
257 2242
     * @return string[] indexed by namespace alias
258
     */
259 2242
    public function getEntityNamespaces() : array
260 2242
    {
261
        return $this->entityNamespaces;
262
    }
263
264
    /**
265
     * Gets the cache driver implementation that is used for the mapping metadata.
266
     */
267 1
    public function getMetadataDriverImpl() : ?MappingDriver
268
    {
269 1
        return $this->metadataDriver;
270 1
    }
271 1
272
    /**
273
     * Gets the cache driver implementation that is used for the query cache (SQL cache).
274
     */
275
    public function getQueryCacheImpl() : ?CacheDriver
276
    {
277
        return $this->queryCache;
278
    }
279
280
    /**
281 1
     * Sets the cache driver implementation that is used for the query cache (SQL cache).
282
     */
283 1
    public function setQueryCacheImpl(CacheDriver $queryCache) : void
284 1
    {
285
        $this->queryCache = $queryCache;
286
    }
287
288
    /**
289
     * Gets the cache driver implementation that is used for the hydration cache (SQL cache).
290
     */
291 2299
    public function getHydrationCacheImpl() : ?CacheDriver
292
    {
293 2299
        return $this->hydrationCache;
294 2237
    }
295 2299
296
    /**
297
     * Sets the cache driver implementation that is used for the hydration cache (SQL cache).
298
     */
299
    public function setHydrationCacheImpl(CacheDriver $hydrationCache) : void
300
    {
301
        $this->hydrationCache = $hydrationCache;
302
    }
303
304
    /**
305 2242
     * Gets the cache driver implementation that is used for metadata caching.
306
     */
307 2242
    public function getMetadataCacheImpl() : ?CacheDriver
308 2242
    {
309
        return $this->metadataCache;
310
    }
311
312
    /**
313
     * Sets the cache driver implementation that is used for metadata caching.
314
     */
315
    public function setMetadataCacheImpl(CacheDriver $metadataCache) : void
316
    {
317
        $this->metadataCache = $metadataCache;
318 1
    }
319
320 1
    /**
321 1
     * Adds a named DQL query to the configuration.
322
     */
323
    public function addNamedQuery(string $queryName, string $dqlQuery) : void
324
    {
325
        $this->namedQueries[$queryName] = $dqlQuery;
326
    }
327
328
    /**
329
     * Gets a previously registered named DQL query.
330
     *
331
     * @throws ORMException
332 2
     */
333
    public function getNamedQuery(string $queryName) : string
334 2
    {
335 2
        if ( ! isset($this->namedQueries[$queryName])) {
336
            throw ORMException::namedQueryNotFound($queryName);
337
        }
338 1
339
        return $this->namedQueries[$queryName];
340
    }
341
342
    /**
343
     * Adds a named native query to the configuration.
344
     */
345
    public function addNamedNativeQuery(string $queryName, string $sql, ResultSetMapping $resultSetMapping) : void
346
    {
347
        $this->namedNativeQueries[$queryName] = [$sql, $resultSetMapping];
348
    }
349
350 1
    /**
351
     * Gets the components of a previously registered named native query.
352 1
     *
353 1
     * @return string[]|ResultSetMapping[] tuple of [$sqlString, $resultSetMaping]
354
     *
355
     * @throws ORMException
356
     */
357
    public function getNamedNativeQuery(string $queryName) : array
358
    {
359
        if ( ! isset($this->namedNativeQueries[$queryName])) {
360
            throw ORMException::namedNativeQueryNotFound($queryName);
361
        }
362
363
        return $this->namedNativeQueries[$queryName];
364
    }
365 1
366
    /**
367 1
     * Ensures that this Configuration instance contains settings that are
368
     * suitable for a production environment.
369
     *
370
     * @throws ORMException If a configuration setting has a value that is not
371 1
     *                      suitable for a production environment.
372
     */
373
    public function ensureProductionSettings() : void
374
    {
375
        $queryCacheImpl = $this->getQueryCacheImpl();
376
377
        if ( ! $queryCacheImpl) {
378
            throw ORMException::queryCacheNotConfigured();
379
        }
380
381
        if ($queryCacheImpl instanceof ArrayCache) {
382
            throw ORMException::queryCacheUsesNonPersistentCache($queryCacheImpl);
383 8
        }
384
385 8
        $metadataCacheImpl = $this->getMetadataCacheImpl();
386
387 8
        if ( ! $metadataCacheImpl) {
388 1
            throw ORMException::metadataCacheNotConfigured();
389
        }
390
391 7
        if ($metadataCacheImpl instanceof ArrayCache) {
392 1
            throw ORMException::metadataCacheUsesNonPersistentCache($metadataCacheImpl);
393
        }
394
395 6
        if ($this->getProxyManagerConfiguration()->getGeneratorStrategy() instanceof EvaluatingGeneratorStrategy) {
396
            throw ORMException::proxyClassesAlwaysRegenerating();
397 6
        }
398 1
    }
399
400
    /**
401 5
     * Registers a custom DQL function that produces a string value.
402 1
     * Such a function can then be used in any DQL statement in any place where string
403
     * functions are allowed.
404
     *
405 4
     * DQL function names are case-insensitive.
406 3
     *
407
     * @param string|callable $classNameOrFactory Class name or a callable that returns the function.
408 1
     */
409
    public function addCustomStringFunction(string $functionName, $classNameOrFactory) : void
410
    {
411
        $this->customStringFunctions[\strtolower($functionName)] = $classNameOrFactory;
412
    }
413
414
    /**
415
     * Gets the implementation class name of a registered custom string DQL function.
416
     *
417
     * @return string|callable|null
418
     */
419
    public function getCustomStringFunction(string $functionName)
420
    {
421
        return $this->customStringFunctions[\strtolower($functionName)] ?? null;
422
    }
423
424 3
    /**
425
     * Sets a map of custom DQL string functions.
426 3
     *
427 1
     * Keys must be function names and values the FQCN of the implementing class.
428
     * The function names will be case-insensitive in DQL.
429
     *
430 3
     * Any previously added string functions are discarded.
431 3
     *
432
     * @param array $functions The map of custom DQL string functions.
433
     */
434
    public function setCustomStringFunctions(array $functions) : void
435
    {
436
        foreach ($functions as $name => $className) {
437
            $this->addCustomStringFunction($name, $className);
438
        }
439
    }
440 4
441
    /**
442 4
     * Registers a custom DQL function that produces a numeric value.
443
     * Such a function can then be used in any DQL statement in any place where numeric
444 4
     * functions are allowed.
445 3
     *
446 4
     * DQL function names are case-insensitive.
447
     *
448
     * @param string|callable $classNameOrFactory Class name or a callable that returns the function.
449
     */
450
    public function addCustomNumericFunction(string $functionName, $classNameOrFactory) : void
451
    {
452
        $this->customNumericFunctions[\strtolower($functionName)] = $classNameOrFactory;
453
    }
454
455
    /**
456
     * Gets the implementation class name of a registered custom numeric DQL function.
457
     *
458
     * @return string|callable|null
459
     */
460
    public function getCustomNumericFunction(string $functionName)
461 1
    {
462
        return $this->customNumericFunctions[\strtolower($functionName)] ?? null;
463 1
    }
464 1
465
    /**
466 1
     * Sets a map of custom DQL numeric functions.
467
     *
468
     * Keys must be function names and values the FQCN of the implementing class.
469
     * The function names will be case-insensitive in DQL.
470
     *
471
     * Any previously added numeric functions are discarded.
472
     *
473
     * @param array $functions The map of custom DQL numeric functions.
474
     */
475
    public function setCustomNumericFunctions(array $functions) : void
476
    {
477
        foreach ($functions as $name => $className) {
478
            $this->addCustomNumericFunction($name, $className);
479
        }
480
    }
481
482 3
    /**
483
     * Registers a custom DQL function that produces a date/time value.
484 3
     * Such a function can then be used in any DQL statement in any place where date/time
485 1
     * functions are allowed.
486
     *
487
     * DQL function names are case-insensitive.
488 3
     *
489 3
     * @param string|callable $classNameOrFactory Class name or a callable that returns the function.
490
     */
491
    public function addCustomDatetimeFunction(string $functionName, $classNameOrFactory)
492
    {
493
        $this->customDatetimeFunctions[\strtolower($functionName)] = $classNameOrFactory;
494
    }
495
496
    /**
497
     * Gets the implementation class name of a registered custom date/time DQL function.
498 3
     *
499
     * @return string|callable|null
500 3
     */
501
    public function getCustomDatetimeFunction(string $functionName)
502 3
    {
503 3
        return $this->customDatetimeFunctions[\strtolower($functionName)] ?? null;
504 3
    }
505
506
    /**
507
     * Sets a map of custom DQL date/time functions.
508
     *
509
     * Keys must be function names and values the FQCN of the implementing class.
510
     * The function names will be case-insensitive in DQL.
511
     *
512
     * Any previously added date/time functions are discarded.
513
     *
514
     * @param array $functions The map of custom DQL date/time functions.
515
     */
516
    public function setCustomDatetimeFunctions(array $functions) : void
517
    {
518
        foreach ($functions as $name => $className) {
519 1
            $this->addCustomDatetimeFunction($name, $className);
520
        }
521 1
    }
522 1
523
    /**
524 1
     * Sets the custom hydrator modes in one pass.
525
     *
526
     * @param iterable $modes An iterable of string $modeName => string $hydratorClassName
527
     */
528
    public function setCustomHydrationModes(iterable $modes) : void
529
    {
530
        $this->customHydrationModes = [];
531
532
        foreach ($modes as $modeName => $hydrator) {
533
            $this->addCustomHydrationMode($modeName, $hydrator);
534
        }
535
    }
536
537
    /**
538
     * Gets the hydrator class for the given hydration mode name.
539
     *
540 1
     * @return string|null The hydrator class name.
541
     */
542 1
    public function getCustomHydrationMode(string $modeName) : ?string
543 1
    {
544
        return $this->customHydrationModes[$modeName] ?? null;
545
    }
546 1
547 1
    /**
548
     * Adds a custom hydration mode.
549
     */
550
    public function addCustomHydrationMode(string $modeName, string $hydratorClassName) : void
551
    {
552
        $this->customHydrationModes[$modeName] = $hydratorClassName;
553
    }
554
555
    /**
556 1
     * Sets a class metadata factory.
557
     */
558 1
    public function setClassMetadataFactoryName(string $classMetadataFactoryClassName) : void
559
    {
560 1
        $this->classMetadataFactoryClassName = $classMetadataFactoryClassName;
561 1
    }
562 1
563
    public function getClassMetadataFactoryName() : string
564
    {
565
        return $this->classMetadataFactoryClassName;
566
    }
567
568
    /**
569
     * Adds a filter to the list of possible filters.
570
     */
571
    public function addFilter(string $filterName, string $filterClassName) : void
572
    {
573
        $this->filters[$filterName] = $filterClassName;
574
    }
575
576
    /**
577 1
     * Gets the class name for a given filter name.
578
     *
579 1
     * @return string|null The class name of the filter
580 1
     */
581
    public function getFilterClassName(string $filterName) : ?string
582 1
    {
583
        return $this->filters[$filterName] ?? null;
584
    }
585
586
    /**
587
     * Sets default repository class.
588
     *
589
     * @since 2.2
590
     *
591 1
     * @throws ORMException If not is a \Doctrine\Common\Persistence\ObjectRepository implementation
592
     */
593 1
    public function setDefaultRepositoryClassName(string $repositoryClassName) : void
594
    {
595 1
        $reflectionClass = new \ReflectionClass($repositoryClassName);
596 1
597
        if ( ! $reflectionClass->implementsInterface(ObjectRepository::class)) {
598 1
            throw ORMException::invalidEntityRepository($repositoryClassName);
599
        }
600
601
        $this->defaultRepositoryClassName = $repositoryClassName;
602
    }
603
604
    /**
605
     * Get default repository class.
606
     *
607 3
     * @since 2.2
608
     */
609 3
    public function getDefaultRepositoryClassName() : string
610 3
    {
611 3
        return $this->defaultRepositoryClassName;
612
    }
613
614
    /**
615
     * Sets naming strategy.
616
     *
617
     * @since 2.3
618
     */
619
    public function setNamingStrategy(NamingStrategy $namingStrategy) : void
620
    {
621
        $this->namingStrategy = $namingStrategy;
622 3
    }
623
624 3
    /**
625 3
     * Gets naming strategy..
626
     *
627
     * @since 2.3
628
     */
629
    public function getNamingStrategy() : ?NamingStrategy
630
    {
631
        return $this->namingStrategy
632
            ?? $this->namingStrategy = new DefaultNamingStrategy();
633
    }
634 1
635
    /**
636 1
     * Set the entity listener resolver.
637 1
     *
638
     * @since 2.4
639
     */
640
    public function setEntityListenerResolver(EntityListenerResolver $resolver) : void
641
    {
642 2291
        $this->entityListenerResolver = $resolver;
643
    }
644 2291
645 2291
    /**
646
     * Get the entity listener resolver.
647
     *
648 2291
     * @since 2.4
649
     */
650
    public function getEntityListenerResolver() : EntityListenerResolver
651
    {
652
        return $this->entityListenerResolver
653
            ?? $this->entityListenerResolver = new DefaultEntityListenerResolver();
654
    }
655
656
    /**
657 46
     * Set the entity repository factory.
658
     *
659 46
     * @since 2.4
660 46
     */
661
    public function setRepositoryFactory(RepositoryFactory $repositoryFactory) : void
662
    {
663
        $this->repositoryFactory = $repositoryFactory;
664
    }
665
666
    /**
667
     * Get the entity repository factory.
668
     *
669
     * @since 2.4
670 45
     */
671
    public function getRepositoryFactory() : RepositoryFactory
672 45
    {
673 45
        return $this->repositoryFactory
674 45
            ?? $this->repositoryFactory = new DefaultRepositoryFactory();
675
    }
676
677
    /**
678
     * @since 2.5
679
     */
680
    public function isSecondLevelCacheEnabled() : bool
681
    {
682
        return $this->isSecondLevelCacheEnabled;
683
    }
684
685
    /**
686
     * @since 2.5
687
     */
688 3
    public function setSecondLevelCacheEnabled(bool $flag = true) : void
689
    {
690 3
        $this->isSecondLevelCacheEnabled = $flag;
691
    }
692 3
693 1
    /**
694
     * @since 2.5
695
     */
696 2
    public function setSecondLevelCacheConfiguration(CacheConfiguration $cacheConfig) : void
697 2
    {
698
        $this->secondLevelCacheConfiguration = $cacheConfig;
699
    }
700
701
    /**
702
     * @since 2.5
703
     *
704
     * @return  \Doctrine\ORM\Cache\CacheConfiguration|null
705
     */
706 139
    public function getSecondLevelCacheConfiguration() : ?CacheConfiguration
707
    {
708 139
        if ($this->isSecondLevelCacheEnabled && ! $this->secondLevelCacheConfiguration) {
709 2
            $this->secondLevelCacheConfiguration = new CacheConfiguration();
710 139
        }
711
712
        return $this->secondLevelCacheConfiguration;
713
    }
714
715
    /**
716
     * Returns query hints, which will be applied to every query in application
717
     *
718
     * @since 2.5
719
     */
720
    public function getDefaultQueryHints() : array
721
    {
722 5
        return $this->defaultQueryHints;
723
    }
724 5
725 5
    /**
726
     * Sets array of query hints, which will be applied to every query in application
727
     *
728
     * @since 2.5
729
     */
730
    public function setDefaultQueryHints(array $defaultQueryHints) : void
731
    {
732
        $this->defaultQueryHints = $defaultQueryHints;
733
    }
734 391
735
    /**
736 391
     * Gets the value of a default query hint. If the hint name is not recognized, FALSE is returned.
737 391
     *
738
     * @since 2.5
739
     *
740 391
     * @return mixed The value of the hint or FALSE, if the hint name is not recognized.
741
     */
742
    public function getDefaultQueryHint(string $hintName)
743
    {
744
        return $this->defaultQueryHints[$hintName] ?? false;
745
    }
746
747
    /**
748
     * Sets a default query hint. If the hint name is not recognized, it is silently ignored.
749
     *
750
     * @since 2.5
751
     *
752 1
     * @param mixed  $value The value of the hint.
753
     */
754 1
    public function setDefaultQueryHint(string $hintName, $value) : void
755 1
    {
756
        $this->defaultQueryHints[$hintName] = $value;
757
    }
758
759
    public function buildGhostObjectFactory() : LazyLoadingGhostFactory
760
    {
761
        return new LazyLoadingGhostFactory(clone $this->getProxyManagerConfiguration());
762
    }
763
764 1602
    public function getProxyManagerConfiguration() : ProxyManagerConfiguration
765
    {
766 1602
        return $this->proxyManagerConfiguration
767 1602
            ?? $this->proxyManagerConfiguration = new ProxyManagerConfiguration();
768
    }
769
}
770