11
11
12
12
namespace Symfony \Bridge \Doctrine \Form ;
13
13
14
- use Doctrine \DBAL \Types \Type ;
15
14
use Doctrine \DBAL \Types \Types ;
16
15
use Doctrine \ORM \Mapping \ClassMetadataInfo ;
17
16
use Doctrine \ORM \Mapping \MappingException as LegacyMappingException ;
@@ -29,15 +28,9 @@ class DoctrineOrmTypeGuesser implements FormTypeGuesserInterface
29
28
30
29
private $ cache = [];
31
30
32
- private static $ useDeprecatedConstants ;
33
-
34
31
public function __construct (ManagerRegistry $ registry )
35
32
{
36
33
$ this ->registry = $ registry ;
37
-
38
- if (null === self ::$ useDeprecatedConstants ) {
39
- self ::$ useDeprecatedConstants = !class_exists (Types::class);
40
- }
41
34
}
42
35
43
36
/**
@@ -59,39 +52,39 @@ public function guessType(string $class, string $property)
59
52
}
60
53
61
54
switch ($ metadata ->getTypeOfField ($ property )) {
62
- case self :: $ useDeprecatedConstants ? Type:: TARRAY : Types::ARRAY :
63
- case self :: $ useDeprecatedConstants ? Type:: SIMPLE_ARRAY : Types::SIMPLE_ARRAY :
55
+ case Types::ARRAY :
56
+ case Types::SIMPLE_ARRAY :
64
57
return new TypeGuess ('Symfony\Component\Form\Extension\Core\Type\CollectionType ' , [], Guess::MEDIUM_CONFIDENCE );
65
- case self :: $ useDeprecatedConstants ? Type:: BOOLEAN : Types::BOOLEAN :
58
+ case Types::BOOLEAN :
66
59
return new TypeGuess ('Symfony\Component\Form\Extension\Core\Type\CheckboxType ' , [], Guess::HIGH_CONFIDENCE );
67
- case self :: $ useDeprecatedConstants ? Type:: DATETIME : Types::DATETIME_MUTABLE :
68
- case self :: $ useDeprecatedConstants ? Type:: DATETIMETZ : Types::DATETIMETZ_MUTABLE :
60
+ case Types::DATETIME_MUTABLE :
61
+ case Types::DATETIMETZ_MUTABLE :
69
62
case 'vardatetime ' :
70
63
return new TypeGuess ('Symfony\Component\Form\Extension\Core\Type\DateTimeType ' , [], Guess::HIGH_CONFIDENCE );
71
- case ' datetime_immutable ' :
72
- case ' datetimetz_immutable ' :
64
+ case Types:: DATE_IMMUTABLE :
65
+ case Types:: DATETIMETZ_IMMUTABLE :
73
66
return new TypeGuess ('Symfony\Component\Form\Extension\Core\Type\DateTimeType ' , ['input ' => 'datetime_immutable ' ], Guess::HIGH_CONFIDENCE );
74
- case ' dateinterval ' :
67
+ case Types:: DATEINTERVAL :
75
68
return new TypeGuess ('Symfony\Component\Form\Extension\Core\Type\DateIntervalType ' , [], Guess::HIGH_CONFIDENCE );
76
- case self :: $ useDeprecatedConstants ? Type:: DATE : Types::DATE_MUTABLE :
69
+ case Types::DATE_MUTABLE :
77
70
return new TypeGuess ('Symfony\Component\Form\Extension\Core\Type\DateType ' , [], Guess::HIGH_CONFIDENCE );
78
- case ' date_immutable ' :
71
+ case Types:: DATE_IMMUTABLE :
79
72
return new TypeGuess ('Symfony\Component\Form\Extension\Core\Type\DateType ' , ['input ' => 'datetime_immutable ' ], Guess::HIGH_CONFIDENCE );
80
- case self :: $ useDeprecatedConstants ? Type:: TIME : Types::TIME_MUTABLE :
73
+ case Types::TIME_MUTABLE :
81
74
return new TypeGuess ('Symfony\Component\Form\Extension\Core\Type\TimeType ' , [], Guess::HIGH_CONFIDENCE );
82
- case ' time_immutable ' :
75
+ case Types:: TIME_IMMUTABLE :
83
76
return new TypeGuess ('Symfony\Component\Form\Extension\Core\Type\TimeType ' , ['input ' => 'datetime_immutable ' ], Guess::HIGH_CONFIDENCE );
84
- case self :: $ useDeprecatedConstants ? Type:: DECIMAL : Types::DECIMAL :
77
+ case Types::DECIMAL :
85
78
return new TypeGuess ('Symfony\Component\Form\Extension\Core\Type\NumberType ' , ['input ' => 'string ' ], Guess::MEDIUM_CONFIDENCE );
86
- case self :: $ useDeprecatedConstants ? Type:: FLOAT : Types::FLOAT :
79
+ case Types::FLOAT :
87
80
return new TypeGuess ('Symfony\Component\Form\Extension\Core\Type\NumberType ' , [], Guess::MEDIUM_CONFIDENCE );
88
- case self :: $ useDeprecatedConstants ? Type:: INTEGER : Types::INTEGER :
89
- case self :: $ useDeprecatedConstants ? Type:: BIGINT : Types::BIGINT :
90
- case self :: $ useDeprecatedConstants ? Type:: SMALLINT : Types::SMALLINT :
81
+ case Types::INTEGER :
82
+ case Types::BIGINT :
83
+ case Types::SMALLINT :
91
84
return new TypeGuess ('Symfony\Component\Form\Extension\Core\Type\IntegerType ' , [], Guess::MEDIUM_CONFIDENCE );
92
- case self :: $ useDeprecatedConstants ? Type:: STRING : Types::STRING :
85
+ case Types::STRING :
93
86
return new TypeGuess ('Symfony\Component\Form\Extension\Core\Type\TextType ' , [], Guess::MEDIUM_CONFIDENCE );
94
- case self :: $ useDeprecatedConstants ? Type:: TEXT : Types::TEXT :
87
+ case Types::TEXT :
95
88
return new TypeGuess ('Symfony\Component\Form\Extension\Core\Type\TextareaType ' , [], Guess::MEDIUM_CONFIDENCE );
96
89
default :
97
90
return new TypeGuess ('Symfony\Component\Form\Extension\Core\Type\TextType ' , [], Guess::LOW_CONFIDENCE );
@@ -114,7 +107,7 @@ public function guessRequired(string $class, string $property)
114
107
115
108
// Check whether the field exists and is nullable or not
116
109
if (isset ($ classMetadata ->fieldMappings [$ property ])) {
117
- if (!$ classMetadata ->isNullable ($ property ) && ( self :: $ useDeprecatedConstants ? Type:: BOOLEAN : Types::BOOLEAN ) !== $ classMetadata ->getTypeOfField ($ property )) {
110
+ if (!$ classMetadata ->isNullable ($ property ) && Types::BOOLEAN !== $ classMetadata ->getTypeOfField ($ property )) {
118
111
return new ValueGuess (true , Guess::HIGH_CONFIDENCE );
119
112
}
120
113
@@ -151,7 +144,7 @@ public function guessMaxLength(string $class, string $property)
151
144
return new ValueGuess ($ mapping ['length ' ], Guess::HIGH_CONFIDENCE );
152
145
}
153
146
154
- if (\in_array ($ ret [0 ]->getTypeOfField ($ property ), self :: $ useDeprecatedConstants ? [Type:: DECIMAL , Type:: FLOAT ] : [Types::DECIMAL , Types::FLOAT ])) {
147
+ if (\in_array ($ ret [0 ]->getTypeOfField ($ property ), [Types::DECIMAL , Types::FLOAT ])) {
155
148
return new ValueGuess (null , Guess::MEDIUM_CONFIDENCE );
156
149
}
157
150
}
@@ -166,7 +159,7 @@ public function guessPattern(string $class, string $property)
166
159
{
167
160
$ ret = $ this ->getMetadata ($ class );
168
161
if ($ ret && isset ($ ret [0 ]->fieldMappings [$ property ]) && !$ ret [0 ]->hasAssociation ($ property )) {
169
- if (\in_array ($ ret [0 ]->getTypeOfField ($ property ), self :: $ useDeprecatedConstants ? [Type:: DECIMAL , Type:: FLOAT ] : [Types::DECIMAL , Types::FLOAT ])) {
162
+ if (\in_array ($ ret [0 ]->getTypeOfField ($ property ), [Types::DECIMAL , Types::FLOAT ])) {
170
163
return new ValueGuess (null , Guess::MEDIUM_CONFIDENCE );
171
164
}
172
165
}
0 commit comments