1 | <?php |
||
18 | class Bag extends AbstractCollection |
||
19 | { |
||
20 | /** |
||
21 | * The collection elements |
||
22 | * |
||
23 | * @var array |
||
24 | */ |
||
25 | protected $elements = []; |
||
26 | |||
27 | /** |
||
28 | * Constructor |
||
29 | * |
||
30 | * @param array $elements |
||
31 | */ |
||
32 | 4 | public function __construct(array $elements = []) |
|
36 | |||
37 | /** |
||
38 | * Ensure the element exists in the collection |
||
39 | * |
||
40 | * Returns true if the collection can contain duplicates, |
||
41 | * and false if it cannot. |
||
42 | * |
||
43 | * By default this method will use strict comparison checking, passing false |
||
44 | * in will use a double equals (==) instead. |
||
45 | * |
||
46 | * @param mixed $element |
||
47 | * @param bool $strict |
||
48 | * @return bool |
||
49 | */ |
||
50 | 12 | public function add($element, bool $strict = true): bool |
|
56 | |||
57 | /** |
||
58 | * Removes all elements from a collection |
||
59 | * |
||
60 | * @return void |
||
61 | */ |
||
62 | 1 | public function clear() |
|
66 | |||
67 | /** |
||
68 | * Returns true if the collection contains element |
||
69 | * |
||
70 | * By default this method will use strict comparison checking, passing false |
||
71 | * in will use a double equals (==) instead. |
||
72 | * |
||
73 | * @param mixed $element |
||
74 | * @param bool $strict |
||
75 | * @return bool |
||
76 | */ |
||
77 | 3 | public function contains($element, bool $strict = true): bool |
|
81 | |||
82 | /** |
||
83 | * Removes object if it exists |
||
84 | * |
||
85 | * By default this method will use strict comparison checking, passing false |
||
86 | * in will use a double equals (==) instead. |
||
87 | * |
||
88 | * Returns true if the element was removed |
||
89 | * |
||
90 | * @param mixed $element |
||
91 | * @param bool $strict |
||
92 | * @return bool |
||
93 | */ |
||
94 | 3 | public function remove($element, bool $strict = true): bool |
|
106 | |||
107 | /** |
||
108 | * Returns an array of all elements in the collection |
||
109 | * |
||
110 | * @return array |
||
111 | */ |
||
112 | 5 | public function toArray(): array |
|
116 | |||
117 | /** |
||
118 | * Filter the collection using closure |
||
119 | * |
||
120 | * The closure will get passed each element. Returning true from the |
||
121 | * closure will include that element in the new collection. |
||
122 | * |
||
123 | * @param callable $filter |
||
124 | * @return CollectionInterface |
||
125 | */ |
||
126 | 1 | public function filter(callable $filter): CollectionInterface |
|
130 | |||
131 | /** |
||
132 | * Returns the size of the collection |
||
133 | * |
||
134 | * @return int |
||
135 | */ |
||
136 | 9 | public function count(): int |
|
140 | |||
141 | /** |
||
142 | * Retrieve an external iterator |
||
143 | * |
||
144 | * @return ArrayIterator |
||
145 | */ |
||
146 | 1 | public function getIterator(): ArrayIterator |
|
150 | } |
||
151 |