-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
MappingException.php
1007 lines (921 loc) · 28.9 KB
/
MappingException.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
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
declare(strict_types=1);
namespace Doctrine\ORM\Mapping;
use BackedEnum;
use Doctrine\ORM\Exception\ORMException;
use LibXMLError;
use ReflectionException;
use ValueError;
use function array_keys;
use function array_map;
use function array_values;
use function get_debug_type;
use function get_parent_class;
use function implode;
use function sprintf;
use const PHP_EOL;
/**
* A MappingException indicates that something is wrong with the mapping setup.
*/
class MappingException extends ORMException
{
/** @return MappingException */
public static function pathRequired()
{
return new self('Specifying the paths to your entities is required ' .
'in the AnnotationDriver to retrieve all class names.');
}
/**
* @param string $entityName
*
* @return MappingException
*/
public static function identifierRequired($entityName)
{
$parent = get_parent_class($entityName);
if ($parent !== false) {
return new self(sprintf(
'No identifier/primary key specified for Entity "%s" sub class of "%s". Every Entity must have an identifier/primary key.',
$entityName,
$parent
));
}
return new self(sprintf(
'No identifier/primary key specified for Entity "%s". Every Entity must have an identifier/primary key.',
$entityName
));
}
/**
* @param string $entityName
* @param int $type
*
* @return MappingException
*/
public static function invalidInheritanceType($entityName, $type)
{
return new self(sprintf("The inheritance type '%s' specified for '%s' does not exist.", $type, $entityName));
}
/** @return MappingException */
public static function generatorNotAllowedWithCompositeId()
{
return new self("Id generators can't be used with a composite id.");
}
/**
* @param string $entity
*
* @return MappingException
*/
public static function missingFieldName($entity)
{
return new self(sprintf(
"The field or association mapping misses the 'fieldName' attribute in entity '%s'.",
$entity
));
}
/**
* @param string $fieldName
*
* @return MappingException
*/
public static function missingTargetEntity($fieldName)
{
return new self(sprintf("The association mapping '%s' misses the 'targetEntity' attribute.", $fieldName));
}
/**
* @param string $fieldName
*
* @return MappingException
*/
public static function missingSourceEntity($fieldName)
{
return new self(sprintf("The association mapping '%s' misses the 'sourceEntity' attribute.", $fieldName));
}
/**
* @param string $fieldName
*
* @return MappingException
*/
public static function missingEmbeddedClass($fieldName)
{
return new self(sprintf("The embed mapping '%s' misses the 'class' attribute.", $fieldName));
}
/**
* @param string $entityName
* @param string $fileName
*
* @return MappingException
*/
public static function mappingFileNotFound($entityName, $fileName)
{
return new self(sprintf("No mapping file found named '%s' for class '%s'.", $fileName, $entityName));
}
/**
* Exception for invalid property name override.
*
* @param string $className The entity's name.
* @param string $fieldName
*
* @return MappingException
*/
public static function invalidOverrideFieldName($className, $fieldName)
{
return new self(sprintf("Invalid field override named '%s' for class '%s'.", $fieldName, $className));
}
/**
* Exception for invalid property type override.
*
* @param string $className The entity's name.
* @param string $fieldName
*
* @return MappingException
*/
public static function invalidOverrideFieldType($className, $fieldName)
{
return new self(sprintf(
"The column type of attribute '%s' on class '%s' could not be changed.",
$fieldName,
$className
));
}
/**
* @param string $className
* @param string $fieldName
*
* @return MappingException
*/
public static function mappingNotFound($className, $fieldName)
{
return new self(sprintf("No mapping found for field '%s' on class '%s'.", $fieldName, $className));
}
/**
* @param string $className
* @param string $queryName
*
* @return MappingException
*/
public static function queryNotFound($className, $queryName)
{
return new self(sprintf("No query found named '%s' on class '%s'.", $queryName, $className));
}
/**
* @param string $className
* @param string $resultName
*
* @return MappingException
*/
public static function resultMappingNotFound($className, $resultName)
{
return new self(sprintf("No result set mapping found named '%s' on class '%s'.", $resultName, $className));
}
/**
* @param string $entity
* @param string $queryName
*
* @return MappingException
*/
public static function emptyQueryMapping($entity, $queryName)
{
return new self(sprintf('Query named "%s" in "%s" could not be empty.', $queryName, $entity));
}
/**
* @param string $className
*
* @return MappingException
*/
public static function nameIsMandatoryForQueryMapping($className)
{
return new self(sprintf("Query name on entity class '%s' is not defined.", $className));
}
/**
* @param string $entity
* @param string $queryName
*
* @return MappingException
*/
public static function missingQueryMapping($entity, $queryName)
{
return new self(sprintf(
'Query named "%s" in "%s requires a result class or result set mapping.',
$queryName,
$entity
));
}
/**
* @param string $entity
* @param string $resultName
*
* @return MappingException
*/
public static function missingResultSetMappingEntity($entity, $resultName)
{
return new self(sprintf(
'Result set mapping named "%s" in "%s requires a entity class name.',
$resultName,
$entity
));
}
/**
* @param string $entity
* @param string $resultName
*
* @return MappingException
*/
public static function missingResultSetMappingFieldName($entity, $resultName)
{
return new self(sprintf(
'Result set mapping named "%s" in "%s requires a field name.',
$resultName,
$entity
));
}
/**
* @param string $className
*
* @return MappingException
*/
public static function nameIsMandatoryForSqlResultSetMapping($className)
{
return new self(sprintf("Result set mapping name on entity class '%s' is not defined.", $className));
}
public static function oneToManyRequiresMappedBy(string $entityName, string $fieldName): MappingException
{
return new self(sprintf(
"OneToMany mapping on entity '%s' field '%s' requires the 'mappedBy' attribute.",
$entityName,
$fieldName
));
}
/**
* @param string $fieldName
*
* @return MappingException
*/
public static function joinTableRequired($fieldName)
{
return new self(sprintf("The mapping of field '%s' requires an the 'joinTable' attribute.", $fieldName));
}
/**
* Called if a required option was not found but is required
*
* @param string $field Which field cannot be processed?
* @param string $expectedOption Which option is required
* @param string $hint Can optionally be used to supply a tip for common mistakes,
* e.g. "Did you think of the plural s?"
*
* @return MappingException
*/
public static function missingRequiredOption($field, $expectedOption, $hint = '')
{
$message = "The mapping of field '" . $field . "' is invalid: The option '" . $expectedOption . "' is required.";
if (! empty($hint)) {
$message .= ' (Hint: ' . $hint . ')';
}
return new self($message);
}
/**
* Generic exception for invalid mappings.
*
* @param string $fieldName
*
* @return MappingException
*/
public static function invalidMapping($fieldName)
{
return new self(sprintf("The mapping of field '%s' is invalid.", $fieldName));
}
/**
* Exception for reflection exceptions - adds the entity name,
* because there might be long classnames that will be shortened
* within the stacktrace
*
* @param string $entity The entity's name
*
* @return MappingException
*/
public static function reflectionFailure($entity, ReflectionException $previousException)
{
return new self(sprintf('An error occurred in %s', $entity), 0, $previousException);
}
/**
* @param string $className
* @param string $joinColumn
*
* @return MappingException
*/
public static function joinColumnMustPointToMappedField($className, $joinColumn)
{
return new self(sprintf(
'The column %s must be mapped to a field in class %s since it is referenced by a join column of another class.',
$joinColumn,
$className
));
}
/**
* @param string $className
*
* @return MappingException
*/
public static function classIsNotAValidEntityOrMappedSuperClass($className)
{
$parent = get_parent_class($className);
if ($parent !== false) {
return new self(sprintf(
'Class "%s" sub class of "%s" is not a valid entity or mapped super class.',
$className,
$parent
));
}
return new self(sprintf(
'Class "%s" is not a valid entity or mapped super class.',
$className
));
}
/**
* @deprecated 2.9 no longer in use
*
* @param string $className
* @param string $propertyName
*
* @return MappingException
*/
public static function propertyTypeIsRequired($className, $propertyName)
{
return new self(sprintf(
"The attribute 'type' is required for the column description of property %s::\$%s.",
$className,
$propertyName
));
}
/**
* @param string $entity The entity's name.
* @param string $fieldName The name of the field that was already declared.
*
* @return MappingException
*/
public static function duplicateFieldMapping($entity, $fieldName)
{
return new self(sprintf(
'Property "%s" in "%s" was already declared, but it must be declared only once',
$fieldName,
$entity
));
}
/**
* @param string $entity
* @param string $fieldName
*
* @return MappingException
*/
public static function duplicateAssociationMapping($entity, $fieldName)
{
return new self(sprintf(
'Property "%s" in "%s" was already declared, but it must be declared only once',
$fieldName,
$entity
));
}
/**
* @param string $entity
* @param string $queryName
*
* @return MappingException
*/
public static function duplicateQueryMapping($entity, $queryName)
{
return new self(sprintf(
'Query named "%s" in "%s" was already declared, but it must be declared only once',
$queryName,
$entity
));
}
/**
* @param string $entity
* @param string $resultName
*
* @return MappingException
*/
public static function duplicateResultSetMapping($entity, $resultName)
{
return new self(sprintf(
'Result set mapping named "%s" in "%s" was already declared, but it must be declared only once',
$resultName,
$entity
));
}
/**
* @param string $entity
*
* @return MappingException
*/
public static function singleIdNotAllowedOnCompositePrimaryKey($entity)
{
return new self('Single id is not allowed on composite primary key in entity ' . $entity);
}
/**
* @param string $entity
*
* @return MappingException
*/
public static function noIdDefined($entity)
{
return new self('No ID defined for entity ' . $entity);
}
/**
* @param string $entity
* @param string $fieldName
* @param string $unsupportedType
*
* @return MappingException
*/
public static function unsupportedOptimisticLockingType($entity, $fieldName, $unsupportedType)
{
return new self(sprintf(
'Locking type "%s" (specified in "%s", field "%s") is not supported by Doctrine.',
$unsupportedType,
$entity,
$fieldName
));
}
/**
* @param string|null $path
*
* @return MappingException
*/
public static function fileMappingDriversRequireConfiguredDirectoryPath($path = null)
{
if (! empty($path)) {
$path = '[' . $path . ']';
}
return new self(
'File mapping drivers must have a valid directory path, ' .
'however the given path ' . $path . ' seems to be incorrect!'
);
}
/**
* Returns an exception that indicates that a class used in a discriminator map does not exist.
* An example would be an outdated (maybe renamed) classname.
*
* @param string $className The class that could not be found
* @param string $owningClass The class that declares the discriminator map.
*
* @return MappingException
*/
public static function invalidClassInDiscriminatorMap($className, $owningClass)
{
return new self(sprintf(
"Entity class '%s' used in the discriminator map of class '%s' " .
'does not exist.',
$className,
$owningClass
));
}
/**
* @param string $className
* @param string[] $entries
* @param array<string,string> $map
*
* @return MappingException
*/
public static function duplicateDiscriminatorEntry($className, array $entries, array $map)
{
return new self(
'The entries ' . implode(', ', $entries) . " in discriminator map of class '" . $className . "' is duplicated. " .
'If the discriminator map is automatically generated you have to convert it to an explicit discriminator map now. ' .
'The entries of the current map are: @DiscriminatorMap({' . implode(', ', array_map(
static function ($a, $b) {
return sprintf("'%s': '%s'", $a, $b);
},
array_keys($map),
array_values($map)
)) . '})'
);
}
/**
* @param string $className
*
* @return MappingException
*/
public static function missingDiscriminatorMap($className)
{
return new self(sprintf(
"Entity class '%s' is using inheritance but no discriminator map was defined.",
$className
));
}
/**
* @param string $className
*
* @return MappingException
*/
public static function missingDiscriminatorColumn($className)
{
return new self(sprintf(
"Entity class '%s' is using inheritance but no discriminator column was defined.",
$className
));
}
/**
* @param string $className
* @param string $type
*
* @return MappingException
*/
public static function invalidDiscriminatorColumnType($className, $type)
{
return new self(sprintf(
"Discriminator column type on entity class '%s' is not allowed to be '%s'. 'string' or 'integer' type variables are suggested!",
$className,
$type
));
}
/**
* @param string $className
*
* @return MappingException
*/
public static function nameIsMandatoryForDiscriminatorColumns($className)
{
return new self(sprintf("Discriminator column name on entity class '%s' is not defined.", $className));
}
/**
* @param string $className
* @param string $fieldName
*
* @return MappingException
*/
public static function cannotVersionIdField($className, $fieldName)
{
return new self(sprintf(
"Setting Id field '%s' as versionable in entity class '%s' is not supported.",
$fieldName,
$className
));
}
/**
* @param string $className
* @param string $fieldName
* @param string $type
*
* @return MappingException
*/
public static function sqlConversionNotAllowedForIdentifiers($className, $fieldName, $type)
{
return new self(sprintf(
"It is not possible to set id field '%s' to type '%s' in entity class '%s'. The type '%s' requires conversion SQL which is not allowed for identifiers.",
$fieldName,
$type,
$className,
$type
));
}
/**
* @param string $className
* @param string $columnName
*
* @return MappingException
*/
public static function duplicateColumnName($className, $columnName)
{
return new self("Duplicate definition of column '" . $columnName . "' on entity '" . $className . "' in a field or discriminator column mapping.");
}
/**
* @param string $className
* @param string $field
*
* @return MappingException
*/
public static function illegalToManyAssociationOnMappedSuperclass($className, $field)
{
return new self("It is illegal to put an inverse side one-to-many or many-to-many association on mapped superclass '" . $className . '#' . $field . "'.");
}
/**
* @param string $className
* @param string $targetEntity
* @param string $targetField
*
* @return MappingException
*/
public static function cannotMapCompositePrimaryKeyEntitiesAsForeignId($className, $targetEntity, $targetField)
{
return new self("It is not possible to map entity '" . $className . "' with a composite primary key " .
"as part of the primary key of another entity '" . $targetEntity . '#' . $targetField . "'.");
}
/**
* @param string $className
* @param string $field
*
* @return MappingException
*/
public static function noSingleAssociationJoinColumnFound($className, $field)
{
return new self(sprintf("'%s#%s' is not an association with a single join column.", $className, $field));
}
/**
* @param string $className
* @param string $column
*
* @return MappingException
*/
public static function noFieldNameFoundForColumn($className, $column)
{
return new self(sprintf(
"Cannot find a field on '%s' that is mapped to column '%s'. Either the " .
'field does not exist or an association exists but it has multiple join columns.',
$className,
$column
));
}
/**
* @param string $className
* @param string $field
*
* @return MappingException
*/
public static function illegalOrphanRemovalOnIdentifierAssociation($className, $field)
{
return new self(sprintf(
"The orphan removal option is not allowed on an association that is part of the identifier in '%s#%s'.",
$className,
$field
));
}
/**
* @param string $className
* @param string $field
*
* @return MappingException
*/
public static function illegalOrphanRemoval($className, $field)
{
return new self('Orphan removal is only allowed on one-to-one and one-to-many ' .
'associations, but ' . $className . '#' . $field . ' is not.');
}
/**
* @param string $className
* @param string $field
*
* @return MappingException
*/
public static function illegalInverseIdentifierAssociation($className, $field)
{
return new self(sprintf(
"An inverse association is not allowed to be identifier in '%s#%s'.",
$className,
$field
));
}
/**
* @param string $className
* @param string $field
*
* @return MappingException
*/
public static function illegalToManyIdentifierAssociation($className, $field)
{
return new self(sprintf(
"Many-to-many or one-to-many associations are not allowed to be identifier in '%s#%s'.",
$className,
$field
));
}
/**
* @param string $className
*
* @return MappingException
*/
public static function noInheritanceOnMappedSuperClass($className)
{
return new self("It is not supported to define inheritance information on a mapped superclass '" . $className . "'.");
}
/**
* @param string $className
* @param string $rootClassName
*
* @return MappingException
*/
public static function mappedClassNotPartOfDiscriminatorMap($className, $rootClassName)
{
return new self(
"Entity '" . $className . "' has to be part of the discriminator map of '" . $rootClassName . "' " .
"to be properly mapped in the inheritance hierarchy. Alternatively you can make '" . $className . "' an abstract class " .
'to avoid this exception from occurring.'
);
}
/**
* @param string $className
* @param string $methodName
*
* @return MappingException
*/
public static function lifecycleCallbackMethodNotFound($className, $methodName)
{
return new self("Entity '" . $className . "' has no method '" . $methodName . "' to be registered as lifecycle callback.");
}
/**
* @param string $listenerName
* @param string $className
*
* @return MappingException
*/
public static function entityListenerClassNotFound($listenerName, $className)
{
return new self(sprintf('Entity Listener "%s" declared on "%s" not found.', $listenerName, $className));
}
/**
* @param string $listenerName
* @param string $methodName
* @param string $className
*
* @return MappingException
*/
public static function entityListenerMethodNotFound($listenerName, $methodName, $className)
{
return new self(sprintf('Entity Listener "%s" declared on "%s" has no method "%s".', $listenerName, $className, $methodName));
}
/**
* @param string $listenerName
* @param string $methodName
* @param string $className
*
* @return MappingException
*/
public static function duplicateEntityListener($listenerName, $methodName, $className)
{
return new self(sprintf('Entity Listener "%s#%s()" in "%s" was already declared, but it must be declared only once.', $listenerName, $methodName, $className));
}
/** @param class-string $className */
public static function invalidFetchMode(string $className, string $fetchMode): self
{
return new self("Entity '" . $className . "' has a mapping with invalid fetch mode '" . $fetchMode . "'");
}
/** @param int|string $generatedMode */
public static function invalidGeneratedMode($generatedMode): self
{
return new self("Invalid generated mode '" . $generatedMode . "'");
}
/**
* @param string $className
*
* @return MappingException
*/
public static function compositeKeyAssignedIdGeneratorRequired($className)
{
return new self("Entity '" . $className . "' has a composite identifier but uses an ID generator other than manually assigning (Identity, Sequence). This is not supported.");
}
/**
* @param string $targetEntity
* @param string $sourceEntity
* @param string $associationName
*
* @return MappingException
*/
public static function invalidTargetEntityClass($targetEntity, $sourceEntity, $associationName)
{
return new self('The target-entity ' . $targetEntity . " cannot be found in '" . $sourceEntity . '#' . $associationName . "'.");
}
/**
* @param string[] $cascades
* @param string $className
* @param string $propertyName
*
* @return MappingException
*/
public static function invalidCascadeOption(array $cascades, $className, $propertyName)
{
$cascades = implode(', ', array_map(static function ($e) {
return "'" . $e . "'";
}, $cascades));
return new self(sprintf(
"You have specified invalid cascade options for %s::$%s: %s; available options: 'remove', 'persist', 'refresh', 'merge', and 'detach'",
$className,
$propertyName,
$cascades
));
}
/**
* @param string $className
*
* @return MappingException
*/
public static function missingSequenceName($className)
{
return new self(
sprintf('Missing "sequenceName" attribute for sequence id generator definition on class "%s".', $className)
);
}
/**
* @param string $className
* @param string $propertyName
*
* @return MappingException
*/
public static function infiniteEmbeddableNesting($className, $propertyName)
{
return new self(
sprintf(
'Infinite nesting detected for embedded property %s::%s. ' .
'You cannot embed an embeddable from the same type inside an embeddable.',
$className,
$propertyName
)
);
}
/**
* @param string $className
* @param string $propertyName
*
* @return self
*/
public static function illegalOverrideOfInheritedProperty($className, $propertyName)
{
return new self(
sprintf(
'Override for %s::%s is only allowed for attributes/associations ' .
'declared on a mapped superclass or a trait.',
$className,
$propertyName
)
);
}
/** @return self */
public static function invalidIndexConfiguration($className, $indexName)
{
return new self(
sprintf(
'Index %s for entity %s should contain columns or fields values, but not both.',
$indexName,
$className
)
);
}
/** @return self */
public static function invalidUniqueConstraintConfiguration($className, $indexName)
{
return new self(
sprintf(
'Unique constraint %s for entity %s should contain columns or fields values, but not both.',
$indexName,
$className
)
);
}
/** @param mixed $givenValue */
public static function invalidOverrideType(string $expectdType, $givenValue): self
{
return new self(sprintf(
'Expected %s, but %s was given.',
$expectdType,
get_debug_type($givenValue)
));
}
public static function enumsRequirePhp81(string $className, string $fieldName): self
{
return new self(sprintf('Enum types require PHP 8.1 in %s::$%s', $className, $fieldName));
}
public static function nonEnumTypeMapped(string $className, string $fieldName, string $enumType): self
{
return new self(sprintf(
'Attempting to map non-enum type %s as enum in entity %s::$%s',
$enumType,
$className,
$fieldName
));
}
/**
* @param class-string $className
* @param class-string<BackedEnum> $enumType
*/
public static function invalidEnumValue(
string $className,
string $fieldName,
string $value,
string $enumType,
ValueError $previous
): self {
return new self(sprintf(
<<<'EXCEPTION'
Context: Trying to hydrate enum property "%s::$%s"
Problem: Case "%s" is not listed in enum "%s"
Solution: Either add the case to the enum type or migrate the database column to use another case of the enum
EXCEPTION
,
$className,
$fieldName,
$value,
$enumType
), 0, $previous);
}
/** @param LibXMLError[] $errors */
public static function fromLibXmlErrors(array $errors): self
{
$formatter = static function (LibXMLError $error): string {
return sprintf(
'libxml error: %s in %s at line %d',
$error->message,
$error->file,