Completed
Pull Request — master (#527)
by
unknown
14:10 queued 08:39
created

Configuration::setNumericFunctions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

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