diff --git a/src/Symfony/Component/Form/Util/ReferencingArrayIterator.php b/src/Symfony/Component/Form/Util/ReferencingArrayIterator.php new file mode 100644 index 0000000000..9bb64d79d2 --- /dev/null +++ b/src/Symfony/Component/Form/Util/ReferencingArrayIterator.php @@ -0,0 +1,78 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Form\Util; + +/** + * Iterator that traverses an array. + * + * Contrary to {@link \ArrayIterator}, this iterator recognizes changes in the + * original array during iteration. + * + * @author Bernhard Schussek + */ +class ReferencingArrayIterator implements \Iterator +{ + /** + * @var array + */ + private $array; + + /** + * Creates a new iterator. + * + * @param array $array An array + */ + public function __construct(array &$array) + { + $this->array = &$array; + } + + /** + *{@inheritdoc} + */ + public function current() + { + return current($this->array); + } + + /** + *{@inheritdoc} + */ + public function next() + { + next($this->array); + } + + /** + *{@inheritdoc} + */ + public function key() + { + return key($this->array); + } + + /** + *{@inheritdoc} + */ + public function valid() + { + return null !== key($this->array); + } + + /** + *{@inheritdoc} + */ + public function rewind() + { + reset($this->array); + } +} diff --git a/src/Symfony/Component/Form/Util/VirtualFormAwareIterator.php b/src/Symfony/Component/Form/Util/VirtualFormAwareIterator.php index 9b9abb36e7..2648c3a501 100644 --- a/src/Symfony/Component/Form/Util/VirtualFormAwareIterator.php +++ b/src/Symfony/Component/Form/Util/VirtualFormAwareIterator.php @@ -14,71 +14,16 @@ namespace Symfony\Component\Form\Util; /** * Iterator that traverses an array of forms. * - * Contrary to \ArrayIterator, this iterator recognizes changes in the original - * array during iteration. + * Contrary to {@link \ArrayIterator}, this iterator recognizes changes in the + * original array during iteration. * * You can wrap the iterator into a {@link \RecursiveIterator} in order to * enter any virtual child form and iterate the children of that virtual form. * * @author Bernhard Schussek */ -class VirtualFormAwareIterator implements \RecursiveIterator +class VirtualFormAwareIterator extends ReferencingArrayIterator implements \RecursiveIterator { - /** - * @var \Symfony\Component\Form\FormInterface[] - */ - private $forms; - - /** - * Creates a new iterator. - * - * @param \Symfony\Component\Form\FormInterface[] $forms An array of forms - */ - public function __construct(array &$forms) - { - $this->forms = &$forms; - } - - /** - *{@inheritdoc} - */ - public function current() - { - return current($this->forms); - } - - /** - *{@inheritdoc} - */ - public function next() - { - next($this->forms); - } - - /** - *{@inheritdoc} - */ - public function key() - { - return key($this->forms); - } - - /** - *{@inheritdoc} - */ - public function valid() - { - return null !== key($this->forms); - } - - /** - *{@inheritdoc} - */ - public function rewind() - { - reset($this->forms); - } - /** *{@inheritdoc} */