Completed
Pull Request — master (#527)
by
unknown
10:34
created

Configuration::setSchemaFilter()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 0
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 2
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 = [];
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 = [];
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 = [];
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 = [];
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 = [];
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 = [];
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 = [];
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 = [];
148
149
    /**
150
     * Naming strategy or name of the naming strategy service to be set in ORM
151
     * configuration (if any)
152
     *
153
     * @var string|null|NamingStrategy
154
     */
155
    protected $namingStrategy;
156
157
    /**
158
     * Quote strategy or name of the quote strategy service to be set in ORM
159
     * configuration (if any)
160
     *
161
     * @var string|null|QuoteStrategy
162
     */
163
    protected $quoteStrategy;
164
165
    /**
166
     * Default repository class
167
     *
168
     * @var string|null
169
     */
170
    protected $defaultRepositoryClassName;
171
172
    /**
173
     * Repository factory or name of the repository factory service to be set in ORM
174
     * configuration (if any)
175
     *
176
     * @var string|null|RepositoryFactory
177
     */
178
    protected $repositoryFactory;
179
180
    /**
181
     * Class name of MetaData factory to be set in ORM.
182
     * The entityManager will create a new instance on construction.
183
     *
184
     * @var string
185
     */
186
    protected $classMetadataFactoryName;
187
188
    /**
189
     * Entity listener resolver or service name of the entity listener resolver
190
     * to be set in ORM configuration (if any)
191
     *
192
     * @link http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/events.html
193
     * @var  string|null|EntityListenerResolver
194
     */
195
    protected $entityListenerResolver;
196
197
    /**
198
     * Configuration for second level cache
199
     *
200
     * @link http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/second-level-cache.html
201
     * @var SecondLevelCacheConfiguration|null
202
     */
203
    protected $secondLevelCache;
204
    
205
    /**
206
     * Configuration for schema filter
207
     *
208
     * @var string|null
209 72
     */
210
    protected $schemaFilter;
211 72
212
    /**
213 72
     * @param  array $datetimeFunctions
214
     * @return self
215
     */
216
    public function setDatetimeFunctions($datetimeFunctions)
217
    {
218
        $this->datetimeFunctions = $datetimeFunctions;
219 88
220
        return $this;
221 88
    }
222
223
    /**
224
     * @return array
225
     */
226
    public function getDatetimeFunctions()
227
    {
228 72
        return $this->datetimeFunctions;
229
    }
230 72
231
    /**
232 72
     * @param  string $driver
233
     * @return self
234
     */
235
    public function setDriver($driver)
236
    {
237
        $this->driver = $driver;
238 88
239
        return $this;
240 88
    }
241
242
    /**
243
     * @return string
244
     */
245
    public function getDriver()
246
    {
247
        return "doctrine.driver.{$this->driver}";
248
    }
249
250
    /**
251
     * @param  array $entityNamespaces
252
     * @return self
253
     */
254
    public function setEntityNamespaces($entityNamespaces)
255
    {
256
        $this->entityNamespaces = $entityNamespaces;
257 88
258
        return $this;
259 88
    }
260
261
    /**
262
     * @return array
263
     */
264
    public function getEntityNamespaces()
265
    {
266 72
        return $this->entityNamespaces;
267
    }
268 72
269
    /**
270 72
     * @param  boolean $generateProxies
271
     * @return self
272
     */
273
    public function setGenerateProxies($generateProxies)
274
    {
275
        $this->generateProxies = $generateProxies;
276 88
277
        return $this;
278 88
    }
279
280
    /**
281
     * @return boolean
282
     */
283
    public function getGenerateProxies()
284
    {
285 72
        return $this->generateProxies;
286
    }
287 72
288
    /**
289 72
     * @param  string $metadataCache
290
     * @return self
291
     */
292
    public function setMetadataCache($metadataCache)
293
    {
294
        $this->metadataCache = $metadataCache;
295 88
296
        return $this;
297 88
    }
298
299
    /**
300
     * @return string
301
     */
302
    public function getMetadataCache()
303
    {
304 73
        return "doctrine.cache.{$this->metadataCache}";
305
    }
306 73
307
    /**
308 73
     * @param  string $resultCache
309
     * @return self
310
     */
311
    public function setResultCache($resultCache)
312
    {
313
        $this->resultCache = $resultCache;
314 88
315
        return $this;
316 88
    }
317
318
    /**
319
     * @return string
320
     */
321
    public function getResultCache()
322
    {
323 74
        return "doctrine.cache.{$this->resultCache}";
324
    }
325 74
326
    /**
327 74
     * @param  string $hydrationCache
328
     * @return self
329
     */
330
    public function setHydrationCache($hydrationCache)
331
    {
332
        $this->hydrationCache = $hydrationCache;
333 88
334
        return $this;
335 88
    }
336
337
    /**
338
     * @return string
339
     */
340
    public function getHydrationCache()
341
    {
342
        return "doctrine.cache.{$this->hydrationCache}";
343
    }
344
345
    /**
346
     * @param  array $namedNativeQueries
347
     * @return self
348
     */
349
    public function setNamedNativeQueries($namedNativeQueries)
350
    {
351
        $this->namedNativeQueries = $namedNativeQueries;
352 88
353
        return $this;
354 88
    }
355
356
    /**
357
     * @return array
358
     */
359
    public function getNamedNativeQueries()
360
    {
361
        return $this->namedNativeQueries;
362
    }
363
364
    /**
365
     * @param  array $namedQueries
366
     * @return self
367
     */
368
    public function setNamedQueries($namedQueries)
369
    {
370
        $this->namedQueries = $namedQueries;
371 88
372
        return $this;
373 88
    }
374
375
    /**
376
     * @return array
377
     */
378
    public function getNamedQueries()
379
    {
380 72
        return $this->namedQueries;
381
    }
382 72
383
    /**
384 72
     * @param  array $numericFunctions
385
     * @return self
386
     */
387
    public function setNumericFunctions($numericFunctions)
388
    {
389
        $this->numericFunctions = $numericFunctions;
390 88
391
        return $this;
392 88
    }
393
394
    /**
395
     * @return array
396
     */
397
    public function getNumericFunctions()
398
    {
399
        return $this->numericFunctions;
400 72
    }
401
402 72
    /**
403
     *
404 72
     * @param  array $filters
405
     * @return self
406
     */
407
    public function setFilters($filters)
408
    {
409
        $this->filters = $filters;
410
411 88
        return $this;
412
    }
413 88
414
    /**
415
     *
416
     * @return array
417
     */
418
    public function getFilters()
419
    {
420 72
        return $this->filters;
421
    }
422 72
423
    /**
424 72
     * @param  string $proxyDir
425
     * @return self
426
     */
427
    public function setProxyDir($proxyDir)
428
    {
429
        $this->proxyDir = $proxyDir;
430 88
431
        return $this;
432 88
    }
433
434
    /**
435
     * @return string
436
     */
437
    public function getProxyDir()
438
    {
439 72
        return $this->proxyDir;
440
    }
441 72
442
    /**
443 72
     * @param  string $proxyNamespace
444
     * @return self
445
     */
446
    public function setProxyNamespace($proxyNamespace)
447
    {
448
        $this->proxyNamespace = $proxyNamespace;
449 88
450
        return $this;
451 88
    }
452
453
    /**
454
     * @return string
455
     */
456
    public function getProxyNamespace()
457
    {
458 72
        return $this->proxyNamespace;
459
    }
460 72
461
    /**
462 72
     * @param  string $queryCache
463
     * @return self
464
     */
465
    public function setQueryCache($queryCache)
466
    {
467
        $this->queryCache = $queryCache;
468 88
469
        return $this;
470 88
    }
471
472
    /**
473
     * @return string
474
     */
475
    public function getQueryCache()
476
    {
477 72
        return "doctrine.cache.{$this->queryCache}";
478
    }
479 72
480
    /**
481 72
     * @param  array $stringFunctions
482
     * @return self
483
     */
484
    public function setStringFunctions($stringFunctions)
485
    {
486
        $this->stringFunctions = $stringFunctions;
487 88
488
        return $this;
489 88
    }
490
491
    /**
492
     * @return array
493
     */
494
    public function getStringFunctions()
495
    {
496
        return $this->stringFunctions;
497
    }
498
499
    /**
500
     * @param  array $modes
501
     * @return self
502
     */
503
    public function setCustomHydrationModes($modes)
504
    {
505
        $this->customHydrationModes = $modes;
506 88
507
        return $this;
508 88
    }
509
510
    /**
511
     * @return array
512
     */
513
    public function getCustomHydrationModes()
514
    {
515
        return $this->customHydrationModes;
516 4
    }
517
518 4
    /**
519 4
     * @param  string|null|NamingStrategy $namingStrategy
520 4
     * @return self
521 4
     * @throws InvalidArgumentException   when the provided naming strategy does not fit the expected type
522 4
     */
523
    public function setNamingStrategy($namingStrategy)
524 4
    {
525
        if (null === $namingStrategy
526
            || is_string($namingStrategy)
527 1
            || $namingStrategy instanceof NamingStrategy
528 1
        ) {
529
            $this->namingStrategy = $namingStrategy;
530 1
531 1
            return $this;
532 1
        }
533 1
534
        throw new InvalidArgumentException(
535
            sprintf(
536
                'namingStrategy must be either a string, a Doctrine\ORM\Mapping\NamingStrategy '
537
                . 'instance or null, %s given',
538
                is_object($namingStrategy) ? get_class($namingStrategy) : gettype($namingStrategy)
539 89
            )
540
        );
541 89
    }
542
543
    /**
544
     * @return string|null|NamingStrategy
545
     */
546
    public function getNamingStrategy()
547
    {
548
        return $this->namingStrategy;
549 4
    }
550
551 4
    /**
552 4
     * @param  string|null|QuoteStrategy $quoteStrategy
553 4
     * @return self
554 4
     * @throws InvalidArgumentException   when the provided quote strategy does not fit the expected type
555 4
     */
556
    public function setQuoteStrategy($quoteStrategy)
557 4
    {
558
        if (null === $quoteStrategy
559
            || is_string($quoteStrategy)
560 1
            || $quoteStrategy instanceof QuoteStrategy
561 1
        ) {
562
            $this->quoteStrategy = $quoteStrategy;
563 1
564 1
            return $this;
565 1
        }
566 1
567
        throw new InvalidArgumentException(
568
            sprintf(
569
                'quoteStrategy must be either a string, a Doctrine\ORM\Mapping\QuoteStrategy '
570
                . 'instance or null, %s given',
571
                is_object($quoteStrategy) ? get_class($quoteStrategy) : gettype($quoteStrategy)
572 88
            )
573
        );
574 88
    }
575
576
    /**
577
     * @return string|null|QuoteStrategy
578
     */
579
    public function getQuoteStrategy()
580
    {
581
        return $this->quoteStrategy;
582 1
    }
583
584 1
    /**
585 1
     * @param  string|null|RepositoryFactory $repositoryFactory
586 1
     * @return self
587 1
     * @throws InvalidArgumentException   when the provided repository factory does not fit the expected type
588 1
     */
589
    public function setRepositoryFactory($repositoryFactory)
590 1
    {
591
        if (null === $repositoryFactory
592
            || is_string($repositoryFactory)
593 1
            || $repositoryFactory instanceof RepositoryFactory
594 1
        ) {
595
            $this->repositoryFactory = $repositoryFactory;
596 1
597 1
            return $this;
598 1
        }
599 1
600
        throw new InvalidArgumentException(
601
            sprintf(
602
                'repositoryFactory must be either a string, a Doctrine\ORM\Repository\RepositoryFactory '
603
                . 'instance or null, %s given',
604
                is_object($repositoryFactory) ? get_class($repositoryFactory) : gettype($repositoryFactory)
605 87
            )
606
        );
607 87
    }
608
609
    /**
610
     * @return string|null|RepositoryFactory
611
     */
612
    public function getRepositoryFactory()
613
    {
614
        return $this->repositoryFactory;
615
    }
616
617 1
    /**
618
     * Set the metadata factory class name to use
619 1
     *
620 1
     * @see \Doctrine\ORM\Configuration::setClassMetadataFactoryName()
621
     *
622
     * @param string $factoryName
623
     */
624
    public function setClassMetadataFactoryName($factoryName)
625 88
    {
626
        $this->classMetadataFactoryName = (string) $factoryName;
627 88
    }
628
629
    /**
630
     * @return string
631
     */
632
    public function getClassMetadataFactoryName()
633
    {
634
        return $this->classMetadataFactoryName;
635
    }
636 3
637
    /**
638 3
     * @param  string|null|EntityListenerResolver $entityListenerResolver
639 3
     * @return self
640 3
     * @throws InvalidArgumentException           When the provided entity listener resolver
641 3
     *                                            does not fit the expected type
642 3
     */
643
    public function setEntityListenerResolver($entityListenerResolver)
644 3
    {
645
        if (null === $entityListenerResolver
646
            || $entityListenerResolver instanceof EntityListenerResolver
647 1
            || is_string($entityListenerResolver)
648
        ) {
649 1
            $this->entityListenerResolver = $entityListenerResolver;
650 1
651 1
            return $this;
652
        }
653
654
        throw new InvalidArgumentException(sprintf(
655
            'entityListenerResolver must be either a string, a Doctrine\ORM\Mapping\EntityListenerResolver '
656
            . 'instance or null, %s given',
657 87
            is_object($entityListenerResolver) ? get_class($entityListenerResolver) : gettype($entityListenerResolver)
658
        ));
659 87
    }
660
661
    /**
662
     * @return string|null|EntityListenerResolver
663
     */
664
    public function getEntityListenerResolver()
665
    {
666 73
        return $this->entityListenerResolver;
667
    }
668 73
669 73
    /**
670
     * @param  array $secondLevelCache
671
     * @return void
672
     */
673
    public function setSecondLevelCache(array $secondLevelCache)
674 86
    {
675
        $this->secondLevelCache = new SecondLevelCacheConfiguration($secondLevelCache);
676 86
    }
677
678
    /**
679
     * @return SecondLevelCacheConfiguration
680
     */
681
    public function getSecondLevelCache()
682
    {
683
        return $this->secondLevelCache ?: new SecondLevelCacheConfiguration();
684
    }
685 73
    
686
    /**
687 73
     * @param  string $schemaFilter
688 73
     * @return void
689
     */
690
    public function setSchemaFilter($schemaFilter)
691
    {
692
        $this->schemaFilter = $schemaFilter;
693
    }
694
695 86
    /**
696
     * @return string|null
697 86
     */
698
    public function getSchemaFilter()
699
    {
700
        return $this->schemaFilter;
701
    }
702
703
    /**
704
     * Sets default repository class.
705
     *
706
     * @param  string $className
707
     * @return void
708
     */
709
    public function setDefaultRepositoryClassName($className)
710
    {
711
        $this->defaultRepositoryClassName = (string) $className;
712
    }
713
714
    /**
715
     * Get default repository class name.
716
     *
717
     * @return string|null
718
     */
719
    public function getDefaultRepositoryClassName()
720
    {
721
        return $this->defaultRepositoryClassName;
722
    }
723
}
724