bytic /
Collections
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Nip\Collections; |
||
| 4 | |||
| 5 | use ArrayIterator; |
||
| 6 | use JsonSerializable; |
||
| 7 | use Nip\Collections\Legacy\Traits\DeprecatedTraits; |
||
| 8 | |||
| 9 | /** |
||
| 10 | * Class Registry |
||
| 11 | * @package Nip |
||
| 12 | */ |
||
| 13 | abstract class AbstractCollection implements CollectionInterface, JsonSerializable |
||
| 14 | { |
||
| 15 | use Traits\AccessMethodsTrait; |
||
| 16 | use Traits\ArrayAccessTrait; |
||
| 17 | use Traits\EnumeratesValues; |
||
| 18 | use Traits\FilterTrait; |
||
| 19 | use Traits\OperationsOnItemsTrait; |
||
| 20 | use Traits\OperationsTrait; |
||
| 21 | use Traits\SortingTrait; |
||
| 22 | use Traits\TransformMethodsTrait; |
||
| 23 | use DeprecatedTraits; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * @var array |
||
| 27 | */ |
||
| 28 | protected $items = []; |
||
| 29 | |||
| 30 | protected $index = 0; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * Collection constructor. |
||
| 34 | * @param array $items |
||
| 35 | */ |
||
| 36 | public function __construct($items = []) |
||
| 37 | { |
||
| 38 | 40 | if (is_array($items)) { |
|
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 39 | $this->items = $items; |
||
| 40 | 40 | } elseif ($items instanceof AbstractCollection) { |
|
| 41 | 40 | $this->items = $items->toArray(); |
|
| 42 | } |
||
| 43 | } |
||
| 44 | |||
| 45 | 40 | /** |
|
| 46 | * @param $needle |
||
| 47 | * @return bool |
||
| 48 | */ |
||
| 49 | public function contains($needle) |
||
| 50 | { |
||
| 51 | foreach ($this as $key => $value) { |
||
| 52 | if ($value === $needle) { |
||
| 53 | return true; |
||
| 54 | } |
||
| 55 | } |
||
| 56 | return false; |
||
| 57 | } |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @return ArrayIterator |
||
| 61 | */ |
||
| 62 | public function getIterator() |
||
| 63 | { |
||
| 64 | 1 | return new ArrayIterator($this->items); |
|
| 65 | } |
||
| 66 | } |
||
| 67 |