Failed Conditions
Pull Request — 2.6 (#7197)
by JHONATAN
11:05
created

Configuration::getCustomBooleanFunction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
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
     * Sets the directory where Doctrine generates any necessary proxy class files.
59
     *
60
     * @param string $dir
61
     *
62
     * @return void
63
     */
64 2474
    public function setProxyDir($dir)
65
    {
66 2474
        $this->_attributes['proxyDir'] = $dir;
67 2474
    }
68
69
    /**
70
     * Gets the directory where Doctrine generates any necessary proxy class files.
71
     *
72
     * @return string|null
73
     */
74 2467
    public function getProxyDir()
75
    {
76 2467
        return isset($this->_attributes['proxyDir'])
77 2467
            ? $this->_attributes['proxyDir']
78 2467
            : null;
79
    }
80
81
    /**
82
     * Gets the strategy for automatically generating proxy classes.
83
     *
84
     * @return int Possible values are constants of Doctrine\Common\Proxy\AbstractProxyFactory.
85
     */
86 2469
    public function getAutoGenerateProxyClasses()
87
    {
88 2469
        return isset($this->_attributes['autoGenerateProxyClasses'])
89 5
            ? $this->_attributes['autoGenerateProxyClasses']
90 2469
            : AbstractProxyFactory::AUTOGENERATE_ALWAYS;
91
    }
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 18
    public function setAutoGenerateProxyClasses($autoGenerate)
102
    {
103 18
        $this->_attributes['autoGenerateProxyClasses'] = (int) $autoGenerate;
104 18
    }
105
106
    /**
107
     * Gets the namespace where proxy classes reside.
108
     *
109
     * @return string|null
110
     */
111 2466
    public function getProxyNamespace()
112
    {
113 2466
        return isset($this->_attributes['proxyNamespace'])
114 2466
            ? $this->_attributes['proxyNamespace']
115 2466
            : null;
116
    }
117
118
    /**
119
     * Sets the namespace where proxy classes reside.
120
     *
121
     * @param string $ns
122
     *
123
     * @return void
124
     */
125 2474
    public function setProxyNamespace($ns)
126
    {
127 2474
        $this->_attributes['proxyNamespace'] = $ns;
128 2474
    }
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 2470
    public function setMetadataDriverImpl(MappingDriver $driverImpl)
141
    {
142 2470
        $this->_attributes['metadataDriverImpl'] = $driverImpl;
143 2470
    }
144
145
    /**
146
     * Adds a new default annotation driver with a correctly configured annotation reader. If $useSimpleAnnotationReader
147
     * is true, the notation `@Entity` will work, otherwise, the notation `@ORM\Entity` will be supported.
148
     *
149
     * @param array $paths
150
     * @param bool  $useSimpleAnnotationReader
151
     *
152
     * @return AnnotationDriver
153
     */
154 2445
    public function newDefaultAnnotationDriver($paths = [], $useSimpleAnnotationReader = true)
155
    {
156 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

156
        /** @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...
157
158 2445
        if ($useSimpleAnnotationReader) {
159
            // Register the ORM Annotations in the AnnotationRegistry
160 2445
            $reader = new SimpleAnnotationReader();
161 2445
            $reader->addNamespace('Doctrine\ORM\Mapping');
162 2445
            $cachedReader = new CachedReader($reader, new ArrayCache());
163
164 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

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