-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
Copy pathConfiguration.php
665 lines (583 loc) · 20.6 KB
/
Configuration.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
<?php
declare(strict_types=1);
namespace Doctrine\ORM;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\ORM\Cache\CacheConfiguration;
use Doctrine\ORM\Exception\InvalidEntityRepository;
use Doctrine\ORM\Internal\Hydration\AbstractHydrator;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Mapping\ClassMetadataFactory;
use Doctrine\ORM\Mapping\DefaultEntityListenerResolver;
use Doctrine\ORM\Mapping\DefaultNamingStrategy;
use Doctrine\ORM\Mapping\DefaultQuoteStrategy;
use Doctrine\ORM\Mapping\EntityListenerResolver;
use Doctrine\ORM\Mapping\NamingStrategy;
use Doctrine\ORM\Mapping\QuoteStrategy;
use Doctrine\ORM\Mapping\TypedFieldMapper;
use Doctrine\ORM\Proxy\ProxyFactory;
use Doctrine\ORM\Query\AST\Functions\FunctionNode;
use Doctrine\ORM\Query\Filter\SQLFilter;
use Doctrine\ORM\Repository\DefaultRepositoryFactory;
use Doctrine\ORM\Repository\RepositoryFactory;
use Doctrine\Persistence\Mapping\Driver\MappingDriver;
use LogicException;
use Psr\Cache\CacheItemPoolInterface;
use function class_exists;
use function is_a;
use function strtolower;
use const PHP_VERSION_ID;
/**
* Configuration container for all configuration options of Doctrine.
* It combines all configuration options from DBAL & ORM.
*
* Internal note: When adding a new configuration option just write a getter/setter pair.
*/
class Configuration extends \Doctrine\DBAL\Configuration
{
/** @var mixed[] */
protected array $attributes = [];
/** @psalm-var array<class-string<AbstractPlatform>, ClassMetadata::GENERATOR_TYPE_*> */
private $identityGenerationPreferences = [];
/** @psalm-param array<class-string<AbstractPlatform>, ClassMetadata::GENERATOR_TYPE_*> $value */
public function setIdentityGenerationPreferences(array $value): void
{
$this->identityGenerationPreferences = $value;
}
/** @psalm-return array<class-string<AbstractPlatform>, ClassMetadata::GENERATOR_TYPE_*> $value */
public function getIdentityGenerationPreferences(): array
{
return $this->identityGenerationPreferences;
}
/**
* Sets the directory where Doctrine generates any necessary proxy class files.
*/
public function setProxyDir(string $dir): void
{
$this->attributes['proxyDir'] = $dir;
}
/**
* Gets the directory where Doctrine generates any necessary proxy class files.
*/
public function getProxyDir(): string|null
{
return $this->attributes['proxyDir'] ?? null;
}
/**
* Gets the strategy for automatically generating proxy classes.
*
* @return ProxyFactory::AUTOGENERATE_*
*/
public function getAutoGenerateProxyClasses(): int
{
return $this->attributes['autoGenerateProxyClasses'] ?? ProxyFactory::AUTOGENERATE_ALWAYS;
}
/**
* Sets the strategy for automatically generating proxy classes.
*
* @param bool|ProxyFactory::AUTOGENERATE_* $autoGenerate True is converted to AUTOGENERATE_ALWAYS, false to AUTOGENERATE_NEVER.
*/
public function setAutoGenerateProxyClasses(bool|int $autoGenerate): void
{
$this->attributes['autoGenerateProxyClasses'] = (int) $autoGenerate;
}
/**
* Gets the namespace where proxy classes reside.
*/
public function getProxyNamespace(): string|null
{
return $this->attributes['proxyNamespace'] ?? null;
}
/**
* Sets the namespace where proxy classes reside.
*/
public function setProxyNamespace(string $ns): void
{
$this->attributes['proxyNamespace'] = $ns;
}
/**
* Sets the cache driver implementation that is used for metadata caching.
*
* @todo Force parameter to be a Closure to ensure lazy evaluation
* (as soon as a metadata cache is in effect, the driver never needs to initialize).
*/
public function setMetadataDriverImpl(MappingDriver $driverImpl): void
{
$this->attributes['metadataDriverImpl'] = $driverImpl;
}
/**
* Sets the entity alias map.
*
* @psalm-param array<string, string> $entityNamespaces
*/
public function setEntityNamespaces(array $entityNamespaces): void
{
$this->attributes['entityNamespaces'] = $entityNamespaces;
}
/**
* Retrieves the list of registered entity namespace aliases.
*
* @psalm-return array<string, string>
*/
public function getEntityNamespaces(): array
{
return $this->attributes['entityNamespaces'];
}
/**
* Gets the cache driver implementation that is used for the mapping metadata.
*/
public function getMetadataDriverImpl(): MappingDriver|null
{
return $this->attributes['metadataDriverImpl'] ?? null;
}
/**
* Gets the cache driver implementation that is used for the query cache (SQL cache).
*/
public function getQueryCache(): CacheItemPoolInterface|null
{
return $this->attributes['queryCache'] ?? null;
}
/**
* Sets the cache driver implementation that is used for the query cache (SQL cache).
*/
public function setQueryCache(CacheItemPoolInterface $cache): void
{
$this->attributes['queryCache'] = $cache;
}
public function getHydrationCache(): CacheItemPoolInterface|null
{
return $this->attributes['hydrationCache'] ?? null;
}
public function setHydrationCache(CacheItemPoolInterface $cache): void
{
$this->attributes['hydrationCache'] = $cache;
}
public function getMetadataCache(): CacheItemPoolInterface|null
{
return $this->attributes['metadataCache'] ?? null;
}
public function setMetadataCache(CacheItemPoolInterface $cache): void
{
$this->attributes['metadataCache'] = $cache;
}
/**
* Registers a custom DQL function that produces a string value.
* Such a function can then be used in any DQL statement in any place where string
* functions are allowed.
*
* DQL function names are case-insensitive.
*
* @param class-string|callable $className Class name or a callable that returns the function.
* @psalm-param class-string<FunctionNode>|callable(string):FunctionNode $className
*/
public function addCustomStringFunction(string $name, string|callable $className): void
{
$this->attributes['customStringFunctions'][strtolower($name)] = $className;
}
/**
* Gets the implementation class name of a registered custom string DQL function.
*
* @psalm-return class-string<FunctionNode>|callable(string):FunctionNode|null
*/
public function getCustomStringFunction(string $name): string|callable|null
{
$name = strtolower($name);
return $this->attributes['customStringFunctions'][$name] ?? null;
}
/**
* Sets a map of custom DQL string functions.
*
* Keys must be function names and values the FQCN of the implementing class.
* The function names will be case-insensitive in DQL.
*
* Any previously added string functions are discarded.
*
* @psalm-param array<string, class-string<FunctionNode>|callable(string):FunctionNode> $functions The map of custom
* DQL string functions.
*/
public function setCustomStringFunctions(array $functions): void
{
foreach ($functions as $name => $className) {
$this->addCustomStringFunction($name, $className);
}
}
/**
* Registers a custom DQL function that produces a numeric value.
* Such a function can then be used in any DQL statement in any place where numeric
* functions are allowed.
*
* DQL function names are case-insensitive.
*
* @param class-string|callable $className Class name or a callable that returns the function.
* @psalm-param class-string<FunctionNode>|callable(string):FunctionNode $className
*/
public function addCustomNumericFunction(string $name, string|callable $className): void
{
$this->attributes['customNumericFunctions'][strtolower($name)] = $className;
}
/**
* Gets the implementation class name of a registered custom numeric DQL function.
*
* @psalm-return ?class-string<FunctionNode>|callable(string):FunctionNode
*/
public function getCustomNumericFunction(string $name): string|callable|null
{
$name = strtolower($name);
return $this->attributes['customNumericFunctions'][$name] ?? null;
}
/**
* Sets a map of custom DQL numeric functions.
*
* Keys must be function names and values the FQCN of the implementing class.
* The function names will be case-insensitive in DQL.
*
* Any previously added numeric functions are discarded.
*
* @psalm-param array<string, class-string> $functions The map of custom
* DQL numeric functions.
*/
public function setCustomNumericFunctions(array $functions): void
{
foreach ($functions as $name => $className) {
$this->addCustomNumericFunction($name, $className);
}
}
/**
* Registers a custom DQL function that produces a date/time value.
* Such a function can then be used in any DQL statement in any place where date/time
* functions are allowed.
*
* DQL function names are case-insensitive.
*
* @param string|callable $className Class name or a callable that returns the function.
* @psalm-param class-string<FunctionNode>|callable(string):FunctionNode $className
*/
public function addCustomDatetimeFunction(string $name, string|callable $className): void
{
$this->attributes['customDatetimeFunctions'][strtolower($name)] = $className;
}
/**
* Gets the implementation class name of a registered custom date/time DQL function.
*
* @psalm-return class-string|callable|null
*/
public function getCustomDatetimeFunction(string $name): string|callable|null
{
$name = strtolower($name);
return $this->attributes['customDatetimeFunctions'][$name] ?? null;
}
/**
* Sets a map of custom DQL date/time functions.
*
* Keys must be function names and values the FQCN of the implementing class.
* The function names will be case-insensitive in DQL.
*
* Any previously added date/time functions are discarded.
*
* @param array $functions The map of custom DQL date/time functions.
* @psalm-param array<string, class-string<FunctionNode>|callable(string):FunctionNode> $functions
*/
public function setCustomDatetimeFunctions(array $functions): void
{
foreach ($functions as $name => $className) {
$this->addCustomDatetimeFunction($name, $className);
}
}
/**
* Sets a TypedFieldMapper for php typed fields to DBAL types auto-completion.
*/
public function setTypedFieldMapper(TypedFieldMapper|null $typedFieldMapper): void
{
$this->attributes['typedFieldMapper'] = $typedFieldMapper;
}
/**
* Gets a TypedFieldMapper for php typed fields to DBAL types auto-completion.
*/
public function getTypedFieldMapper(): TypedFieldMapper|null
{
return $this->attributes['typedFieldMapper'] ?? null;
}
/**
* Sets the custom hydrator modes in one pass.
*
* @param array<string, class-string<AbstractHydrator>> $modes An array of ($modeName => $hydrator).
*/
public function setCustomHydrationModes(array $modes): void
{
$this->attributes['customHydrationModes'] = [];
foreach ($modes as $modeName => $hydrator) {
$this->addCustomHydrationMode($modeName, $hydrator);
}
}
/**
* Gets the hydrator class for the given hydration mode name.
*
* @psalm-return class-string<AbstractHydrator>|null
*/
public function getCustomHydrationMode(string $modeName): string|null
{
return $this->attributes['customHydrationModes'][$modeName] ?? null;
}
/**
* Adds a custom hydration mode.
*
* @psalm-param class-string<AbstractHydrator> $hydrator
*/
public function addCustomHydrationMode(string $modeName, string $hydrator): void
{
$this->attributes['customHydrationModes'][$modeName] = $hydrator;
}
/**
* Sets a class metadata factory.
*
* @psalm-param class-string $cmfName
*/
public function setClassMetadataFactoryName(string $cmfName): void
{
$this->attributes['classMetadataFactoryName'] = $cmfName;
}
/** @psalm-return class-string */
public function getClassMetadataFactoryName(): string
{
if (! isset($this->attributes['classMetadataFactoryName'])) {
$this->attributes['classMetadataFactoryName'] = ClassMetadataFactory::class;
}
return $this->attributes['classMetadataFactoryName'];
}
/**
* Adds a filter to the list of possible filters.
*
* @param string $className The class name of the filter.
* @psalm-param class-string<SQLFilter> $className
*/
public function addFilter(string $name, string $className): void
{
$this->attributes['filters'][$name] = $className;
}
/**
* Gets the class name for a given filter name.
*
* @return string|null The class name of the filter, or null if it is not
* defined.
* @psalm-return class-string<SQLFilter>|null
*/
public function getFilterClassName(string $name): string|null
{
return $this->attributes['filters'][$name] ?? null;
}
/**
* Sets default repository class.
*
* @psalm-param class-string<EntityRepository> $className
*
* @throws InvalidEntityRepository If $classname is not an ObjectRepository.
*/
public function setDefaultRepositoryClassName(string $className): void
{
if (! class_exists($className) || ! is_a($className, EntityRepository::class, true)) {
throw InvalidEntityRepository::fromClassName($className);
}
$this->attributes['defaultRepositoryClassName'] = $className;
}
/**
* Get default repository class.
*
* @psalm-return class-string<EntityRepository>
*/
public function getDefaultRepositoryClassName(): string
{
return $this->attributes['defaultRepositoryClassName'] ?? EntityRepository::class;
}
/**
* Sets naming strategy.
*/
public function setNamingStrategy(NamingStrategy $namingStrategy): void
{
$this->attributes['namingStrategy'] = $namingStrategy;
}
/**
* Gets naming strategy..
*/
public function getNamingStrategy(): NamingStrategy
{
if (! isset($this->attributes['namingStrategy'])) {
$this->attributes['namingStrategy'] = new DefaultNamingStrategy();
}
return $this->attributes['namingStrategy'];
}
/**
* Sets quote strategy.
*/
public function setQuoteStrategy(QuoteStrategy $quoteStrategy): void
{
$this->attributes['quoteStrategy'] = $quoteStrategy;
}
/**
* Gets quote strategy.
*/
public function getQuoteStrategy(): QuoteStrategy
{
if (! isset($this->attributes['quoteStrategy'])) {
$this->attributes['quoteStrategy'] = new DefaultQuoteStrategy();
}
return $this->attributes['quoteStrategy'];
}
/**
* Set the entity listener resolver.
*/
public function setEntityListenerResolver(EntityListenerResolver $resolver): void
{
$this->attributes['entityListenerResolver'] = $resolver;
}
/**
* Get the entity listener resolver.
*/
public function getEntityListenerResolver(): EntityListenerResolver
{
if (! isset($this->attributes['entityListenerResolver'])) {
$this->attributes['entityListenerResolver'] = new DefaultEntityListenerResolver();
}
return $this->attributes['entityListenerResolver'];
}
/**
* Set the entity repository factory.
*/
public function setRepositoryFactory(RepositoryFactory $repositoryFactory): void
{
$this->attributes['repositoryFactory'] = $repositoryFactory;
}
/**
* Get the entity repository factory.
*/
public function getRepositoryFactory(): RepositoryFactory
{
return $this->attributes['repositoryFactory'] ?? new DefaultRepositoryFactory();
}
public function isSecondLevelCacheEnabled(): bool
{
return $this->attributes['isSecondLevelCacheEnabled'] ?? false;
}
public function setSecondLevelCacheEnabled(bool $flag = true): void
{
$this->attributes['isSecondLevelCacheEnabled'] = $flag;
}
public function setSecondLevelCacheConfiguration(CacheConfiguration $cacheConfig): void
{
$this->attributes['secondLevelCacheConfiguration'] = $cacheConfig;
}
public function getSecondLevelCacheConfiguration(): CacheConfiguration|null
{
if (! isset($this->attributes['secondLevelCacheConfiguration']) && $this->isSecondLevelCacheEnabled()) {
$this->attributes['secondLevelCacheConfiguration'] = new CacheConfiguration();
}
return $this->attributes['secondLevelCacheConfiguration'] ?? null;
}
/**
* Returns query hints, which will be applied to every query in application
*
* @psalm-return array<string, mixed>
*/
public function getDefaultQueryHints(): array
{
return $this->attributes['defaultQueryHints'] ?? [];
}
/**
* Sets array of query hints, which will be applied to every query in application
*
* @psalm-param array<string, mixed> $defaultQueryHints
*/
public function setDefaultQueryHints(array $defaultQueryHints): void
{
$this->attributes['defaultQueryHints'] = $defaultQueryHints;
}
/**
* Gets the value of a default query hint. If the hint name is not recognized, FALSE is returned.
*
* @return mixed The value of the hint or FALSE, if the hint name is not recognized.
*/
public function getDefaultQueryHint(string $name): mixed
{
return $this->attributes['defaultQueryHints'][$name] ?? false;
}
/**
* Sets a default query hint. If the hint name is not recognized, it is silently ignored.
*/
public function setDefaultQueryHint(string $name, mixed $value): void
{
$this->attributes['defaultQueryHints'][$name] = $value;
}
/**
* Gets a list of entity class names to be ignored by the SchemaTool
*
* @return list<class-string>
*/
public function getSchemaIgnoreClasses(): array
{
return $this->attributes['schemaIgnoreClasses'] ?? [];
}
/**
* Sets a list of entity class names to be ignored by the SchemaTool
*
* @param list<class-string> $schemaIgnoreClasses List of entity class names
*/
public function setSchemaIgnoreClasses(array $schemaIgnoreClasses): void
{
$this->attributes['schemaIgnoreClasses'] = $schemaIgnoreClasses;
}
public function isLazyProxyEnabled(): bool
{
return $this->attributes['lazyProxy'] ?? false;
}
public function setLazyProxyEnabled(bool $lazyProxy): void
{
if (PHP_VERSION_ID < 80400) {
throw new LogicException('Lazy loading proxies require PHP 8.4 or higher.');
}
$this->attributes['lazyProxy'] = $lazyProxy;
}
/**
* To be deprecated in 3.1.0
*
* @return true
*/
public function isLazyGhostObjectEnabled(): bool
{
return true;
}
/** To be deprecated in 3.1.0 */
public function setLazyGhostObjectEnabled(bool $flag): void
{
if (! $flag) {
throw new LogicException(<<<'EXCEPTION'
The lazy ghost object feature cannot be disabled anymore.
Please remove the call to setLazyGhostObjectEnabled(false).
EXCEPTION);
}
}
/** To be deprecated in 3.1.0 */
public function setRejectIdCollisionInIdentityMap(bool $flag): void
{
if (! $flag) {
throw new LogicException(<<<'EXCEPTION'
Rejecting ID collisions in the identity map cannot be disabled anymore.
Please remove the call to setRejectIdCollisionInIdentityMap(false).
EXCEPTION);
}
}
/**
* To be deprecated in 3.1.0
*
* @return true
*/
public function isRejectIdCollisionInIdentityMapEnabled(): bool
{
return true;
}
public function setEagerFetchBatchSize(int $batchSize = 100): void
{
$this->attributes['fetchModeSubselectBatchSize'] = $batchSize;
}
public function getEagerFetchBatchSize(): int
{
return $this->attributes['fetchModeSubselectBatchSize'] ?? 100;
}
}