@@ -52,12 +52,7 @@ public function mapDataToForms($data, $forms)
52
52
$ form ->setData ($ this ->propertyAccessor ->getValue ($ data , $ propertyPath ));
53
53
} catch (AccessException $ e ) {
54
54
// Skip unitialized properties on $data
55
- if (!$ e instanceof UninitializedPropertyException
56
- // For versions without UninitializedPropertyException check the exception message
57
- && (class_exists (UninitializedPropertyException::class) || false === strpos ($ e ->getMessage (), 'You should initialize it ' ))
58
- ) {
59
- throw $ e ;
60
- }
55
+ $ this ->catchUninitializedPropertyException ($ e );
61
56
}
62
57
} else {
63
58
$ form ->setData ($ config ->getData ());
@@ -118,7 +113,24 @@ private function getPropertyValue($data, $propertyPath)
118
113
try {
119
114
return $ this ->propertyAccessor ->getValue ($ data , $ propertyPath );
120
115
} catch (AccessException $ e ) {
116
+
117
+ // The following line might be removed in future versions
118
+ // See https://github.com/symfony/symfony/issues/36754
119
+ $ this ->catchUninitializedPropertyException ($ e );
120
+
121
121
return null ;
122
122
}
123
123
}
124
+
125
+ /**
126
+ * Throw everything but UninitializedPropertyException
127
+ */
128
+ private function catchUninitializedPropertyException (AccessException $ e ) {
129
+ if (!$ e instanceof UninitializedPropertyException
130
+ // For versions without UninitializedPropertyException check the exception message
131
+ && (class_exists (UninitializedPropertyException::class) || false === strpos ($ e ->getMessage (), 'You should initialize it ' ))
132
+ ) {
133
+ throw $ e ;
134
+ }
135
+ }
124
136
}
0 commit comments