RecursiveFieldIterator.php 1023 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien.potencier@symfony-project.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 Sonata\BaseApplicationBundle\Form;
  11. use Symfony\Component\Form\FormInterface;
  12. /**
  13. * Iterator that traverses fields of a field group
  14. *
  15. * If the iterator encounters a virtual field group, it enters the field
  16. * group and traverses its children as well.
  17. *
  18. * @author Bernhard Schussek <bernhard.schussek@symfony-project.com>
  19. */
  20. class RecursiveFieldIterator extends \IteratorIterator implements \RecursiveIterator
  21. {
  22. protected $counter = 0;
  23. public function __construct(FormInterface $group)
  24. {
  25. parent::__construct($group);
  26. }
  27. public function getChildren()
  28. {
  29. return new self($this->current());
  30. }
  31. public function hasChildren()
  32. {
  33. return $this->current() instanceof FormInterface;
  34. }
  35. }