23
23
class FormValidator extends ConstraintValidator
24
24
{
25
25
/**
26
- * @var \SplObjectStorage
26
+ * @var array
27
27
*/
28
- private static $ clickedButtons ;
28
+ private static $ clickedButtons = array () ;
29
29
30
30
/**
31
31
* @var ServerParams
@@ -52,15 +52,9 @@ public function validate($form, Constraint $constraint)
52
52
return ;
53
53
}
54
54
55
- if (null === static ::$ clickedButtons ) {
56
- static ::$ clickedButtons = new \SplObjectStorage ();
57
- }
58
-
59
55
// If the form was previously validated, remove it from the cache in
60
56
// case the clicked button has changed
61
- if (static ::$ clickedButtons ->contains ($ form )) {
62
- static ::$ clickedButtons ->detach ($ form );
63
- }
57
+ unset(self ::$ clickedButtons [spl_object_hash ($ form )]);
64
58
65
59
/* @var FormInterface $form */
66
60
$ config = $ form ->getConfig ();
@@ -188,16 +182,17 @@ private static function allowDataWalking(FormInterface $form)
188
182
private static function getValidationGroups (FormInterface $ form )
189
183
{
190
184
$ root = $ form ->getRoot ();
185
+ $ rootHash = spl_object_hash ($ root );
191
186
192
187
// Determine the clicked button of the complete form tree
193
- if (!static ::$ clickedButtons-> contains ( $ root )) {
188
+ if (!array_key_exists ( $ rootHash , self ::$ clickedButtons )) {
194
189
// Only call findClickedButton() once to prevent an exponential
195
190
// runtime
196
191
// https://github.com/symfony/symfony/issues/8317
197
- static ::$ clickedButtons-> attach ( $ root , self ::findClickedButton ($ root) );
192
+ self ::$ clickedButtons[ $ rootHash ] = self ::findClickedButton ($ root );
198
193
}
199
194
200
- $ button = static ::$ clickedButtons-> offsetGet ( $ root ) ;
195
+ $ button = self ::$ clickedButtons[ $ rootHash ] ;
201
196
202
197
if (null !== $ button ) {
203
198
$ groups = $ button ->getConfig ()->getOption ('validation_groups ' );
0 commit comments