FormViewIterator.php 1.4 KB

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