InheritDataAwareIterator.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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\Util;
  11. /**
  12. * Iterator that traverses an array of forms.
  13. *
  14. * Contrary to \ArrayIterator, this iterator recognizes changes in the original
  15. * array during iteration.
  16. *
  17. * You can wrap the iterator into a {@link \RecursiveIteratorIterator} in order to
  18. * enter any child form that inherits its parent's data and iterate the children
  19. * of that form as well.
  20. *
  21. * @author Bernhard Schussek <bschussek@gmail.com>
  22. */
  23. class InheritDataAwareIterator extends \IteratorIterator implements \RecursiveIterator
  24. {
  25. /**
  26. * {@inheritdoc}
  27. */
  28. public function getChildren()
  29. {
  30. return new static($this->current());
  31. }
  32. /**
  33. * @return bool
  34. */
  35. public function hasChildren()
  36. {
  37. return (bool) $this->current()->getConfig()->getInheritData();
  38. }
  39. }