FormViewIterator.php 1.5 KB

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