11
11
12
12
namespace Symfony \Component \Form \Extension \Validator ;
13
13
14
+ use Symfony \Component \Form \Extension \Core \Type \CheckboxType ;
15
+ use Symfony \Component \Form \Extension \Core \Type \CollectionType ;
16
+ use Symfony \Component \Form \Extension \Core \Type \CountryType ;
17
+ use Symfony \Component \Form \Extension \Core \Type \CurrencyType ;
18
+ use Symfony \Component \Form \Extension \Core \Type \DateTimeType ;
19
+ use Symfony \Component \Form \Extension \Core \Type \DateType ;
20
+ use Symfony \Component \Form \Extension \Core \Type \EmailType ;
21
+ use Symfony \Component \Form \Extension \Core \Type \FileType ;
22
+ use Symfony \Component \Form \Extension \Core \Type \IntegerType ;
23
+ use Symfony \Component \Form \Extension \Core \Type \LanguageType ;
24
+ use Symfony \Component \Form \Extension \Core \Type \LocaleType ;
25
+ use Symfony \Component \Form \Extension \Core \Type \NumberType ;
26
+ use Symfony \Component \Form \Extension \Core \Type \TextType ;
27
+ use Symfony \Component \Form \Extension \Core \Type \TimeType ;
28
+ use Symfony \Component \Form \Extension \Core \Type \UrlType ;
14
29
use Symfony \Component \Form \FormTypeGuesserInterface ;
15
30
use Symfony \Component \Form \Guess \Guess ;
16
31
use Symfony \Component \Form \Guess \TypeGuess ;
17
32
use Symfony \Component \Form \Guess \ValueGuess ;
18
33
use Symfony \Component \Validator \Constraint ;
34
+ use Symfony \Component \Validator \Constraints \Count ;
35
+ use Symfony \Component \Validator \Constraints \Country ;
36
+ use Symfony \Component \Validator \Constraints \Currency ;
37
+ use Symfony \Component \Validator \Constraints \Date ;
38
+ use Symfony \Component \Validator \Constraints \DateTime ;
39
+ use Symfony \Component \Validator \Constraints \Email ;
40
+ use Symfony \Component \Validator \Constraints \File ;
41
+ use Symfony \Component \Validator \Constraints \Image ;
42
+ use Symfony \Component \Validator \Constraints \Ip ;
43
+ use Symfony \Component \Validator \Constraints \IsFalse ;
19
44
use Symfony \Component \Validator \Constraints \IsTrue ;
45
+ use Symfony \Component \Validator \Constraints \Language ;
46
+ use Symfony \Component \Validator \Constraints \Length ;
47
+ use Symfony \Component \Validator \Constraints \Locale ;
20
48
use Symfony \Component \Validator \Constraints \NotBlank ;
21
49
use Symfony \Component \Validator \Constraints \NotNull ;
50
+ use Symfony \Component \Validator \Constraints \Range ;
51
+ use Symfony \Component \Validator \Constraints \Regex ;
52
+ use Symfony \Component \Validator \Constraints \Time ;
53
+ use Symfony \Component \Validator \Constraints \Type ;
54
+ use Symfony \Component \Validator \Constraints \Url ;
22
55
use Symfony \Component \Validator \Mapping \ClassMetadataInterface ;
23
56
use Symfony \Component \Validator \Mapping \Factory \MetadataFactoryInterface ;
24
57
@@ -79,86 +112,86 @@ public function guessPattern(string $class, string $property): ?ValueGuess
79
112
public function guessTypeForConstraint (Constraint $ constraint ): ?TypeGuess
80
113
{
81
114
switch (\get_class ($ constraint )) {
82
- case ' Symfony\Component\Validator\Constraints\ Type' :
115
+ case Type::class :
83
116
switch ($ constraint ->type ) {
84
117
case 'array ' :
85
- return new TypeGuess (' Symfony\Component\Form\Extension\Core\Type\ CollectionType' , [], Guess::MEDIUM_CONFIDENCE );
118
+ return new TypeGuess (CollectionType::class , [], Guess::MEDIUM_CONFIDENCE );
86
119
case 'boolean ' :
87
120
case 'bool ' :
88
- return new TypeGuess (' Symfony\Component\Form\Extension\Core\Type\ CheckboxType' , [], Guess::MEDIUM_CONFIDENCE );
121
+ return new TypeGuess (CheckboxType::class , [], Guess::MEDIUM_CONFIDENCE );
89
122
90
123
case 'double ' :
91
124
case 'float ' :
92
125
case 'numeric ' :
93
126
case 'real ' :
94
- return new TypeGuess (' Symfony\Component\Form\Extension\Core\Type\ NumberType' , [], Guess::MEDIUM_CONFIDENCE );
127
+ return new TypeGuess (NumberType::class , [], Guess::MEDIUM_CONFIDENCE );
95
128
96
129
case 'integer ' :
97
130
case 'int ' :
98
131
case 'long ' :
99
- return new TypeGuess (' Symfony\Component\Form\Extension\Core\Type\ IntegerType' , [], Guess::MEDIUM_CONFIDENCE );
132
+ return new TypeGuess (IntegerType::class , [], Guess::MEDIUM_CONFIDENCE );
100
133
101
134
case \DateTime::class:
102
135
case '\DateTime ' :
103
- return new TypeGuess (' Symfony\Component\Form\Extension\Core\Type\ DateType' , [], Guess::MEDIUM_CONFIDENCE );
136
+ return new TypeGuess (DateType::class , [], Guess::MEDIUM_CONFIDENCE );
104
137
105
138
case 'string ' :
106
- return new TypeGuess (' Symfony\Component\Form\Extension\Core\Type\ TextType' , [], Guess::LOW_CONFIDENCE );
139
+ return new TypeGuess (TextType::class , [], Guess::LOW_CONFIDENCE );
107
140
}
108
141
break ;
109
142
110
- case ' Symfony\Component\Validator\Constraints\ Country' :
111
- return new TypeGuess (' Symfony\Component\Form\Extension\Core\Type\ CountryType' , [], Guess::HIGH_CONFIDENCE );
143
+ case Country::class :
144
+ return new TypeGuess (CountryType::class , [], Guess::HIGH_CONFIDENCE );
112
145
113
- case ' Symfony\Component\Validator\Constraints\ Currency' :
114
- return new TypeGuess (' Symfony\Component\Form\Extension\Core\Type\ CurrencyType' , [], Guess::HIGH_CONFIDENCE );
146
+ case Currency::class :
147
+ return new TypeGuess (CurrencyType::class , [], Guess::HIGH_CONFIDENCE );
115
148
116
- case ' Symfony\Component\Validator\Constraints\ Date' :
117
- return new TypeGuess (' Symfony\Component\Form\Extension\Core\Type\ DateType' , ['input ' => 'string ' ], Guess::HIGH_CONFIDENCE );
149
+ case Date::class :
150
+ return new TypeGuess (DateType::class , ['input ' => 'string ' ], Guess::HIGH_CONFIDENCE );
118
151
119
- case ' Symfony\Component\Validator\Constraints\ DateTime' :
120
- return new TypeGuess (' Symfony\Component\Form\Extension\Core\Type\ DateTimeType' , ['input ' => 'string ' ], Guess::HIGH_CONFIDENCE );
152
+ case DateTime::class :
153
+ return new TypeGuess (DateTimeType::class , ['input ' => 'string ' ], Guess::HIGH_CONFIDENCE );
121
154
122
- case ' Symfony\Component\Validator\Constraints\ Email' :
123
- return new TypeGuess (' Symfony\Component\Form\Extension\Core\Type\ EmailType' , [], Guess::HIGH_CONFIDENCE );
155
+ case Email::class :
156
+ return new TypeGuess (EmailType::class , [], Guess::HIGH_CONFIDENCE );
124
157
125
- case ' Symfony\Component\Validator\Constraints\ File' :
126
- case ' Symfony\Component\Validator\Constraints\ Image' :
158
+ case File::class :
159
+ case Image::class :
127
160
$ options = [];
128
161
if ($ constraint ->mimeTypes ) {
129
162
$ options = ['attr ' => ['accept ' => implode (', ' , (array ) $ constraint ->mimeTypes )]];
130
163
}
131
164
132
- return new TypeGuess (' Symfony\Component\Form\Extension\Core\Type\ FileType' , $ options , Guess::HIGH_CONFIDENCE );
165
+ return new TypeGuess (FileType::class , $ options , Guess::HIGH_CONFIDENCE );
133
166
134
- case ' Symfony\Component\Validator\Constraints\ Language' :
135
- return new TypeGuess (' Symfony\Component\Form\Extension\Core\Type\ LanguageType' , [], Guess::HIGH_CONFIDENCE );
167
+ case Language::class :
168
+ return new TypeGuess (LanguageType::class , [], Guess::HIGH_CONFIDENCE );
136
169
137
- case ' Symfony\Component\Validator\Constraints\ Locale' :
138
- return new TypeGuess (' Symfony\Component\Form\Extension\Core\Type\ LocaleType' , [], Guess::HIGH_CONFIDENCE );
170
+ case Locale::class :
171
+ return new TypeGuess (LocaleType::class , [], Guess::HIGH_CONFIDENCE );
139
172
140
- case ' Symfony\Component\Validator\Constraints\ Time' :
141
- return new TypeGuess (' Symfony\Component\Form\Extension\Core\Type\ TimeType' , ['input ' => 'string ' ], Guess::HIGH_CONFIDENCE );
173
+ case Time::class :
174
+ return new TypeGuess (TimeType::class , ['input ' => 'string ' ], Guess::HIGH_CONFIDENCE );
142
175
143
- case ' Symfony\Component\Validator\Constraints\ Url' :
144
- return new TypeGuess (' Symfony\Component\Form\Extension\Core\Type\ UrlType' , [], Guess::HIGH_CONFIDENCE );
176
+ case Url::class :
177
+ return new TypeGuess (UrlType::class , [], Guess::HIGH_CONFIDENCE );
145
178
146
- case ' Symfony\Component\Validator\Constraints\Ip ' :
147
- return new TypeGuess (' Symfony\Component\Form\Extension\Core\Type\ TextType' , [], Guess::MEDIUM_CONFIDENCE );
179
+ case Ip::class :
180
+ return new TypeGuess (TextType::class , [], Guess::MEDIUM_CONFIDENCE );
148
181
149
- case ' Symfony\Component\Validator\Constraints\ Length' :
150
- case ' Symfony\Component\Validator\Constraints\ Regex' :
151
- return new TypeGuess (' Symfony\Component\Form\Extension\Core\Type\ TextType' , [], Guess::LOW_CONFIDENCE );
182
+ case Length::class :
183
+ case Regex::class :
184
+ return new TypeGuess (TextType::class , [], Guess::LOW_CONFIDENCE );
152
185
153
- case ' Symfony\Component\Validator\Constraints\ Range' :
154
- return new TypeGuess (' Symfony\Component\Form\Extension\Core\Type\ NumberType' , [], Guess::LOW_CONFIDENCE );
186
+ case Range::class :
187
+ return new TypeGuess (NumberType::class , [], Guess::LOW_CONFIDENCE );
155
188
156
- case ' Symfony\Component\Validator\Constraints\ Count' :
157
- return new TypeGuess (' Symfony\Component\Form\Extension\Core\Type\ CollectionType' , [], Guess::LOW_CONFIDENCE );
189
+ case Count::class :
190
+ return new TypeGuess (CollectionType::class , [], Guess::LOW_CONFIDENCE );
158
191
159
- case ' Symfony\Component\Validator\Constraints\ IsTrue' :
160
- case ' Symfony\Component\Validator\Constraints\ IsFalse' :
161
- return new TypeGuess (' Symfony\Component\Form\Extension\Core\Type\ CheckboxType' , [], Guess::MEDIUM_CONFIDENCE );
192
+ case IsTrue::class :
193
+ case IsFalse::class :
194
+ return new TypeGuess (CheckboxType::class , [], Guess::MEDIUM_CONFIDENCE );
162
195
}
163
196
164
197
return null ;
@@ -183,19 +216,19 @@ public function guessRequiredForConstraint(Constraint $constraint): ?ValueGuess
183
216
public function guessMaxLengthForConstraint (Constraint $ constraint ): ?ValueGuess
184
217
{
185
218
switch (\get_class ($ constraint )) {
186
- case ' Symfony\Component\Validator\Constraints\ Length' :
219
+ case Length::class :
187
220
if (is_numeric ($ constraint ->max )) {
188
221
return new ValueGuess ($ constraint ->max , Guess::HIGH_CONFIDENCE );
189
222
}
190
223
break ;
191
224
192
- case ' Symfony\Component\Validator\Constraints\ Type' :
225
+ case Type::class :
193
226
if (\in_array ($ constraint ->type , ['double ' , 'float ' , 'numeric ' , 'real ' ])) {
194
227
return new ValueGuess (null , Guess::MEDIUM_CONFIDENCE );
195
228
}
196
229
break ;
197
230
198
- case ' Symfony\Component\Validator\Constraints\ Range' :
231
+ case Range::class :
199
232
if (is_numeric ($ constraint ->max )) {
200
233
return new ValueGuess (\strlen ((string ) $ constraint ->max ), Guess::LOW_CONFIDENCE );
201
234
}
@@ -211,27 +244,27 @@ public function guessMaxLengthForConstraint(Constraint $constraint): ?ValueGuess
211
244
public function guessPatternForConstraint (Constraint $ constraint ): ?ValueGuess
212
245
{
213
246
switch (\get_class ($ constraint )) {
214
- case ' Symfony\Component\Validator\Constraints\ Length' :
247
+ case Length::class :
215
248
if (is_numeric ($ constraint ->min )) {
216
249
return new ValueGuess (sprintf ('.{%s,} ' , (string ) $ constraint ->min ), Guess::LOW_CONFIDENCE );
217
250
}
218
251
break ;
219
252
220
- case ' Symfony\Component\Validator\Constraints\ Regex' :
253
+ case Regex::class :
221
254
$ htmlPattern = $ constraint ->getHtmlPattern ();
222
255
223
256
if (null !== $ htmlPattern ) {
224
257
return new ValueGuess ($ htmlPattern , Guess::HIGH_CONFIDENCE );
225
258
}
226
259
break ;
227
260
228
- case ' Symfony\Component\Validator\Constraints\ Range' :
261
+ case Range::class :
229
262
if (is_numeric ($ constraint ->min )) {
230
263
return new ValueGuess (sprintf ('.{%s,} ' , \strlen ((string ) $ constraint ->min )), Guess::LOW_CONFIDENCE );
231
264
}
232
265
break ;
233
266
234
- case ' Symfony\Component\Validator\Constraints\ Type' :
267
+ case Type::class :
235
268
if (\in_array ($ constraint ->type , ['double ' , 'float ' , 'numeric ' , 'real ' ])) {
236
269
return new ValueGuess (null , Guess::MEDIUM_CONFIDENCE );
237
270
}
0 commit comments