TestCollection.php 804 B

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. declare(strict_types=1);
  3. namespace TestApp\Collection;
  4. use ArrayIterator;
  5. use Cake\Collection\CollectionInterface;
  6. use Cake\Collection\CollectionTrait;
  7. use InvalidArgumentException;
  8. use IteratorIterator;
  9. use Traversable;
  10. class TestCollection extends IteratorIterator implements CollectionInterface
  11. {
  12. use CollectionTrait;
  13. /**
  14. * @param iterable $items
  15. * @throws \InvalidArgumentException
  16. */
  17. public function __construct(iterable $items)
  18. {
  19. if (is_array($items)) {
  20. $items = new ArrayIterator($items);
  21. }
  22. if (!($items instanceof Traversable)) {
  23. $msg = 'Only an array or \Traversable is allowed for Collection';
  24. throw new InvalidArgumentException($msg);
  25. }
  26. parent::__construct($items);
  27. }
  28. }