Completed
Pull Request — master (#6501)
by Matthias
71:49 queued 65:37
created

Configuration   F

Complexity

Total Complexity 99

Size/Duplication

Total Lines 875
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 14

Test Coverage

Coverage 96.14%

Importance

Changes 0
Metric Value
wmc 99
lcom 1
cbo 14
dl 0
loc 875
ccs 224
cts 233
cp 0.9614
rs 1.5999
c 0
b 0
f 0

58 Methods

Rating   Name   Duplication   Size   Complexity  
A setProxyDir() 0 4 1
A getProxyDir() 0 6 2
A getAutoGenerateProxyClasses() 0 6 2
A setAutoGenerateProxyClasses() 0 4 1
A getProxyNamespace() 0 6 2
A setProxyNamespace() 0 4 1
A setMetadataDriverImpl() 0 4 1
A newDefaultAnnotationDriver() 0 18 2
A addEntityNamespace() 0 4 1
A getEntityNamespace() 0 8 2
A setEntityNamespaces() 0 4 1
A getEntityNamespaces() 0 4 1
A getMetadataDriverImpl() 0 6 2
A getQueryCacheImpl() 0 6 2
A setQueryCacheImpl() 0 4 1
A getHydrationCacheImpl() 0 6 2
A setHydrationCacheImpl() 0 4 1
A getMetadataCacheImpl() 0 6 2
A setMetadataCacheImpl() 0 4 1
A addNamedQuery() 0 4 1
A getNamedQuery() 0 8 2
A addNamedNativeQuery() 0 4 1
A getNamedNativeQuery() 0 8 2
B ensureProductionSettings() 0 26 6
A addCustomStringFunction() 0 8 2
A getCustomStringFunction() 0 8 2
A setCustomStringFunctions() 0 6 2
A addCustomNumericFunction() 0 8 2
A getCustomNumericFunction() 0 8 2
A setCustomNumericFunctions() 0 6 2
A addCustomDatetimeFunction() 0 8 2
A getCustomDatetimeFunction() 0 8 2
A setCustomDatetimeFunctions() 0 6 2
A setCustomHydrationModes() 0 8 2
A getCustomHydrationMode() 0 6 2
A addCustomHydrationMode() 0 4 1
A setClassMetadataFactoryName() 0 4 1
A getClassMetadataFactoryName() 0 8 2
A addFilter() 0 4 1
A getFilterClassName() 0 6 2
A setDefaultRepositoryClassName() 0 10 2
A getDefaultRepositoryClassName() 0 6 2
A setNamingStrategy() 0 4 1
A getNamingStrategy() 0 8 2
A setQuoteStrategy() 0 4 1
A getQuoteStrategy() 0 8 2
A setEntityListenerResolver() 0 4 1
A getEntityListenerResolver() 0 8 2
A setRepositoryFactory() 0 4 1
A getRepositoryFactory() 0 6 2
A isSecondLevelCacheEnabled() 0 6 2
A setSecondLevelCacheEnabled() 0 4 1
A setSecondLevelCacheConfiguration() 0 4 1
A getSecondLevelCacheConfiguration() 0 10 4
A getDefaultQueryHints() 0 4 2
A setDefaultQueryHints() 0 4 1
A getDefaultQueryHint() 0 6 2
A setDefaultQueryHint() 0 4 1

How to fix   Complexity   

Complex Class

Complex classes like Configuration often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use Configuration, and based on these observations, apply Extract Interface, too.

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 2390
    public function setProxyDir($dir)
65
    {
66 2390
        $this->_attributes['proxyDir'] = $dir;
67 2390
    }
68
69
    /**
70
     * Gets the directory where Doctrine generates any necessary proxy class files.
71
     *
72
     * @return string|null
73
     */
74 2386
    public function getProxyDir()
75
    {
76 2386
        return isset($this->_attributes['proxyDir'])
77 2386
            ? $this->_attributes['proxyDir']
78 2386
            : 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 2388
    public function getAutoGenerateProxyClasses()
87
    {
88 2388
        return isset($this->_attributes['autoGenerateProxyClasses'])
89 5
            ? $this->_attributes['autoGenerateProxyClasses']
90 2388
            : 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 15
    public function setAutoGenerateProxyClasses($autoGenerate)
102
    {
103 15
        $this->_attributes['autoGenerateProxyClasses'] = (int) $autoGenerate;
104 15
    }
105
106
    /**
107
     * Gets the namespace where proxy classes reside.
108
     *
109
     * @return string|null
110
     */
111 2385
    public function getProxyNamespace()
112
    {
113 2385
        return isset($this->_attributes['proxyNamespace'])
114 2385
            ? $this->_attributes['proxyNamespace']
115 2385
            : null;
116
    }
117
118
    /**
119
     * Sets the namespace where proxy classes reside.
120
     *
121
     * @param string $ns
122
     *
123
     * @return void
124
     */
125 2390
    public function setProxyNamespace($ns)
126
    {
127 2390
        $this->_attributes['proxyNamespace'] = $ns;
128 2390
    }
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 2389
    public function setMetadataDriverImpl(MappingDriver $driverImpl)
141
    {
142 2389
        $this->_attributes['metadataDriverImpl'] = $driverImpl;
143 2389
    }
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 2365
    public function newDefaultAnnotationDriver($paths = [], $useSimpleAnnotationReader = true)
155
    {
156 2365
        AnnotationRegistry::registerFile(__DIR__ . '/Mapping/Driver/DoctrineAnnotations.php');
157
158 2365
        if ($useSimpleAnnotationReader) {
159
            // Register the ORM Annotations in the AnnotationRegistry
160 2365
            $reader = new SimpleAnnotationReader();
161 2365
            $reader->addNamespace('Doctrine\ORM\Mapping');
162 2365
            $cachedReader = new CachedReader($reader, new ArrayCache());
163
164 2365
            return new AnnotationDriver($cachedReader, (array) $paths);
0 ignored issues
show
Documentation introduced by
$cachedReader is of type object<Doctrine\Common\Annotations\CachedReader>, but the function expects a object<Doctrine\Common\A...tions\AnnotationReader>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
165
        }
166
167 1
        return new AnnotationDriver(
168 1
            new CachedReader(new AnnotationReader(), new ArrayCache()),
0 ignored issues
show
Documentation introduced by
new \Doctrine\Common\Ann...mon\Cache\ArrayCache()) is of type object<Doctrine\Common\Annotations\CachedReader>, but the function expects a object<Doctrine\Common\A...tions\AnnotationReader>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
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 1521
    public function getMetadataDriverImpl()
234
    {
235 1521
        return isset($this->_attributes['metadataDriverImpl'])
236 1521
            ? $this->_attributes['metadataDriverImpl']
237 1521
            : 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 577
    public function getQueryCacheImpl()
246
    {
247 577
        return isset($this->_attributes['queryCacheImpl'])
248 576
            ? $this->_attributes['queryCacheImpl']
249 577
            : 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 2326
    public function setQueryCacheImpl(CacheDriver $cacheImpl)
260
    {
261 2326
        $this->_attributes['queryCacheImpl'] = $cacheImpl;
262 2326
    }
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 2392
    public function getMetadataCacheImpl()
294
    {
295 2392
        return isset($this->_attributes['metadataCacheImpl'])
296 2320
            ? $this->_attributes['metadataCacheImpl']
297 2392
            : 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 2326
    public function setMetadataCacheImpl(CacheDriver $cacheImpl)
308
    {
309 2326
        $this->_attributes['metadataCacheImpl'] = $cacheImpl;
310 2326
    }
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
     * @throws ORMException
425
     */
426 3
    public function addCustomStringFunction($name, $className)
427
    {
428 3
        if (Query\Parser::isInternalFunction($name)) {
429 1
            throw ORMException::overwriteInternalDQLFunctionNotAllowed($name);
430
        }
431
432 3
        $this->_attributes['customStringFunctions'][strtolower($name)] = $className;
433 3
    }
434
435
    /**
436
     * Gets the implementation class name of a registered custom string DQL function.
437
     *
438
     * @param string $name
439
     *
440
     * @return string|null
441
     */
442 4
    public function getCustomStringFunction($name)
443
    {
444 4
        $name = strtolower($name);
445
446 4
        return isset($this->_attributes['customStringFunctions'][$name])
447 3
            ? $this->_attributes['customStringFunctions'][$name]
448 4
            : null;
449
    }
450
451
    /**
452
     * Sets a map of custom DQL string functions.
453
     *
454
     * Keys must be function names and values the FQCN of the implementing class.
455
     * The function names will be case-insensitive in DQL.
456
     *
457
     * Any previously added string functions are discarded.
458
     *
459
     * @param array $functions The map of custom DQL string functions.
460
     *
461
     * @return void
462
     */
463 1
    public function setCustomStringFunctions(array $functions)
464
    {
465 1
        foreach ($functions as $name => $className) {
466 1
            $this->addCustomStringFunction($name, $className);
467
        }
468 1
    }
469
470
    /**
471
     * Registers a custom DQL function that produces a numeric value.
472
     * Such a function can then be used in any DQL statement in any place where numeric
473
     * functions are allowed.
474
     *
475
     * DQL function names are case-insensitive.
476
     *
477
     * @param string          $name      Function name.
478
     * @param string|callable $className Class name or a callable that returns the function.
479
     *
480
     * @return void
481
     *
482
     * @throws ORMException
483
     */
484 3
    public function addCustomNumericFunction($name, $className)
485
    {
486 3
        if (Query\Parser::isInternalFunction($name)) {
487 1
            throw ORMException::overwriteInternalDQLFunctionNotAllowed($name);
488
        }
489
490 3
        $this->_attributes['customNumericFunctions'][strtolower($name)] = $className;
491 3
    }
492
493
    /**
494
     * Gets the implementation class name of a registered custom numeric DQL function.
495
     *
496
     * @param string $name
497
     *
498
     * @return string|null
499
     */
500 3
    public function getCustomNumericFunction($name)
501
    {
502 3
        $name = strtolower($name);
503
504 3
        return isset($this->_attributes['customNumericFunctions'][$name])
505 3
            ? $this->_attributes['customNumericFunctions'][$name]
506 3
            : null;
507
    }
508
509
    /**
510
     * Sets a map of custom DQL numeric functions.
511
     *
512
     * Keys must be function names and values the FQCN of the implementing class.
513
     * The function names will be case-insensitive in DQL.
514
     *
515
     * Any previously added numeric functions are discarded.
516
     *
517
     * @param array $functions The map of custom DQL numeric functions.
518
     *
519
     * @return void
520
     */
521 2
    public function setCustomNumericFunctions(array $functions)
522
    {
523 2
        foreach ($functions as $name => $className) {
524 1
            $this->addCustomNumericFunction($name, $className);
525
        }
526 2
    }
527
528
    /**
529
     * Registers a custom DQL function that produces a date/time value.
530
     * Such a function can then be used in any DQL statement in any place where date/time
531
     * functions are allowed.
532
     *
533
     * DQL function names are case-insensitive.
534
     *
535
     * @param string          $name      Function name.
536
     * @param string|callable $className Class name or a callable that returns the function.
537
     *
538
     * @return void
539
     *
540
     * @throws ORMException
541
     */
542 1
    public function addCustomDatetimeFunction($name, $className)
543
    {
544 1
        if (Query\Parser::isInternalFunction($name)) {
545 1
            throw ORMException::overwriteInternalDQLFunctionNotAllowed($name);
546
        }
547
548 1
        $this->_attributes['customDatetimeFunctions'][strtolower($name)] = $className;
549 1
    }
550
551
    /**
552
     * Gets the implementation class name of a registered custom date/time DQL function.
553
     *
554
     * @param string $name
555
     *
556
     * @return string|null
557
     */
558 1
    public function getCustomDatetimeFunction($name)
559
    {
560 1
        $name = strtolower($name);
561
562 1
        return isset($this->_attributes['customDatetimeFunctions'][$name])
563 1
            ? $this->_attributes['customDatetimeFunctions'][$name]
564 1
            : null;
565
    }
566
567
    /**
568
     * Sets a map of custom DQL date/time functions.
569
     *
570
     * Keys must be function names and values the FQCN of the implementing class.
571
     * The function names will be case-insensitive in DQL.
572
     *
573
     * Any previously added date/time functions are discarded.
574
     *
575
     * @param array $functions The map of custom DQL date/time functions.
576
     *
577
     * @return void
578
     */
579 1
    public function setCustomDatetimeFunctions(array $functions)
580
    {
581 1
        foreach ($functions as $name => $className) {
582 1
            $this->addCustomDatetimeFunction($name, $className);
583
        }
584 1
    }
585
586
    /**
587
     * Sets the custom hydrator modes in one pass.
588
     *
589
     * @param array $modes An array of ($modeName => $hydrator).
590
     *
591
     * @return void
592
     */
593 1
    public function setCustomHydrationModes($modes)
594
    {
595 1
        $this->_attributes['customHydrationModes'] = [];
596
597 1
        foreach ($modes as $modeName => $hydrator) {
598 1
            $this->addCustomHydrationMode($modeName, $hydrator);
599
        }
600 1
    }
601
602
    /**
603
     * Gets the hydrator class for the given hydration mode name.
604
     *
605
     * @param string $modeName The hydration mode name.
606
     *
607
     * @return string|null The hydrator class name.
608
     */
609 3
    public function getCustomHydrationMode($modeName)
610
    {
611 3
        return isset($this->_attributes['customHydrationModes'][$modeName])
612 3
            ? $this->_attributes['customHydrationModes'][$modeName]
613 3
            : null;
614
    }
615
616
    /**
617
     * Adds a custom hydration mode.
618
     *
619
     * @param string $modeName The hydration mode name.
620
     * @param string $hydrator The hydrator class name.
621
     *
622
     * @return void
623
     */
624 3
    public function addCustomHydrationMode($modeName, $hydrator)
625
    {
626 3
        $this->_attributes['customHydrationModes'][$modeName] = $hydrator;
627 3
    }
628
629
    /**
630
     * Sets a class metadata factory.
631
     *
632
     * @param string $cmfName
633
     *
634
     * @return void
635
     */
636 1
    public function setClassMetadataFactoryName($cmfName)
637
    {
638 1
        $this->_attributes['classMetadataFactoryName'] = $cmfName;
639 1
    }
640
641
    /**
642
     * @return string
643
     */
644 2384
    public function getClassMetadataFactoryName()
645
    {
646 2384
        if ( ! isset($this->_attributes['classMetadataFactoryName'])) {
647 2384
            $this->_attributes['classMetadataFactoryName'] = ClassMetadataFactory::class;
648
        }
649
650 2384
        return $this->_attributes['classMetadataFactoryName'];
651
    }
652
653
    /**
654
     * Adds a filter to the list of possible filters.
655
     *
656
     * @param string $name      The name of the filter.
657
     * @param string $className The class name of the filter.
658
     */
659 46
    public function addFilter($name, $className)
660
    {
661 46
        $this->_attributes['filters'][$name] = $className;
662 46
    }
663
664
    /**
665
     * Gets the class name for a given filter name.
666
     *
667
     * @param string $name The name of the filter.
668
     *
669
     * @return string The class name of the filter, or null if it is not
670
     *  defined.
671
     */
672 45
    public function getFilterClassName($name)
673
    {
674 45
        return isset($this->_attributes['filters'][$name])
675 45
            ? $this->_attributes['filters'][$name]
676 45
            : null;
677
    }
678
679
    /**
680
     * Sets default repository class.
681
     *
682
     * @since 2.2
683
     *
684
     * @param string $className
685
     *
686
     * @return void
687
     *
688
     * @throws ORMException If not is a \Doctrine\Common\Persistence\ObjectRepository
689
     */
690 3
    public function setDefaultRepositoryClassName($className)
691
    {
692 3
        $reflectionClass = new \ReflectionClass($className);
693
694 3
        if ( ! $reflectionClass->implementsInterface(ObjectRepository::class)) {
695 1
            throw ORMException::invalidEntityRepository($className);
696
        }
697
698 2
        $this->_attributes['defaultRepositoryClassName'] = $className;
699 2
    }
700
701
    /**
702
     * Get default repository class.
703
     *
704
     * @since 2.2
705
     *
706
     * @return string
707
     */
708 150
    public function getDefaultRepositoryClassName()
709
    {
710 150
        return isset($this->_attributes['defaultRepositoryClassName'])
711 2
            ? $this->_attributes['defaultRepositoryClassName']
712 150
            : EntityRepository::class;
713
    }
714
715
    /**
716
     * Sets naming strategy.
717
     *
718
     * @since 2.3
719
     *
720
     * @param NamingStrategy $namingStrategy
721
     *
722
     * @return void
723
     */
724 7
    public function setNamingStrategy(NamingStrategy $namingStrategy)
725
    {
726 7
        $this->_attributes['namingStrategy'] = $namingStrategy;
727 7
    }
728
729
    /**
730
     * Gets naming strategy..
731
     *
732
     * @since 2.3
733
     *
734
     * @return NamingStrategy
735
     */
736 449
    public function getNamingStrategy()
737
    {
738 449
        if ( ! isset($this->_attributes['namingStrategy'])) {
739 449
            $this->_attributes['namingStrategy'] = new DefaultNamingStrategy();
740
        }
741
742 449
        return $this->_attributes['namingStrategy'];
743
    }
744
745
    /**
746
     * Sets quote strategy.
747
     *
748
     * @since 2.3
749
     *
750
     * @param \Doctrine\ORM\Mapping\QuoteStrategy $quoteStrategy
751
     *
752
     * @return void
753
     */
754 2
    public function setQuoteStrategy(QuoteStrategy $quoteStrategy)
755
    {
756 2
        $this->_attributes['quoteStrategy'] = $quoteStrategy;
757 2
    }
758
759
    /**
760
     * Gets quote strategy.
761
     *
762
     * @since 2.3
763
     *
764
     * @return \Doctrine\ORM\Mapping\QuoteStrategy
765
     */
766 1637
    public function getQuoteStrategy()
767
    {
768 1637
        if ( ! isset($this->_attributes['quoteStrategy'])) {
769 1637
            $this->_attributes['quoteStrategy'] = new DefaultQuoteStrategy();
770
        }
771
772 1637
        return $this->_attributes['quoteStrategy'];
773
    }
774
775
    /**
776
     * Set the entity listener resolver.
777
     *
778
     * @since 2.4
779
     * @param \Doctrine\ORM\Mapping\EntityListenerResolver $resolver
780
     */
781 1
    public function setEntityListenerResolver(EntityListenerResolver $resolver)
782
    {
783 1
        $this->_attributes['entityListenerResolver'] = $resolver;
784 1
    }
785
786
    /**
787
     * Get the entity listener resolver.
788
     *
789
     * @since 2.4
790
     * @return \Doctrine\ORM\Mapping\EntityListenerResolver
791
     */
792 2384
    public function getEntityListenerResolver()
793
    {
794 2384
        if ( ! isset($this->_attributes['entityListenerResolver'])) {
795 2384
            $this->_attributes['entityListenerResolver'] = new DefaultEntityListenerResolver();
796
        }
797
798 2384
        return $this->_attributes['entityListenerResolver'];
799
    }
800
801
    /**
802
     * Set the entity repository factory.
803
     *
804
     * @since 2.4
805
     * @param \Doctrine\ORM\Repository\RepositoryFactory $repositoryFactory
806
     */
807
    public function setRepositoryFactory(RepositoryFactory $repositoryFactory)
808
    {
809
        $this->_attributes['repositoryFactory'] = $repositoryFactory;
810
    }
811
812
    /**
813
     * Get the entity repository factory.
814
     *
815
     * @since 2.4
816
     * @return \Doctrine\ORM\Repository\RepositoryFactory
817
     */
818 2383
    public function getRepositoryFactory()
819
    {
820 2383
        return isset($this->_attributes['repositoryFactory'])
821
            ? $this->_attributes['repositoryFactory']
822 2383
            : new DefaultRepositoryFactory();
823
    }
824
825
    /**
826
     * @since 2.5
827
     *
828
     * @return boolean
829
     */
830 2384
    public function isSecondLevelCacheEnabled()
831
    {
832 2384
        return isset($this->_attributes['isSecondLevelCacheEnabled'])
833 282
            ? $this->_attributes['isSecondLevelCacheEnabled']
834 2384
            : false;
835
    }
836
837
    /**
838
     * @since 2.5
839
     *
840
     * @param boolean $flag
841
     *
842
     * @return void
843
     */
844 282
    public function setSecondLevelCacheEnabled($flag = true)
845
    {
846 282
        $this->_attributes['isSecondLevelCacheEnabled'] = (boolean) $flag;
847 282
    }
848
849
    /**
850
     * @since 2.5
851
     *
852
     * @param \Doctrine\ORM\Cache\CacheConfiguration $cacheConfig
853
     *
854
     * @return void
855
     */
856 283
    public function setSecondLevelCacheConfiguration(CacheConfiguration $cacheConfig)
857
    {
858 283
        $this->_attributes['secondLevelCacheConfiguration'] = $cacheConfig;
859 283
    }
860
861
    /**
862
     * @since 2.5
863
     *
864
     * @return  \Doctrine\ORM\Cache\CacheConfiguration|null
865
     */
866 283
    public function getSecondLevelCacheConfiguration()
867
    {
868 283
        if ( ! isset($this->_attributes['secondLevelCacheConfiguration']) && $this->isSecondLevelCacheEnabled()) {
869
            $this->_attributes['secondLevelCacheConfiguration'] = new CacheConfiguration();
870
        }
871
872 283
        return isset($this->_attributes['secondLevelCacheConfiguration'])
873 283
            ? $this->_attributes['secondLevelCacheConfiguration']
874 283
            : null;
875
    }
876
877
    /**
878
     * Returns query hints, which will be applied to every query in application
879
     *
880
     * @since 2.5
881
     *
882
     * @return array
883
     */
884 954
    public function getDefaultQueryHints()
885
    {
886 954
        return isset($this->_attributes['defaultQueryHints']) ? $this->_attributes['defaultQueryHints'] : [];
887
    }
888
889
    /**
890
     * Sets array of query hints, which will be applied to every query in application
891
     *
892
     * @since 2.5
893
     *
894
     * @param array $defaultQueryHints
895
     */
896 1
    public function setDefaultQueryHints(array $defaultQueryHints)
897
    {
898 1
        $this->_attributes['defaultQueryHints'] = $defaultQueryHints;
899 1
    }
900
901
    /**
902
     * Gets the value of a default query hint. If the hint name is not recognized, FALSE is returned.
903
     *
904
     * @since 2.5
905
     *
906
     * @param string $name The name of the hint.
907
     *
908
     * @return mixed The value of the hint or FALSE, if the hint name is not recognized.
909
     */
910
    public function getDefaultQueryHint($name)
911
    {
912
        return isset($this->_attributes['defaultQueryHints'][$name])
913
            ? $this->_attributes['defaultQueryHints'][$name]
914
            : false;
915
    }
916
917
    /**
918
     * Sets a default query hint. If the hint name is not recognized, it is silently ignored.
919
     *
920
     * @since 2.5
921
     *
922
     * @param string $name  The name of the hint.
923
     * @param mixed  $value The value of the hint.
924
     */
925 1
    public function setDefaultQueryHint($name, $value)
926
    {
927 1
        $this->_attributes['defaultQueryHints'][$name] = $value;
928 1
    }
929
}
930