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 | * @param mixed $element |
||
44 | * @return bool |
||
45 | */ |
||
46 | 28 | public function add($element): bool |
|
52 | |||
53 | /** |
||
54 | * Removes all elements from a collection |
||
55 | * |
||
56 | * @return void |
||
57 | */ |
||
58 | 1 | public function clear() |
|
62 | |||
63 | /** |
||
64 | * Removes object if it exists |
||
65 | * |
||
66 | * Returns true if the element was removed |
||
67 | * |
||
68 | * @param mixed $element |
||
69 | * @return bool |
||
70 | */ |
||
71 | 8 | public function remove($element): bool |
|
83 | |||
84 | /** |
||
85 | * Returns an array of all elements in the collection |
||
86 | * |
||
87 | * @return array |
||
88 | */ |
||
89 | 31 | public function toArray(): array |
|
93 | |||
94 | /** |
||
95 | * Filter the collection using closure |
||
96 | * |
||
97 | * The closure will get passed each element. Returning true from the |
||
98 | * closure will include that element in the new collection. |
||
99 | * |
||
100 | * @param callable $filter |
||
101 | * @return CollectionInterface |
||
102 | */ |
||
103 | 1 | public function filter(callable $filter): CollectionInterface |
|
107 | |||
108 | /** |
||
109 | * Retrieve an external iterator |
||
110 | * |
||
111 | * @return ArrayIterator |
||
112 | */ |
||
113 | 8 | public function getIterator(): ArrayIterator |
|
117 | } |
||
118 |