File tree 2 files changed +81
-58
lines changed
src/Symfony/Component/Form/Util 2 files changed +81
-58
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of the Symfony package.
5
+ *
6
+ * (c) Fabien Potencier <fabien@symfony.com>
7
+ *
8
+ * For the full copyright and license information, please view the LICENSE
9
+ * file that was distributed with this source code.
10
+ */
11
+
12
+ namespace Symfony \Component \Form \Util ;
13
+
14
+ /**
15
+ * Iterator that traverses an array.
16
+ *
17
+ * Contrary to {@link \ArrayIterator}, this iterator recognizes changes in the
18
+ * original array during iteration.
19
+ *
20
+ * @author Bernhard Schussek <bschussek@gmail.com>
21
+ */
22
+ class ReferencingArrayIterator implements \Iterator
23
+ {
24
+ /**
25
+ * @var array
26
+ */
27
+ private $ array ;
28
+
29
+ /**
30
+ * Creates a new iterator.
31
+ *
32
+ * @param array $array An array
33
+ */
34
+ public function __construct (array &$ array )
35
+ {
36
+ $ this ->array = &$ array ;
37
+ }
38
+
39
+ /**
40
+ *{@inheritdoc}
41
+ */
42
+ public function current ()
43
+ {
44
+ return current ($ this ->array );
45
+ }
46
+
47
+ /**
48
+ *{@inheritdoc}
49
+ */
50
+ public function next ()
51
+ {
52
+ next ($ this ->array );
53
+ }
54
+
55
+ /**
56
+ *{@inheritdoc}
57
+ */
58
+ public function key ()
59
+ {
60
+ return key ($ this ->array );
61
+ }
62
+
63
+ /**
64
+ *{@inheritdoc}
65
+ */
66
+ public function valid ()
67
+ {
68
+ return null !== key ($ this ->array );
69
+ }
70
+
71
+ /**
72
+ *{@inheritdoc}
73
+ */
74
+ public function rewind ()
75
+ {
76
+ reset ($ this ->array );
77
+ }
78
+ }
Original file line number Diff line number Diff line change 14
14
/**
15
15
* Iterator that traverses an array of forms.
16
16
*
17
- * Contrary to \ArrayIterator, this iterator recognizes changes in the original
18
- * array during iteration.
17
+ * Contrary to {@link \ArrayIterator} , this iterator recognizes changes in the
18
+ * original array during iteration.
19
19
*
20
20
* You can wrap the iterator into a {@link \RecursiveIterator} in order to
21
21
* enter any virtual child form and iterate the children of that virtual form.
22
22
*
23
23
* @author Bernhard Schussek <bschussek@gmail.com>
24
24
*/
25
- class VirtualFormAwareIterator implements \RecursiveIterator
25
+ class VirtualFormAwareIterator extends ReferencingArrayIterator implements \RecursiveIterator
26
26
{
27
- /**
28
- * @var \Symfony\Component\Form\FormInterface[]
29
- */
30
- private $ forms ;
31
-
32
- /**
33
- * Creates a new iterator.
34
- *
35
- * @param \Symfony\Component\Form\FormInterface[] $forms An array of forms
36
- */
37
- public function __construct (array &$ forms )
38
- {
39
- $ this ->forms = &$ forms ;
40
- }
41
-
42
- /**
43
- *{@inheritdoc}
44
- */
45
- public function current ()
46
- {
47
- return current ($ this ->forms );
48
- }
49
-
50
- /**
51
- *{@inheritdoc}
52
- */
53
- public function next ()
54
- {
55
- next ($ this ->forms );
56
- }
57
-
58
- /**
59
- *{@inheritdoc}
60
- */
61
- public function key ()
62
- {
63
- return key ($ this ->forms );
64
- }
65
-
66
- /**
67
- *{@inheritdoc}
68
- */
69
- public function valid ()
70
- {
71
- return null !== key ($ this ->forms );
72
- }
73
-
74
- /**
75
- *{@inheritdoc}
76
- */
77
- public function rewind ()
78
- {
79
- reset ($ this ->forms );
80
- }
81
-
82
27
/**
83
28
*{@inheritdoc}
84
29
*/
You can’t perform that action at this time.
0 commit comments