Failed Conditions
Pull Request — 2.6 (#7197)
by JHONATAN
09:37
created

Configuration::setCustomDatetimeFunctions()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 2
nc 2
nop 1
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 2
rs 10
c 0
b 0
f 0
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
20
namespace Doctrine\ORM;
21
22
use Doctrine\Common\Annotations\AnnotationReader;
23
use Doctrine\Common\Annotations\AnnotationRegistry;
24
use Doctrine\Common\Annotations\CachedReader;
25
use Doctrine\Common\Annotations\SimpleAnnotationReader;
26
use Doctrine\Common\Cache\ArrayCache;
27
use Doctrine\Common\Cache\Cache as CacheDriver;
28
use Doctrine\Common\Persistence\Mapping\Driver\MappingDriver;
29
use Doctrine\Common\Persistence\ObjectRepository;
30
use Doctrine\Common\Proxy\AbstractProxyFactory;
31
use Doctrine\ORM\Cache\CacheConfiguration;
32
use Doctrine\ORM\Mapping\ClassMetadataFactory;
33
use Doctrine\ORM\Mapping\DefaultEntityListenerResolver;
34
use Doctrine\ORM\Mapping\DefaultNamingStrategy;
35
use Doctrine\ORM\Mapping\DefaultQuoteStrategy;
36
use Doctrine\ORM\Mapping\Driver\AnnotationDriver;
37
use Doctrine\ORM\Mapping\EntityListenerResolver;
38
use Doctrine\ORM\Mapping\NamingStrategy;
39
use Doctrine\ORM\Mapping\QuoteStrategy;
40
use Doctrine\ORM\Repository\DefaultRepositoryFactory;
41
use Doctrine\ORM\Repository\RepositoryFactory;
42
43
/**
44
 * Configuration container for all configuration options of Doctrine.
45
 * It combines all configuration options from DBAL & ORM.
46
 *
47
 * Internal note: When adding a new configuration option just write a getter/setter pair.
48
 *
49
 * @since 2.0
50
 * @author  Benjamin Eberlei <[email protected]>
51
 * @author  Guilherme Blanco <[email protected]>
52
 * @author  Jonathan Wage <[email protected]>
53
 * @author  Roman Borschel <[email protected]>
54
 */
55
class Configuration extends \Doctrine\DBAL\Configuration
56
{
57
    /**
58
     * @var array
59
     */
60
    private $customBooleanFunctions;
61
62
    /**
63
     * Sets the directory where Doctrine generates any necessary proxy class files.
64
     *
65
     * @param string $dir
66
     *
67
     * @return void
68
     */
69 2474
    public function setProxyDir($dir)
70
    {
71 2474
        $this->_attributes['proxyDir'] = $dir;
72 2474
    }
73
74
    /**
75
     * Gets the directory where Doctrine generates any necessary proxy class files.
76
     *
77
     * @return string|null
78
     */
79 2467
    public function getProxyDir()
80
    {
81 2467
        return isset($this->_attributes['proxyDir'])
82 2467
            ? $this->_attributes['proxyDir']
83 2467
            : null;
84
    }
85
86
    /**
87
     * Gets the strategy for automatically generating proxy classes.
88
     *
89
     * @return int Possible values are constants of Doctrine\Common\Proxy\AbstractProxyFactory.
90
     */
91 2469
    public function getAutoGenerateProxyClasses()
92
    {
93 2469
        return isset($this->_attributes['autoGenerateProxyClasses'])
94 5
            ? $this->_attributes['autoGenerateProxyClasses']
95 2469
            : AbstractProxyFactory::AUTOGENERATE_ALWAYS;
96
    }
97
98
    /**
99
     * Sets the strategy for automatically generating proxy classes.
100
     *
101
     * @param boolean|int $autoGenerate Possible values are constants of Doctrine\Common\Proxy\AbstractProxyFactory.
102
     *                                  True is converted to AUTOGENERATE_ALWAYS, false to AUTOGENERATE_NEVER.
103
     *
104
     * @return void
105
     */
106 18
    public function setAutoGenerateProxyClasses($autoGenerate)
107
    {
108 18
        $this->_attributes['autoGenerateProxyClasses'] = (int) $autoGenerate;
109 18
    }
110
111
    /**
112
     * Gets the namespace where proxy classes reside.
113
     *
114
     * @return string|null
115
     */
116 2466
    public function getProxyNamespace()
117
    {
118 2466
        return isset($this->_attributes['proxyNamespace'])
119 2466
            ? $this->_attributes['proxyNamespace']
120 2466
            : null;
121
    }
122
123
    /**
124
     * Sets the namespace where proxy classes reside.
125
     *
126
     * @param string $ns
127
     *
128
     * @return void
129
     */
130 2474
    public function setProxyNamespace($ns)
131
    {
132 2474
        $this->_attributes['proxyNamespace'] = $ns;
133 2474
    }
134
135
    /**
136
     * Sets the cache driver implementation that is used for metadata caching.
137
     *
138
     * @param MappingDriver $driverImpl
139
     *
140
     * @return void
141
     *
142
     * @todo Force parameter to be a Closure to ensure lazy evaluation
143
     *       (as soon as a metadata cache is in effect, the driver never needs to initialize).
144
     */
145 2470
    public function setMetadataDriverImpl(MappingDriver $driverImpl)
146
    {
147 2470
        $this->_attributes['metadataDriverImpl'] = $driverImpl;
148 2470
    }
149
150
    /**
151
     * Adds a new default annotation driver with a correctly configured annotation reader. If $useSimpleAnnotationReader
152
     * is true, the notation `@Entity` will work, otherwise, the notation `@ORM\Entity` will be supported.
153
     *
154
     * @param array $paths
155
     * @param bool  $useSimpleAnnotationReader
156
     *
157
     * @return AnnotationDriver
158
     */
159 2445
    public function newDefaultAnnotationDriver($paths = [], $useSimpleAnnotationReader = true)
160
    {
161 2445
        AnnotationRegistry::registerFile(__DIR__ . '/Mapping/Driver/DoctrineAnnotations.php');
0 ignored issues
show
Deprecated Code introduced by
The function Doctrine\Common\Annotati...egistry::registerFile() has been deprecated: 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') ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

161
        /** @scrutinizer ignore-deprecated */ AnnotationRegistry::registerFile(__DIR__ . '/Mapping/Driver/DoctrineAnnotations.php');

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

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

Loading history...
162
163 2445
        if ($useSimpleAnnotationReader) {
164
            // Register the ORM Annotations in the AnnotationRegistry
165 2445
            $reader = new SimpleAnnotationReader();
166 2445
            $reader->addNamespace('Doctrine\ORM\Mapping');
167 2445
            $cachedReader = new CachedReader($reader, new ArrayCache());
168
169 2445
            return new AnnotationDriver($cachedReader, (array) $paths);
0 ignored issues
show
Bug introduced by
$cachedReader of type Doctrine\Common\Annotations\CachedReader is incompatible with the type Doctrine\Common\Annotations\AnnotationReader expected by parameter $reader of Doctrine\ORM\Mapping\Dri...onDriver::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

169
            return new AnnotationDriver(/** @scrutinizer ignore-type */ $cachedReader, (array) $paths);
Loading history...
170
        }
171
172 1
        return new AnnotationDriver(
173 1
            new CachedReader(new AnnotationReader(), new ArrayCache()),
174 1
            (array) $paths
175
        );
176
    }
177
178
    /**
179
     * Adds a namespace under a certain alias.
180
     *
181
     * @param string $alias
182
     * @param string $namespace
183
     *
184
     * @return void
185
     */
186 8
    public function addEntityNamespace($alias, $namespace)
187
    {
188 8
        $this->_attributes['entityNamespaces'][$alias] = $namespace;
189 8
    }
190
191
    /**
192
     * Resolves a registered namespace alias to the full namespace.
193
     *
194
     * @param string $entityNamespaceAlias
195
     *
196
     * @return string
197
     *
198
     * @throws ORMException
199
     */
200 13
    public function getEntityNamespace($entityNamespaceAlias)
201
    {
202 13
        if ( ! isset($this->_attributes['entityNamespaces'][$entityNamespaceAlias])) {
203 1
            throw ORMException::unknownEntityNamespace($entityNamespaceAlias);
204
        }
205
206 13
        return trim($this->_attributes['entityNamespaces'][$entityNamespaceAlias], '\\');
207
    }
208
209
    /**
210
     * Sets the entity alias map.
211
     *
212
     * @param array $entityNamespaces
213
     *
214
     * @return void
215
     */
216 97
    public function setEntityNamespaces(array $entityNamespaces)
217
    {
218 97
        $this->_attributes['entityNamespaces'] = $entityNamespaces;
219 97
    }
220
221
    /**
222
     * Retrieves the list of registered entity namespace aliases.
223
     *
224
     * @return array
225
     */
226 1
    public function getEntityNamespaces()
227
    {
228 1
        return $this->_attributes['entityNamespaces'];
229
    }
230
231
    /**
232
     * Gets the cache driver implementation that is used for the mapping metadata.
233
     *
234
     * @return MappingDriver|null
235
     *
236
     * @throws ORMException
237
     */
238 1580
    public function getMetadataDriverImpl()
239
    {
240 1580
        return isset($this->_attributes['metadataDriverImpl'])
241 1580
            ? $this->_attributes['metadataDriverImpl']
242 1580
            : null;
243
    }
244
245
    /**
246
     * Gets the cache driver implementation that is used for the query cache (SQL cache).
247
     *
248
     * @return \Doctrine\Common\Cache\Cache|null
249
     */
250 612
    public function getQueryCacheImpl()
251
    {
252 612
        return isset($this->_attributes['queryCacheImpl'])
253 611
            ? $this->_attributes['queryCacheImpl']
254 612
            : null;
255
    }
256
257
    /**
258
     * Sets the cache driver implementation that is used for the query cache (SQL cache).
259
     *
260
     * @param \Doctrine\Common\Cache\Cache $cacheImpl
261
     *
262
     * @return void
263
     */
264 2399
    public function setQueryCacheImpl(CacheDriver $cacheImpl)
265
    {
266 2399
        $this->_attributes['queryCacheImpl'] = $cacheImpl;
267 2399
    }
268
269
    /**
270
     * Gets the cache driver implementation that is used for the hydration cache (SQL cache).
271
     *
272
     * @return \Doctrine\Common\Cache\Cache|null
273
     */
274 1
    public function getHydrationCacheImpl()
275
    {
276 1
        return isset($this->_attributes['hydrationCacheImpl'])
277 1
            ? $this->_attributes['hydrationCacheImpl']
278 1
            : null;
279
    }
280
281
    /**
282
     * Sets the cache driver implementation that is used for the hydration cache (SQL cache).
283
     *
284
     * @param \Doctrine\Common\Cache\Cache $cacheImpl
285
     *
286
     * @return void
287
     */
288 1
    public function setHydrationCacheImpl(CacheDriver $cacheImpl)
289
    {
290 1
        $this->_attributes['hydrationCacheImpl'] = $cacheImpl;
291 1
    }
292
293
    /**
294
     * Gets the cache driver implementation that is used for metadata caching.
295
     *
296
     * @return \Doctrine\Common\Cache\Cache|null
297
     */
298 2476
    public function getMetadataCacheImpl()
299
    {
300 2476
        return isset($this->_attributes['metadataCacheImpl'])
301 2393
            ? $this->_attributes['metadataCacheImpl']
302 2476
            : null;
303
    }
304
305
    /**
306
     * Sets the cache driver implementation that is used for metadata caching.
307
     *
308
     * @param \Doctrine\Common\Cache\Cache $cacheImpl
309
     *
310
     * @return void
311
     */
312 2399
    public function setMetadataCacheImpl(CacheDriver $cacheImpl)
313
    {
314 2399
        $this->_attributes['metadataCacheImpl'] = $cacheImpl;
315 2399
    }
316
317
    /**
318
     * Adds a named DQL query to the configuration.
319
     *
320
     * @param string $name The name of the query.
321
     * @param string $dql  The DQL query string.
322
     *
323
     * @return void
324
     */
325 1
    public function addNamedQuery($name, $dql)
326
    {
327 1
        $this->_attributes['namedQueries'][$name] = $dql;
328 1
    }
329
330
    /**
331
     * Gets a previously registered named DQL query.
332
     *
333
     * @param string $name The name of the query.
334
     *
335
     * @return string The DQL query.
336
     *
337
     * @throws ORMException
338
     */
339 1
    public function getNamedQuery($name)
340
    {
341 1
        if ( ! isset($this->_attributes['namedQueries'][$name])) {
342 1
            throw ORMException::namedQueryNotFound($name);
343
        }
344
345 1
        return $this->_attributes['namedQueries'][$name];
346
    }
347
348
    /**
349
     * Adds a named native query to the configuration.
350
     *
351
     * @param string                 $name The name of the query.
352
     * @param string                 $sql  The native SQL query string.
353
     * @param Query\ResultSetMapping $rsm  The ResultSetMapping used for the results of the SQL query.
354
     *
355
     * @return void
356
     */
357 1
    public function addNamedNativeQuery($name, $sql, Query\ResultSetMapping $rsm)
358
    {
359 1
        $this->_attributes['namedNativeQueries'][$name] = [$sql, $rsm];
360 1
    }
361
362
    /**
363
     * Gets the components of a previously registered named native query.
364
     *
365
     * @param string $name The name of the query.
366
     *
367
     * @return array A tuple with the first element being the SQL string and the second
368
     *               element being the ResultSetMapping.
369
     *
370
     * @throws ORMException
371
     */
372 1
    public function getNamedNativeQuery($name)
373
    {
374 1
        if ( ! isset($this->_attributes['namedNativeQueries'][$name])) {
375 1
            throw ORMException::namedNativeQueryNotFound($name);
376
        }
377
378 1
        return $this->_attributes['namedNativeQueries'][$name];
379
    }
380
381
    /**
382
     * Ensures that this Configuration instance contains settings that are
383
     * suitable for a production environment.
384
     *
385
     * @return void
386
     *
387
     * @throws ORMException If a configuration setting has a value that is not
388
     *                      suitable for a production environment.
389
     */
390 8
    public function ensureProductionSettings()
391
    {
392 8
        $queryCacheImpl = $this->getQueryCacheImpl();
393
394 8
        if ( ! $queryCacheImpl) {
395 1
            throw ORMException::queryCacheNotConfigured();
396
        }
397
398 7
        if ($queryCacheImpl instanceof ArrayCache) {
399 1
            throw ORMException::queryCacheUsesNonPersistentCache($queryCacheImpl);
400
        }
401
402 6
        $metadataCacheImpl = $this->getMetadataCacheImpl();
403
404 6
        if ( ! $metadataCacheImpl) {
405 1
            throw ORMException::metadataCacheNotConfigured();
406
        }
407
408 5
        if ($metadataCacheImpl instanceof ArrayCache) {
409 1
            throw ORMException::metadataCacheUsesNonPersistentCache($metadataCacheImpl);
410
        }
411
412 4
        if ($this->getAutoGenerateProxyClasses()) {
413 3
            throw ORMException::proxyClassesAlwaysRegenerating();
414
        }
415 1
    }
416
417
    /**
418
     * Registers a custom DQL function that produces a string value.
419
     * Such a function can then be used in any DQL statement in any place where string
420
     * functions are allowed.
421
     *
422
     * DQL function names are case-insensitive.
423
     *
424
     * @param string          $name      Function name.
425
     * @param string|callable $className Class name or a callable that returns the function.
426
     *
427
     * @return void
428
     */
429 4
    public function addCustomStringFunction($name, $className)
430
    {
431 4
        $this->_attributes['customStringFunctions'][strtolower($name)] = $className;
432 4
    }
433
434
    /**
435
     * Gets the implementation class name of a registered custom string DQL function.
436
     *
437
     * @param string $name
438
     *
439
     * @return string|null
440
     */
441 156
    public function getCustomStringFunction($name)
442
    {
443 156
        $name = strtolower($name);
444
445 156
        return isset($this->_attributes['customStringFunctions'][$name])
446 4
            ? $this->_attributes['customStringFunctions'][$name]
447 156
            : null;
448
    }
449
450
    /**
451
     * Sets a map of custom DQL string functions.
452
     *
453
     * Keys must be function names and values the FQCN of the implementing class.
454
     * The function names will be case-insensitive in DQL.
455
     *
456
     * Any previously added string functions are discarded.
457
     *
458
     * @param array $functions The map of custom DQL string functions.
459
     *
460
     * @return void
461
     */
462 1
    public function setCustomStringFunctions(array $functions)
463
    {
464 1
        foreach ($functions as $name => $className) {
465 1
            $this->addCustomStringFunction($name, $className);
466
        }
467 1
    }
468
469
    /**
470
     * Registers a custom DQL function that produces a numeric value.
471
     * Such a function can then be used in any DQL statement in any place where numeric
472
     * functions are allowed.
473
     *
474
     * DQL function names are case-insensitive.
475
     *
476
     * @param string          $name      Function name.
477
     * @param string|callable $className Class name or a callable that returns the function.
478
     *
479
     * @return void
480
     */
481 3
    public function addCustomNumericFunction($name, $className)
482
    {
483 3
        $this->_attributes['customNumericFunctions'][strtolower($name)] = $className;
484 3
    }
485
486
    /**
487
     * Gets the implementation class name of a registered custom numeric DQL function.
488
     *
489
     * @param string $name
490
     *
491
     * @return string|null
492
     */
493 154
    public function getCustomNumericFunction($name)
494
    {
495 154
        $name = strtolower($name);
496
497 154
        return isset($this->_attributes['customNumericFunctions'][$name])
498 3
            ? $this->_attributes['customNumericFunctions'][$name]
499 154
            : null;
500
    }
501
502
    /**
503
     * Sets a map of custom DQL numeric functions.
504
     *
505
     * Keys must be function names and values the FQCN of the implementing class.
506
     * The function names will be case-insensitive in DQL.
507
     *
508
     * Any previously added numeric functions are discarded.
509
     *
510
     * @param array $functions The map of custom DQL numeric functions.
511
     *
512
     * @return void
513
     */
514 2
    public function setCustomNumericFunctions(array $functions)
515
    {
516 2
        foreach ($functions as $name => $className) {
517 1
            $this->addCustomNumericFunction($name, $className);
518
        }
519 2
    }
520
521
    /**
522
     * Registers a custom DQL function that produces a date/time value.
523
     * Such a function can then be used in any DQL statement in any place where date/time
524
     * functions are allowed.
525
     *
526
     * DQL function names are case-insensitive.
527
     *
528
     * @param string          $name      Function name.
529
     * @param string|callable $className Class name or a callable that returns the function.
530
     *
531
     * @return void
532
     */
533 1
    public function addCustomDatetimeFunction($name, $className)
534
    {
535 1
        $this->_attributes['customDatetimeFunctions'][strtolower($name)] = $className;
536 1
    }
537
538
    /**
539
     * Gets the implementation class name of a registered custom date/time DQL function.
540
     *
541
     * @param string $name
542
     *
543
     * @return string|null
544
     */
545 152
    public function getCustomDatetimeFunction($name)
546
    {
547 152
        $name = strtolower($name);
548
549 152
        return isset($this->_attributes['customDatetimeFunctions'][$name])
550 1
            ? $this->_attributes['customDatetimeFunctions'][$name]
551 152
            : null;
552
    }
553
554
    /**
555
     * Sets a map of custom DQL date/time functions.
556
     *
557
     * Keys must be function names and values the FQCN of the implementing class.
558
     * The function names will be case-insensitive in DQL.
559
     *
560
     * Any previously added date/time functions are discarded.
561
     *
562
     * @param array $functions The map of custom DQL date/time functions.
563
     *
564
     * @return void
565
     */
566 1
    public function setCustomDatetimeFunctions(array $functions)
567
    {
568 1
        foreach ($functions as $name => $className) {
569 1
            $this->addCustomDatetimeFunction($name, $className);
570
        }
571 1
    }
572
    
573
    /**
574
     * Registers a custom DQL function that produces a boolean value.
575
     * Such a function can then be used in any DQL statement on where clauses
576
     *
577
     * DQL function names are case-insensitive.
578
     *
579
     * @param string|callable $classNameOrFactory Class name or a callable that returns the function.
580
     */
581 1
    public function addCustomBooleanFunction(string $functionName, $classNameOrFactory)
582
    {
583 1
        $this->customBooleanFunctions[strtolower($functionName)] = $classNameOrFactory;
584 1
    }
585
586
    /**
587
     * Gets the implementation class name of a registered custom boolean DQL function.
588
     *
589
     * @return string|callable|null
590
     */
591 1
    public function getCustomBooleanFunction(string $functionName)
592
    {
593 1
        return $this->customBooleanFunctions[strtolower($functionName)] ?? null;
594
    }
595
596
    /**
597
     * Sets a map of custom DQL boolean functions.
598
     *
599
     * Keys must be function names and values the FQCN of the implementing class.
600
     * The function names will be case-insensitive in DQL.
601
     *
602
     * Any previously added date/time functions are discarded.
603
     *
604
     * @param iterable|string[] $functions The map of custom DQL date/time functions.
605
     */
606
    public function setCustomBooleanFunctions(array $functions) : void
607
    {
608
        foreach ($functions as $name => $className) {
609
            $this->addCustomBooleanFunction($name, $className);
610
        }
611
    }
612
613
    /**
614
     * Sets the custom hydrator modes in one pass.
615
     *
616
     * @param array $modes An array of ($modeName => $hydrator).
617
     *
618
     * @return void
619
     */
620 1
    public function setCustomHydrationModes($modes)
621
    {
622 1
        $this->_attributes['customHydrationModes'] = [];
623
624 1
        foreach ($modes as $modeName => $hydrator) {
625 1
            $this->addCustomHydrationMode($modeName, $hydrator);
626
        }
627 1
    }
628
629
    /**
630
     * Gets the hydrator class for the given hydration mode name.
631
     *
632
     * @param string $modeName The hydration mode name.
633
     *
634
     * @return string|null The hydrator class name.
635
     */
636 3
    public function getCustomHydrationMode($modeName)
637
    {
638 3
        return isset($this->_attributes['customHydrationModes'][$modeName])
639 3
            ? $this->_attributes['customHydrationModes'][$modeName]
640 3
            : null;
641
    }
642
643
    /**
644
     * Adds a custom hydration mode.
645
     *
646
     * @param string $modeName The hydration mode name.
647
     * @param string $hydrator The hydrator class name.
648
     *
649
     * @return void
650
     */
651 3
    public function addCustomHydrationMode($modeName, $hydrator)
652
    {
653 3
        $this->_attributes['customHydrationModes'][$modeName] = $hydrator;
654 3
    }
655
656
    /**
657
     * Sets a class metadata factory.
658
     *
659
     * @param string $cmfName
660
     *
661
     * @return void
662
     */
663 1
    public function setClassMetadataFactoryName($cmfName)
664
    {
665 1
        $this->_attributes['classMetadataFactoryName'] = $cmfName;
666 1
    }
667
668
    /**
669
     * @return string
670
     */
671 2465
    public function getClassMetadataFactoryName()
672
    {
673 2465
        if ( ! isset($this->_attributes['classMetadataFactoryName'])) {
674 2465
            $this->_attributes['classMetadataFactoryName'] = ClassMetadataFactory::class;
675
        }
676
677 2465
        return $this->_attributes['classMetadataFactoryName'];
678
    }
679
680
    /**
681
     * Adds a filter to the list of possible filters.
682
     *
683
     * @param string $name      The name of the filter.
684
     * @param string $className The class name of the filter.
685
     */
686 46
    public function addFilter($name, $className)
687
    {
688 46
        $this->_attributes['filters'][$name] = $className;
689 46
    }
690
691
    /**
692
     * Gets the class name for a given filter name.
693
     *
694
     * @param string $name The name of the filter.
695
     *
696
     * @return string The class name of the filter, or null if it is not
697
     *  defined.
698
     */
699 45
    public function getFilterClassName($name)
700
    {
701 45
        return isset($this->_attributes['filters'][$name])
702 45
            ? $this->_attributes['filters'][$name]
703 45
            : null;
704
    }
705
706
    /**
707
     * Sets default repository class.
708
     *
709
     * @since 2.2
710
     *
711
     * @param string $className
712
     *
713
     * @return void
714
     *
715
     * @throws ORMException If not is a \Doctrine\Common\Persistence\ObjectRepository
716
     */
717 3
    public function setDefaultRepositoryClassName($className)
718
    {
719 3
        $reflectionClass = new \ReflectionClass($className);
720
721 3
        if ( ! $reflectionClass->implementsInterface(ObjectRepository::class)) {
722 1
            throw ORMException::invalidEntityRepository($className);
723
        }
724
725 2
        $this->_attributes['defaultRepositoryClassName'] = $className;
726 2
    }
727
728
    /**
729
     * Get default repository class.
730
     *
731
     * @since 2.2
732
     *
733
     * @return string
734
     */
735 155
    public function getDefaultRepositoryClassName()
736
    {
737 155
        return isset($this->_attributes['defaultRepositoryClassName'])
738 2
            ? $this->_attributes['defaultRepositoryClassName']
739 155
            : EntityRepository::class;
740
    }
741
742
    /**
743
     * Sets naming strategy.
744
     *
745
     * @since 2.3
746
     *
747
     * @param NamingStrategy $namingStrategy
748
     *
749
     * @return void
750
     */
751 7
    public function setNamingStrategy(NamingStrategy $namingStrategy)
752
    {
753 7
        $this->_attributes['namingStrategy'] = $namingStrategy;
754 7
    }
755
756
    /**
757
     * Gets naming strategy..
758
     *
759
     * @since 2.3
760
     *
761
     * @return NamingStrategy
762
     */
763 478
    public function getNamingStrategy()
764
    {
765 478
        if ( ! isset($this->_attributes['namingStrategy'])) {
766 478
            $this->_attributes['namingStrategy'] = new DefaultNamingStrategy();
767
        }
768
769 478
        return $this->_attributes['namingStrategy'];
770
    }
771
772
    /**
773
     * Sets quote strategy.
774
     *
775
     * @since 2.3
776
     *
777
     * @param \Doctrine\ORM\Mapping\QuoteStrategy $quoteStrategy
778
     *
779
     * @return void
780
     */
781 2
    public function setQuoteStrategy(QuoteStrategy $quoteStrategy)
782
    {
783 2
        $this->_attributes['quoteStrategy'] = $quoteStrategy;
784 2
    }
785
786
    /**
787
     * Gets quote strategy.
788
     *
789
     * @since 2.3
790
     *
791
     * @return \Doctrine\ORM\Mapping\QuoteStrategy
792
     */
793 1699
    public function getQuoteStrategy()
794
    {
795 1699
        if ( ! isset($this->_attributes['quoteStrategy'])) {
796 1699
            $this->_attributes['quoteStrategy'] = new DefaultQuoteStrategy();
797
        }
798
799 1699
        return $this->_attributes['quoteStrategy'];
800
    }
801
802
    /**
803
     * Set the entity listener resolver.
804
     *
805
     * @since 2.4
806
     * @param \Doctrine\ORM\Mapping\EntityListenerResolver $resolver
807
     */
808 1
    public function setEntityListenerResolver(EntityListenerResolver $resolver)
809
    {
810 1
        $this->_attributes['entityListenerResolver'] = $resolver;
811 1
    }
812
813
    /**
814
     * Get the entity listener resolver.
815
     *
816
     * @since 2.4
817
     * @return \Doctrine\ORM\Mapping\EntityListenerResolver
818
     */
819 2465
    public function getEntityListenerResolver()
820
    {
821 2465
        if ( ! isset($this->_attributes['entityListenerResolver'])) {
822 2465
            $this->_attributes['entityListenerResolver'] = new DefaultEntityListenerResolver();
823
        }
824
825 2465
        return $this->_attributes['entityListenerResolver'];
826
    }
827
828
    /**
829
     * Set the entity repository factory.
830
     *
831
     * @since 2.4
832
     * @param \Doctrine\ORM\Repository\RepositoryFactory $repositoryFactory
833
     */
834
    public function setRepositoryFactory(RepositoryFactory $repositoryFactory)
835
    {
836
        $this->_attributes['repositoryFactory'] = $repositoryFactory;
837
    }
838
839
    /**
840
     * Get the entity repository factory.
841
     *
842
     * @since 2.4
843
     * @return \Doctrine\ORM\Repository\RepositoryFactory
844
     */
845 2464
    public function getRepositoryFactory()
846
    {
847 2464
        return isset($this->_attributes['repositoryFactory'])
848
            ? $this->_attributes['repositoryFactory']
849 2464
            : new DefaultRepositoryFactory();
850
    }
851
852
    /**
853
     * @since 2.5
854
     *
855
     * @return boolean
856
     */
857 2465
    public function isSecondLevelCacheEnabled()
858
    {
859 2465
        return isset($this->_attributes['isSecondLevelCacheEnabled'])
860 286
            ? $this->_attributes['isSecondLevelCacheEnabled']
861 2465
            : false;
862
    }
863
864
    /**
865
     * @since 2.5
866
     *
867
     * @param boolean $flag
868
     *
869
     * @return void
870
     */
871 286
    public function setSecondLevelCacheEnabled($flag = true)
872
    {
873 286
        $this->_attributes['isSecondLevelCacheEnabled'] = (boolean) $flag;
874 286
    }
875
876
    /**
877
     * @since 2.5
878
     *
879
     * @param \Doctrine\ORM\Cache\CacheConfiguration $cacheConfig
880
     *
881
     * @return void
882
     */
883 287
    public function setSecondLevelCacheConfiguration(CacheConfiguration $cacheConfig)
884
    {
885 287
        $this->_attributes['secondLevelCacheConfiguration'] = $cacheConfig;
886 287
    }
887
888
    /**
889
     * @since 2.5
890
     *
891
     * @return  \Doctrine\ORM\Cache\CacheConfiguration|null
892
     */
893 287
    public function getSecondLevelCacheConfiguration()
894
    {
895 287
        if ( ! isset($this->_attributes['secondLevelCacheConfiguration']) && $this->isSecondLevelCacheEnabled()) {
896
            $this->_attributes['secondLevelCacheConfiguration'] = new CacheConfiguration();
897
        }
898
899 287
        return isset($this->_attributes['secondLevelCacheConfiguration'])
900 287
            ? $this->_attributes['secondLevelCacheConfiguration']
901 287
            : null;
902
    }
903
904
    /**
905
     * Returns query hints, which will be applied to every query in application
906
     *
907
     * @since 2.5
908
     *
909
     * @return array
910
     */
911 995
    public function getDefaultQueryHints()
912
    {
913 995
        return isset($this->_attributes['defaultQueryHints']) ? $this->_attributes['defaultQueryHints'] : [];
914
    }
915
916
    /**
917
     * Sets array of query hints, which will be applied to every query in application
918
     *
919
     * @since 2.5
920
     *
921
     * @param array $defaultQueryHints
922
     */
923 1
    public function setDefaultQueryHints(array $defaultQueryHints)
924
    {
925 1
        $this->_attributes['defaultQueryHints'] = $defaultQueryHints;
926 1
    }
927
928
    /**
929
     * Gets the value of a default query hint. If the hint name is not recognized, FALSE is returned.
930
     *
931
     * @since 2.5
932
     *
933
     * @param string $name The name of the hint.
934
     *
935
     * @return mixed The value of the hint or FALSE, if the hint name is not recognized.
936
     */
937
    public function getDefaultQueryHint($name)
938
    {
939
        return isset($this->_attributes['defaultQueryHints'][$name])
940
            ? $this->_attributes['defaultQueryHints'][$name]
941
            : false;
942
    }
943
944
    /**
945
     * Sets a default query hint. If the hint name is not recognized, it is silently ignored.
946
     *
947
     * @since 2.5
948
     *
949
     * @param string $name  The name of the hint.
950
     * @param mixed  $value The value of the hint.
951
     */
952 1
    public function setDefaultQueryHint($name, $value)
953
    {
954 1
        $this->_attributes['defaultQueryHints'][$name] = $value;
955 1
    }
956
}
957