FormViewIterator.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. protected $formView;
  20. protected $iterator;
  21. /**
  22. * @param \Symfony\Component\Form\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. }