FormViewIterator.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. /*
  3. * This file is part of the Sonata Project package.
  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. /**
  13. * @author Thomas Rabaix <thomas.rabaix@sonata-project.org>
  14. */
  15. class FormViewIterator implements \RecursiveIterator
  16. {
  17. /**
  18. * @var \ArrayIterator
  19. */
  20. protected $iterator;
  21. /**
  22. * @param FormView $formView
  23. */
  24. public function __construct(FormView $formView)
  25. {
  26. $this->iterator = $formView->getIterator();
  27. }
  28. /**
  29. * {@inheritdoc}
  30. */
  31. public function getChildren()
  32. {
  33. return new self($this->current());
  34. }
  35. /**
  36. * {@inheritdoc}
  37. */
  38. public function hasChildren()
  39. {
  40. return count($this->current()->children) > 0;
  41. }
  42. /**
  43. * {@inheritdoc}
  44. */
  45. public function current()
  46. {
  47. return $this->iterator->current();
  48. }
  49. /**
  50. * {@inheritdoc}
  51. */
  52. public function next()
  53. {
  54. $this->iterator->next();
  55. }
  56. /**
  57. * {@inheritdoc}
  58. */
  59. public function key()
  60. {
  61. return $this->current()->vars['id'];
  62. }
  63. /**
  64. * {@inheritdoc}
  65. */
  66. public function valid()
  67. {
  68. return $this->iterator->valid();
  69. }
  70. /**
  71. * {@inheritdoc}
  72. */
  73. public function rewind()
  74. {
  75. $this->iterator->rewind();
  76. }
  77. }