15
15
use Doctrine \Common \Persistence \Mapping \MappingException as LegacyCommonMappingException ;
16
16
use Doctrine \Common \Util \ClassUtils ;
17
17
use Doctrine \DBAL \Types \Type ;
18
+ use Doctrine \DBAL \Types \Types ;
18
19
use Doctrine \ORM \Mapping \ClassMetadataInfo ;
19
20
use Doctrine \ORM \Mapping \MappingException as LegacyMappingException ;
20
21
use Doctrine \Persistence \ManagerRegistry ;
@@ -30,12 +31,18 @@ class DoctrineOrmTypeGuesser implements FormTypeGuesserInterface
30
31
31
32
private $ cache = [];
32
33
34
+ private static $ useDeprecatedConstants ;
35
+
33
36
/**
34
37
* @param ManagerRegistry|LegacyManagerRegistry $registry
35
38
*/
36
39
public function __construct ($ registry )
37
40
{
38
41
$ this ->registry = $ registry ;
42
+
43
+ if (null === self ::$ useDeprecatedConstants ) {
44
+ self ::$ useDeprecatedConstants = !class_exists (Types::class);
45
+ }
39
46
}
40
47
41
48
/**
@@ -57,30 +64,30 @@ public function guessType($class, $property)
57
64
}
58
65
59
66
switch ($ metadata ->getTypeOfField ($ property )) {
60
- case Type::TARRAY :
67
+ case self :: $ useDeprecatedConstants ? Type::TARRAY : ' array ' :
61
68
return new TypeGuess ('Symfony\Component\Form\Extension\Core\Type\CollectionType ' , [], Guess::MEDIUM_CONFIDENCE );
62
- case Type::BOOLEAN :
69
+ case self :: $ useDeprecatedConstants ? Type:: BOOLEAN : Types ::BOOLEAN :
63
70
return new TypeGuess ('Symfony\Component\Form\Extension\Core\Type\CheckboxType ' , [], Guess::HIGH_CONFIDENCE );
64
- case Type::DATETIME :
65
- case Type::DATETIMETZ :
71
+ case self :: $ useDeprecatedConstants ? Type::DATETIME : Types:: DATETIME_MUTABLE :
72
+ case self :: $ useDeprecatedConstants ? Type::DATETIMETZ : Types:: DATETIMETZ_MUTABLE :
66
73
case 'vardatetime ' :
67
74
return new TypeGuess ('Symfony\Component\Form\Extension\Core\Type\DateTimeType ' , [], Guess::HIGH_CONFIDENCE );
68
75
case 'dateinterval ' :
69
76
return new TypeGuess ('Symfony\Component\Form\Extension\Core\Type\DateIntervalType ' , [], Guess::HIGH_CONFIDENCE );
70
- case Type::DATE :
77
+ case self :: $ useDeprecatedConstants ? Type::DATE : Types:: DATE_MUTABLE :
71
78
return new TypeGuess ('Symfony\Component\Form\Extension\Core\Type\DateType ' , [], Guess::HIGH_CONFIDENCE );
72
- case Type::TIME :
79
+ case self :: $ useDeprecatedConstants ? Type::TIME : Types:: TIME_MUTABLE :
73
80
return new TypeGuess ('Symfony\Component\Form\Extension\Core\Type\TimeType ' , [], Guess::HIGH_CONFIDENCE );
74
- case Type::DECIMAL :
75
- case Type::FLOAT :
81
+ case self :: $ useDeprecatedConstants ? Type:: DECIMAL : Types ::DECIMAL :
82
+ case self :: $ useDeprecatedConstants ? Type:: FLOAT : Types ::FLOAT :
76
83
return new TypeGuess ('Symfony\Component\Form\Extension\Core\Type\NumberType ' , [], Guess::MEDIUM_CONFIDENCE );
77
- case Type::INTEGER :
78
- case Type::BIGINT :
79
- case Type::SMALLINT :
84
+ case self :: $ useDeprecatedConstants ? Type:: INTEGER : Types ::INTEGER :
85
+ case self :: $ useDeprecatedConstants ? Type:: BIGINT : Types ::BIGINT :
86
+ case self :: $ useDeprecatedConstants ? Type:: SMALLINT : Types ::SMALLINT :
80
87
return new TypeGuess ('Symfony\Component\Form\Extension\Core\Type\IntegerType ' , [], Guess::MEDIUM_CONFIDENCE );
81
- case Type::STRING :
88
+ case self :: $ useDeprecatedConstants ? Type:: STRING : Types ::STRING :
82
89
return new TypeGuess ('Symfony\Component\Form\Extension\Core\Type\TextType ' , [], Guess::MEDIUM_CONFIDENCE );
83
- case Type::TEXT :
90
+ case self :: $ useDeprecatedConstants ? Type:: TEXT : Types ::TEXT :
84
91
return new TypeGuess ('Symfony\Component\Form\Extension\Core\Type\TextareaType ' , [], Guess::MEDIUM_CONFIDENCE );
85
92
default :
86
93
return new TypeGuess ('Symfony\Component\Form\Extension\Core\Type\TextType ' , [], Guess::LOW_CONFIDENCE );
@@ -103,7 +110,7 @@ public function guessRequired($class, $property)
103
110
104
111
// Check whether the field exists and is nullable or not
105
112
if (isset ($ classMetadata ->fieldMappings [$ property ])) {
106
- if (!$ classMetadata ->isNullable ($ property ) && Type::BOOLEAN !== $ classMetadata ->getTypeOfField ($ property )) {
113
+ if (!$ classMetadata ->isNullable ($ property ) && ( self :: $ useDeprecatedConstants ? Type::BOOLEAN : Types:: BOOLEAN ) !== $ classMetadata ->getTypeOfField ($ property )) {
107
114
return new ValueGuess (true , Guess::HIGH_CONFIDENCE );
108
115
}
109
116
@@ -140,7 +147,7 @@ public function guessMaxLength($class, $property)
140
147
return new ValueGuess ($ mapping ['length ' ], Guess::HIGH_CONFIDENCE );
141
148
}
142
149
143
- if (\in_array ($ ret [0 ]->getTypeOfField ($ property ), [Type::DECIMAL , Type::FLOAT ])) {
150
+ if (\in_array ($ ret [0 ]->getTypeOfField ($ property ), self :: $ useDeprecatedConstants ? [Type::DECIMAL , Type:: FLOAT ] : [Types:: DECIMAL , Types ::FLOAT ])) {
144
151
return new ValueGuess (null , Guess::MEDIUM_CONFIDENCE );
145
152
}
146
153
}
@@ -155,7 +162,7 @@ public function guessPattern($class, $property)
155
162
{
156
163
$ ret = $ this ->getMetadata ($ class );
157
164
if ($ ret && isset ($ ret [0 ]->fieldMappings [$ property ]) && !$ ret [0 ]->hasAssociation ($ property )) {
158
- if (\in_array ($ ret [0 ]->getTypeOfField ($ property ), [Type::DECIMAL , Type::FLOAT ])) {
165
+ if (\in_array ($ ret [0 ]->getTypeOfField ($ property ), self :: $ useDeprecatedConstants ? [Type::DECIMAL , Type:: FLOAT ] : [Types:: DECIMAL , Types ::FLOAT ])) {
159
166
return new ValueGuess (null , Guess::MEDIUM_CONFIDENCE );
160
167
}
161
168
}
0 commit comments