BundledComponentCollectionIterator.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php declare(strict_types = 1);
  2. /*
  3. * This file is part of PharIo\Manifest.
  4. *
  5. * Copyright (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de> and contributors
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. *
  10. */
  11. namespace PharIo\Manifest;
  12. use Iterator;
  13. use function count;
  14. /** @template-implements Iterator<int,BundledComponent> */
  15. class BundledComponentCollectionIterator implements Iterator {
  16. /** @var BundledComponent[] */
  17. private $bundledComponents;
  18. /** @var int */
  19. private $position = 0;
  20. public function __construct(BundledComponentCollection $bundledComponents) {
  21. $this->bundledComponents = $bundledComponents->getBundledComponents();
  22. }
  23. public function rewind(): void {
  24. $this->position = 0;
  25. }
  26. public function valid(): bool {
  27. return $this->position < count($this->bundledComponents);
  28. }
  29. public function key(): int {
  30. return $this->position;
  31. }
  32. public function current(): BundledComponent {
  33. return $this->bundledComponents[$this->position];
  34. }
  35. public function next(): void {
  36. $this->position++;
  37. }
  38. }