Completed
Pull Request — master (#6085)
by Arjan
09:08
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
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
A getNamedNativeQuery() 0 8 2

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