CerEndPointIterator.inc 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. /**
  3. * @file
  4. * Contains CerEndPointIterator.
  5. */
  6. /**
  7. * @class
  8. * The purpose of this iterator is to wrap around all the "endpoints" in a field chain.
  9. * An endpoint is a CerFieldHandler for a field that hasn't got a child. This is necessary
  10. * in order to support infinite levels of embedded entities (read: field collections).
  11. * This class is only instantiated by CerFieldChainHandler if its initial field handler
  12. * has a child (@see CerFieldHandler::__construct()).
  13. */
  14. class CerEndPointIterator implements RecursiveIterator {
  15. /**
  16. * @var CerField
  17. */
  18. protected $field;
  19. /**
  20. * @var CerFieldHandler
  21. */
  22. protected $handler;
  23. public function __construct(CerField $field, EntityDrupalWrapper $entity) {
  24. $this->field = $field;
  25. $this->handler = $field->getHandler($entity);
  26. }
  27. /**
  28. * Implements Iterator::current().
  29. */
  30. public function current() {
  31. return $this->field->child()->getHandler($this->handler->current());
  32. }
  33. /**
  34. * Implements Iterator::key().
  35. */
  36. public function key() {
  37. return $this->handler->key();
  38. }
  39. /**
  40. * Implements Iterator::next().
  41. */
  42. public function next() {
  43. $this->handler->next();
  44. }
  45. /**
  46. * Implements Iterator::rewind().
  47. */
  48. public function rewind() {
  49. $this->handler->rewind();
  50. }
  51. /**
  52. * Implements Iterator::handler().
  53. */
  54. public function valid() {
  55. return $this->handler->valid();
  56. }
  57. /**
  58. * Implements RecursiveIterator::hasChildren().
  59. */
  60. public function hasChildren() {
  61. return ($this->field->child() instanceof CerEntityContainerInterface);
  62. }
  63. /**
  64. * Implements RecursiveIterator::getChildren().
  65. */
  66. public function getChildren() {
  67. return new CerEndPointIterator($this->field->child(), $this->handler->current());
  68. }
  69. }