@@ -147,12 +147,9 @@ public function mapViolation(ConstraintViolation $violation, FormInterface $form
147
147
*/
148
148
private function matchChild (FormInterface $ form , PropertyPathIteratorInterface $ it )
149
149
{
150
- // Remember at what property path underneath "data"
151
- // we are looking. Check if there is a child with that
152
- // path, otherwise increase path by one more piece
150
+ $ target = null ;
153
151
$ chunk = '' ;
154
- $ foundChild = null ;
155
- $ foundAtIndex = 0 ;
152
+ $ foundAtIndex = null ;
156
153
157
154
// Construct mapping rules for the given form
158
155
$ rules = array ();
@@ -164,17 +161,11 @@ private function matchChild(FormInterface $form, PropertyPathIteratorInterface $
164
161
}
165
162
}
166
163
167
- // Skip forms inheriting their parent data when iterating the children
168
- $ childIterator = new \RecursiveIteratorIterator (
164
+ $ children = iterator_to_array (new \RecursiveIteratorIterator (
169
165
new InheritDataAwareIterator ($ form )
170
- );
171
-
172
- // Make the path longer until we find a matching child
173
- while (true ) {
174
- if (!$ it ->valid ()) {
175
- return ;
176
- }
166
+ ));
177
167
168
+ while ($ it ->valid ()) {
178
169
if ($ it ->isIndex ()) {
179
170
$ chunk .= '[ ' .$ it ->current ().'] ' ;
180
171
} else {
@@ -196,33 +187,27 @@ private function matchChild(FormInterface $form, PropertyPathIteratorInterface $
196
187
}
197
188
}
198
189
199
- // Test children unless we already found one
200
- if (null === $ foundChild ) {
201
- foreach ($ childIterator as $ child ) {
202
- /* @var FormInterface $child */
203
- $ childPath = (string ) $ child ->getPropertyPath ();
204
-
205
- // Child found, mark as return value
206
- if ($ chunk === $ childPath ) {
207
- $ foundChild = $ child ;
208
- $ foundAtIndex = $ it ->key ();
209
- }
190
+ /** @var FormInterface $child */
191
+ foreach ($ children as $ key => $ child ) {
192
+ $ childPath = (string ) $ child ->getPropertyPath ();
193
+ if ($ childPath === $ chunk ) {
194
+ $ target = $ child ;
195
+ $ foundAtIndex = $ it ->key ();
196
+ } elseif (0 === strpos ($ childPath , $ chunk )) {
197
+ continue ;
210
198
}
199
+
200
+ unset($ children [$ key ]);
211
201
}
212
202
213
- // Add element to the chunk
214
203
$ it ->next ();
204
+ }
215
205
216
- // If we reached the end of the path or if there are no
217
- // more matching mapping rules, return the found child
218
- if (null !== $ foundChild && (!$ it ->valid () || count ($ rules ) === 0 )) {
219
- // Reset index in case we tried to find mapping
220
- // rules further down the path
221
- $ it ->seek ($ foundAtIndex );
222
-
223
- return $ foundChild ;
224
- }
206
+ if (null !== $ foundAtIndex ) {
207
+ $ it ->seek ($ foundAtIndex );
225
208
}
209
+
210
+ return $ target ;
226
211
}
227
212
228
213
/**
0 commit comments