ArrayNode.php 803 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. namespace PHPHtmlParser\Dom;
  3. use Countable;
  4. use ArrayIterator;
  5. use IteratorAggregate;
  6. /**
  7. * Dom node object which will allow users to use it as
  8. * an array.
  9. */
  10. abstract class ArrayNode extends AbstractNode implements IteratorAggregate, Countable
  11. {
  12. /**
  13. * Gets the iterator
  14. *
  15. * @return ArrayIterator
  16. */
  17. public function getIterator(): ArrayIterator
  18. {
  19. return new ArrayIterator($this->getIteratorArray());
  20. }
  21. /**
  22. * Returns the count of the iterator array.
  23. *
  24. * @return int
  25. */
  26. public function count(): int
  27. {
  28. return count($this->getIteratorArray());
  29. }
  30. /**
  31. * Returns the array to be used the the iterator.
  32. *
  33. * @return array
  34. */
  35. abstract protected function getIteratorArray(): array;
  36. }