FormViewIterator.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. /**
  16. * @param \Symfony\Component\Form\FormView $formView
  17. */
  18. public function __construct(FormView $formView)
  19. {
  20. $this->iterator = $formView->getIterator();
  21. }
  22. /**
  23. * {@inheritDoc}
  24. */
  25. public function getChildren()
  26. {
  27. return new FormViewIterator($this->current());
  28. }
  29. /**
  30. * {@inheritDoc}
  31. */
  32. public function hasChildren()
  33. {
  34. return $this->current()->hasChildren();
  35. }
  36. /**
  37. * {@inheritDoc}
  38. */
  39. public function current()
  40. {
  41. return $this->iterator->current();
  42. }
  43. /**
  44. * {@inheritDoc}
  45. */
  46. public function next()
  47. {
  48. $this->iterator->next();
  49. }
  50. /**
  51. * {@inheritDoc}
  52. */
  53. public function key()
  54. {
  55. return $this->current()->get('id');
  56. }
  57. /**
  58. * {@inheritDoc}
  59. */
  60. public function valid()
  61. {
  62. return $this->iterator->valid();
  63. }
  64. /**
  65. * {@inheritDoc}
  66. */
  67. public function rewind()
  68. {
  69. $this->iterator->rewind();
  70. }
  71. }