RecursiveFieldIterator.php 965 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Form;
  11. /**
  12. * Iterator that traverses fields of a field group
  13. *
  14. * If the iterator encounters a virtual field group, it enters the field
  15. * group and traverses its children as well.
  16. *
  17. * @author Bernhard Schussek <bernhard.schussek@symfony.com>
  18. */
  19. class RecursiveFieldIterator extends \IteratorIterator implements \RecursiveIterator
  20. {
  21. public function __construct(FormInterface $group)
  22. {
  23. parent::__construct($group);
  24. }
  25. public function getChildren()
  26. {
  27. return new self($this->current());
  28. }
  29. public function hasChildren()
  30. {
  31. return $this->current() instanceof FormInterface
  32. && $this->current()->getAttribute('virtual');
  33. }
  34. }