FormViewIterator.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /*
  3. * This file is part of the Sonata project.
  4. *
  5. * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
  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\AdminBundle\Util;
  11. use Symfony\Component\Form\FormView;
  12. class FormViewIterator implements \RecursiveIterator
  13. {
  14. protected $formView;
  15. public function __construct(FormView $formView)
  16. {
  17. $this->iterator = $formView->getIterator();
  18. }
  19. public function getChildren()
  20. {
  21. return new FormViewIterator($this->current());
  22. }
  23. public function hasChildren()
  24. {
  25. return $this->current()->hasChildren();
  26. }
  27. public function current()
  28. {
  29. return $this->iterator->current();
  30. }
  31. public function next()
  32. {
  33. return $this->iterator->next();
  34. }
  35. public function key()
  36. {
  37. return $this->current()->get('id');
  38. }
  39. public function valid()
  40. {
  41. return $this->iterator->valid();
  42. }
  43. public function rewind()
  44. {
  45. return $this->iterator->rewind();
  46. }
  47. }