1 | <?php |
||
19 | class Collection |
||
20 | { |
||
21 | /** |
||
22 | * Collection data. |
||
23 | * |
||
24 | * @var array |
||
25 | */ |
||
26 | protected $data = []; |
||
27 | |||
28 | /** |
||
29 | * Collection constructor. |
||
30 | * |
||
31 | * @param array $initialData |
||
32 | * |
||
33 | * @throws \InvalidArgumentException |
||
34 | */ |
||
35 | public function __construct(array $initialData = []) |
||
41 | |||
42 | /** |
||
43 | * Collection data existence. |
||
44 | * |
||
45 | * @param string $key |
||
46 | * |
||
47 | * @return bool |
||
48 | */ |
||
49 | public function has(string $key) : bool |
||
53 | |||
54 | /** |
||
55 | * Get all data. |
||
56 | * |
||
57 | * @return array |
||
58 | */ |
||
59 | public function getAll() : array |
||
63 | |||
64 | /** |
||
65 | * Retrieve collection data. |
||
66 | * |
||
67 | * @param string $key |
||
68 | * @param mixed|null $default |
||
69 | * |
||
70 | * @return mixed |
||
71 | */ |
||
72 | public function get(string $key, $default = null) |
||
76 | |||
77 | /** |
||
78 | * Set collection data. |
||
79 | * |
||
80 | * @param string $key |
||
81 | * @param mixed $value |
||
82 | * |
||
83 | * @throws \InvalidArgumentException |
||
84 | */ |
||
85 | public function set(string $key, $value) |
||
91 | |||
92 | /** |
||
93 | * Verify only scalar values allowed. |
||
94 | * |
||
95 | * @param string|int|float|bool|array $value |
||
96 | * |
||
97 | * @throws \InvalidArgumentException |
||
98 | */ |
||
99 | final protected function verifyScalarValue($value) |
||
111 | |||
112 | /** |
||
113 | * Remove collection data. |
||
114 | * |
||
115 | * @param string $key |
||
116 | */ |
||
117 | public function remove(string $key) |
||
123 | |||
124 | /** |
||
125 | * Remove all collection data. |
||
126 | */ |
||
127 | public function clear() |
||
131 | } |
||
132 |