Completed
Push — master ( 50808e...33b518 )
by Gianluca
05:07
created

Configuration::getGenerateProxies()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace DoctrineORMModule\Options;
4
5
use Doctrine\ORM\Mapping\EntityListenerResolver;
6
use Doctrine\ORM\Mapping\NamingStrategy;
7
use Doctrine\ORM\Mapping\QuoteStrategy;
8
use Doctrine\ORM\Repository\RepositoryFactory;
9
use Zend\Stdlib\Exception\InvalidArgumentException;
10
11
/**
12
 * Configuration options for an ORM Configuration
13
 *
14
 * @license MIT
15
 * @link    http://www.doctrine-project.org/
16
 * @author  Kyle Spraggs <[email protected]>
17
 * @author  Marco Pivetta <[email protected]>
18
 */
19
class Configuration extends DBALConfiguration
20
{
21
    /**
22
     * Set the cache key for the metadata cache. Cache key
23
     * is assembled as "doctrine.cache.{key}" and pulled from
24
     * service locator.
25
     *
26
     * @var string
27
     */
28
    protected $metadataCache = 'array';
29
30
    /**
31
     * Set the cache key for the query cache. Cache key
32
     * is assembled as "doctrine.cache.{key}" and pulled from
33
     * service locator.
34
     *
35
     * @var string
36
     */
37
    protected $queryCache = 'array';
38
39
    /**
40
     * Set the cache key for the result cache. Cache key
41
     * is assembled as "doctrine.cache.{key}" and pulled from
42
     * service locator.
43
     *
44
     * @var string
45
     */
46
    protected $resultCache = 'array';
47
48
    /**
49
     * Set the cache key for the hydration cache. Cache key
50
     * is assembled as "doctrine.cache.{key}" and pulled from
51
     * service locator.
52
     *
53
     * @var string
54
     */
55
    protected $hydrationCache = 'array';
56
57
    /**
58
     * Set the driver key for the metadata driver. Driver key
59
     * is assembled as "doctrine.driver.{key}" and pulled from
60
     * service locator.
61
     *
62
     * @var string
63
     */
64
    protected $driver = 'orm_default';
65
66
    /**
67
     * Automatic generation of proxies (disable for production!)
68
     *
69
     * @var bool
70
     */
71
    protected $generateProxies = true;
72
73
    /**
74
     * Proxy directory.
75
     *
76
     * @var string
77
     */
78
    protected $proxyDir = 'data';
79
80
    /**
81
     * Proxy namespace.
82
     *
83
     * @var string
84
     */
85
    protected $proxyNamespace = 'DoctrineORMModule\Proxy';
86
87
    /**
88
     * Entity alias map.
89
     *
90
     * @var array
91
     */
92
    protected $entityNamespaces = array();
93
94
    /**
95
     * Keys must be function names and values the FQCN of the implementing class.
96
     * The function names will be case-insensitive in DQL.
97
     *
98
     * @var array
99
     */
100
    protected $datetimeFunctions = array();
101
102
    /**
103
     * Keys must be function names and values the FQCN of the implementing class.
104
     * The function names will be case-insensitive in DQL.
105
     *
106
     * @var array
107
     */
108
    protected $stringFunctions = array();
109
110
    /**
111
     * Keys must be function names and values the FQCN of the implementing class.
112
     * The function names will be case-insensitive in DQL.
113
     *
114
     * @var array
115
     */
116
    protected $numericFunctions = array();
117
118
    /**
119
     * Keys must be the name of the custom filter and the value must be
120
     * the class name for the custom filter.
121
     *
122
     * @var array
123
     */
124
    protected $filters = array();
125
126
    /**
127
     * Keys must be the name of the query and values the DQL query string.
128
     *
129
     * @var array
130
     */
131
    protected $namedQueries = array();
132
133
    /**
134
     * Keys must be the name of the query and the value is an array containing
135
     * the keys 'sql' for native SQL query string and 'rsm' for the Query\ResultSetMapping.
136
     *
137
     * @var array
138
     */
139
    protected $namedNativeQueries = array();
140
141
    /**
142
     * Keys must be the name of the custom hydration method and the value must be
143
     * the class name for the custom hydrator
144
     *
145
     * @var array
146
     */
147
    protected $customHydrationModes = array();
148
149
    /**
150
     * Keys must be the name of the custom query hint and the value must be
151
     * the class name for the custom walker
152
     *
153
     * @var array
154
     */
155
    protected $defaultQueryHints = array();
156
157
    /**
158
     * Naming strategy or name of the naming strategy service to be set in ORM
159
     * configuration (if any)
160
     *
161
     * @var string|null|NamingStrategy
162
     */
163
    protected $namingStrategy;
164
165
    /**
166
     * Quote strategy or name of the quote strategy service to be set in ORM
167
     * configuration (if any)
168
     *
169
     * @var string|null|QuoteStrategy
170
     */
171
    protected $quoteStrategy;
172
173
    /**
174
     * Default repository class
175
     *
176
     * @var string|null
177
     */
178
    protected $defaultRepositoryClassName;
179
180
    /**
181
     * Repository factory or name of the repository factory service to be set in ORM
182
     * configuration (if any)
183
     *
184
     * @var string|null|RepositoryFactory
185
     */
186
    protected $repositoryFactory;
187
188
    /**
189
     * Class name of MetaData factory to be set in ORM.
190
     * The entityManager will create a new instance on construction.
191
     *
192
     * @var string
193
     */
194
    protected $classMetadataFactoryName;
195
196
    /**
197
     * Entity listener resolver or service name of the entity listener resolver
198
     * to be set in ORM configuration (if any)
199
     *
200
     * @link http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/events.html
201
     * @var  string|null|EntityListenerResolver
202
     */
203
    protected $entityListenerResolver;
204
205
    /**
206
     * Configuration for second level cache
207
     *
208
     * @link http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/second-level-cache.html
209
     * @var SecondLevelCacheConfiguration|null
210
     */
211
    protected $secondLevelCache;
212
213
    /**
214
     * @param  array $datetimeFunctions
215
     * @return self
216
     */
217 56
    public function setDatetimeFunctions($datetimeFunctions)
218
    {
219 56
        $this->datetimeFunctions = $datetimeFunctions;
220
221 56
        return $this;
222
    }
223
224
    /**
225
     * @return array
226
     */
227 72
    public function getDatetimeFunctions()
228
    {
229 72
        return $this->datetimeFunctions;
230
    }
231
232
    /**
233
     * @param  string $driver
234
     * @return self
235
     */
236 56
    public function setDriver($driver)
237
    {
238 56
        $this->driver = $driver;
239
240 56
        return $this;
241
    }
242
243
    /**
244
     * @return string
245
     */
246 72
    public function getDriver()
247
    {
248 72
        return "doctrine.driver.{$this->driver}";
249
    }
250
251
    /**
252
     * @param  array $entityNamespaces
253
     * @return self
254
     */
255
    public function setEntityNamespaces($entityNamespaces)
256
    {
257
        $this->entityNamespaces = $entityNamespaces;
258
259
        return $this;
260
    }
261
262
    /**
263
     * @return array
264
     */
265 72
    public function getEntityNamespaces()
266
    {
267 72
        return $this->entityNamespaces;
268
    }
269
270
    /**
271
     * @param  boolean $generateProxies
272
     * @return self
273
     */
274 56
    public function setGenerateProxies($generateProxies)
275
    {
276 56
        $this->generateProxies = $generateProxies;
277
278 56
        return $this;
279
    }
280
281
    /**
282
     * @return boolean
283
     */
284 72
    public function getGenerateProxies()
285
    {
286 72
        return $this->generateProxies;
287
    }
288
289
    /**
290
     * @param  string $metadataCache
291
     * @return self
292
     */
293 56
    public function setMetadataCache($metadataCache)
294
    {
295 56
        $this->metadataCache = $metadataCache;
296
297 56
        return $this;
298
    }
299
300
    /**
301
     * @return string
302
     */
303 72
    public function getMetadataCache()
304
    {
305 72
        return "doctrine.cache.{$this->metadataCache}";
306
    }
307
308
    /**
309
     * @param  string $resultCache
310
     * @return self
311
     */
312 57
    public function setResultCache($resultCache)
313
    {
314 57
        $this->resultCache = $resultCache;
315
316 57
        return $this;
317
    }
318
319
    /**
320
     * @return string
321
     */
322 72
    public function getResultCache()
323
    {
324 72
        return "doctrine.cache.{$this->resultCache}";
325
    }
326
327
    /**
328
     * @param  string $hydrationCache
329
     * @return self
330
     */
331 58
    public function setHydrationCache($hydrationCache)
332
    {
333 58
        $this->hydrationCache = $hydrationCache;
334
335 58
        return $this;
336
    }
337
338
    /**
339
     * @return string
340
     */
341 72
    public function getHydrationCache()
342
    {
343 72
        return "doctrine.cache.{$this->hydrationCache}";
344
    }
345
346
    /**
347
     * @param  array $namedNativeQueries
348
     * @return self
349
     */
350
    public function setNamedNativeQueries($namedNativeQueries)
351
    {
352
        $this->namedNativeQueries = $namedNativeQueries;
353
354
        return $this;
355
    }
356
357
    /**
358
     * @return array
359
     */
360 72
    public function getNamedNativeQueries()
361
    {
362 72
        return $this->namedNativeQueries;
363
    }
364
365
    /**
366
     * @param  array $namedQueries
367
     * @return self
368
     */
369
    public function setNamedQueries($namedQueries)
370
    {
371
        $this->namedQueries = $namedQueries;
372
373
        return $this;
374
    }
375
376
    /**
377
     * @return array
378
     */
379 72
    public function getNamedQueries()
380
    {
381 72
        return $this->namedQueries;
382
    }
383
384
    /**
385
     * @param  array $numericFunctions
386
     * @return self
387
     */
388 56
    public function setNumericFunctions($numericFunctions)
389
    {
390 56
        $this->numericFunctions = $numericFunctions;
391
392 56
        return $this;
393
    }
394
395
    /**
396
     * @return array
397
     */
398 72
    public function getNumericFunctions()
399
    {
400 72
        return $this->numericFunctions;
401
    }
402
403
    /**
404
     *
405
     * @param  array $filters
406
     * @return self
407
     */
408 56
    public function setFilters($filters)
409
    {
410 56
        $this->filters = $filters;
411
412 56
        return $this;
413
    }
414
415
    /**
416
     *
417
     * @return array
418
     */
419 72
    public function getFilters()
420
    {
421 72
        return $this->filters;
422
    }
423
424
    /**
425
     * @param  string $proxyDir
426
     * @return self
427
     */
428 56
    public function setProxyDir($proxyDir)
429
    {
430 56
        $this->proxyDir = $proxyDir;
431
432 56
        return $this;
433
    }
434
435
    /**
436
     * @return string
437
     */
438 72
    public function getProxyDir()
439
    {
440 72
        return $this->proxyDir;
441
    }
442
443
    /**
444
     * @param  string $proxyNamespace
445
     * @return self
446
     */
447 56
    public function setProxyNamespace($proxyNamespace)
448
    {
449 56
        $this->proxyNamespace = $proxyNamespace;
450
451 56
        return $this;
452
    }
453
454
    /**
455
     * @return string
456
     */
457 72
    public function getProxyNamespace()
458
    {
459 72
        return $this->proxyNamespace;
460
    }
461
462
    /**
463
     * @param  string $queryCache
464
     * @return self
465
     */
466 56
    public function setQueryCache($queryCache)
467
    {
468 56
        $this->queryCache = $queryCache;
469
470 56
        return $this;
471
    }
472
473
    /**
474
     * @return string
475
     */
476 72
    public function getQueryCache()
477
    {
478 72
        return "doctrine.cache.{$this->queryCache}";
479
    }
480
481
    /**
482
     * @param  array $stringFunctions
483
     * @return self
484
     */
485 56
    public function setStringFunctions($stringFunctions)
486
    {
487 56
        $this->stringFunctions = $stringFunctions;
488
489 56
        return $this;
490
    }
491
492
    /**
493
     * @return array
494
     */
495 72
    public function getStringFunctions()
496
    {
497 72
        return $this->stringFunctions;
498
    }
499
500
    /**
501
     * @param  array $modes
502
     * @return self
503
     */
504
    public function setCustomHydrationModes($modes)
505
    {
506
        $this->customHydrationModes = $modes;
507
508
        return $this;
509
    }
510
511
    /**
512
     * @return array
513
     */
514 72
    public function getCustomHydrationModes()
515
    {
516 72
        return $this->customHydrationModes;
517
    }
518
519
    /**
520
     * @param  string|null|NamingStrategy $namingStrategy
521
     * @return self
522
     * @throws InvalidArgumentException   when the provided naming strategy does not fit the expected type
523
     */
524 4
    public function setNamingStrategy($namingStrategy)
525
    {
526 4
        if (null === $namingStrategy
527 4
            || is_string($namingStrategy)
528 4
            || $namingStrategy instanceof NamingStrategy
529 4
        ) {
530 4
            $this->namingStrategy = $namingStrategy;
531
532 4
            return $this;
533
        }
534
535 1
        throw new InvalidArgumentException(
536 1
            sprintf(
537
                'namingStrategy must be either a string, a Doctrine\ORM\Mapping\NamingStrategy '
538 1
                . 'instance or null, %s given',
539 1
                is_object($namingStrategy) ? get_class($namingStrategy) : gettype($namingStrategy)
540 1
            )
541 1
        );
542
    }
543
544
    /**
545
     * @return string|null|NamingStrategy
546
     */
547 73
    public function getNamingStrategy()
548
    {
549 73
        return $this->namingStrategy;
550
    }
551
552
    /**
553
     * @param  string|null|QuoteStrategy $quoteStrategy
554
     * @return self
555
     * @throws InvalidArgumentException   when the provided quote strategy does not fit the expected type
556
     */
557 4
    public function setQuoteStrategy($quoteStrategy)
558
    {
559 4
        if (null === $quoteStrategy
560 4
            || is_string($quoteStrategy)
561 4
            || $quoteStrategy instanceof QuoteStrategy
562 4
        ) {
563 4
            $this->quoteStrategy = $quoteStrategy;
564
565 4
            return $this;
566
        }
567
568 1
        throw new InvalidArgumentException(
569 1
            sprintf(
570
                'quoteStrategy must be either a string, a Doctrine\ORM\Mapping\QuoteStrategy '
571 1
                . 'instance or null, %s given',
572 1
                is_object($quoteStrategy) ? get_class($quoteStrategy) : gettype($quoteStrategy)
573 1
            )
574 1
        );
575
    }
576
577
    /**
578
     * @return string|null|QuoteStrategy
579
     */
580 72
    public function getQuoteStrategy()
581
    {
582 72
        return $this->quoteStrategy;
583
    }
584
585
    /**
586
     * @param  string|null|RepositoryFactory $repositoryFactory
587
     * @return self
588
     * @throws InvalidArgumentException   when the provided repository factory does not fit the expected type
589
     */
590 1
    public function setRepositoryFactory($repositoryFactory)
591
    {
592 1
        if (null === $repositoryFactory
593 1
            || is_string($repositoryFactory)
594 1
            || $repositoryFactory instanceof RepositoryFactory
595 1
        ) {
596 1
            $this->repositoryFactory = $repositoryFactory;
597
598 1
            return $this;
599
        }
600
601 1
        throw new InvalidArgumentException(
602 1
            sprintf(
603
                'repositoryFactory must be either a string, a Doctrine\ORM\Repository\RepositoryFactory '
604 1
                . 'instance or null, %s given',
605 1
                is_object($repositoryFactory) ? get_class($repositoryFactory) : gettype($repositoryFactory)
606 1
            )
607 1
        );
608
    }
609
610
    /**
611
     * @return string|null|RepositoryFactory
612
     */
613 70
    public function getRepositoryFactory()
614
    {
615 70
        return $this->repositoryFactory;
616
    }
617
618
    /**
619
     * Set the metadata factory class name to use
620
     *
621
     * @see \Doctrine\ORM\Configuration::setClassMetadataFactoryName()
622
     *
623
     * @param string $factoryName
624
     */
625 1
    public function setClassMetadataFactoryName($factoryName)
626
    {
627 1
        $this->classMetadataFactoryName = (string) $factoryName;
628 1
    }
629
630
    /**
631
     * @return string
632
     */
633 72
    public function getClassMetadataFactoryName()
634
    {
635 72
        return $this->classMetadataFactoryName;
636
    }
637
638
    /**
639
     * @param  string|null|EntityListenerResolver $entityListenerResolver
640
     * @return self
641
     * @throws InvalidArgumentException           When the provided entity listener resolver
642
     *                                            does not fit the expected type
643
     */
644 3
    public function setEntityListenerResolver($entityListenerResolver)
645
    {
646 3
        if (null === $entityListenerResolver
647 3
            || $entityListenerResolver instanceof EntityListenerResolver
648 3
            || is_string($entityListenerResolver)
649 3
        ) {
650 3
            $this->entityListenerResolver = $entityListenerResolver;
651
652 3
            return $this;
653
        }
654
655 1
        throw new InvalidArgumentException(sprintf(
656
            'entityListenerResolver must be either a string, a Doctrine\ORM\Mapping\EntityListenerResolver '
657 1
            . 'instance or null, %s given',
658 1
            is_object($entityListenerResolver) ? get_class($entityListenerResolver) : gettype($entityListenerResolver)
659 1
        ));
660
    }
661
662
    /**
663
     * @return string|null|EntityListenerResolver
664
     */
665 70
    public function getEntityListenerResolver()
666
    {
667 70
        return $this->entityListenerResolver;
668
    }
669
670
    /**
671
     * @param  array $secondLevelCache
672
     * @return void
673
     */
674 57
    public function setSecondLevelCache(array $secondLevelCache)
675
    {
676 57
        $this->secondLevelCache = new SecondLevelCacheConfiguration($secondLevelCache);
677 57
    }
678
679
    /**
680
     * @return SecondLevelCacheConfiguration
681
     */
682 69
    public function getSecondLevelCache()
683
    {
684 69
        return $this->secondLevelCache ?: new SecondLevelCacheConfiguration();
685
    }
686
687
    /**
688
     * Sets default repository class.
689
     *
690
     * @param  string $className
691
     * @return void
692
     */
693 57
    public function setDefaultRepositoryClassName($className)
694
    {
695 57
        $this->defaultRepositoryClassName = (string) $className;
696 57
    }
697
698
    /**
699
     * Get default repository class name.
700
     *
701
     * @return string|null
702
     */
703 69
    public function getDefaultRepositoryClassName()
704
    {
705 69
        return $this->defaultRepositoryClassName;
706
    }
707
708
    /**
709
     * Get default query hints
710
     *
711
     * @return array
712
     */
713 73
    public function getDefaultQueryHints()
714
    {
715 73
        return $this->defaultQueryHints;
716
    }
717
718
    /**
719
     * Set default query hints
720
     *
721
     * @param array $defaultQueryHints
722
     */
723 57
    public function setDefaultQueryHints($defaultQueryHints)
724
    {
725 57
        $this->defaultQueryHints = $defaultQueryHints;
726 57
    }
727
}
728