1 | <?php |
||
18 | class Bag implements \IteratorAggregate |
||
19 | { |
||
20 | /** |
||
21 | * @var mixed[] |
||
22 | */ |
||
23 | protected $items; |
||
24 | |||
25 | /** |
||
26 | * Initialise the object |
||
27 | * |
||
28 | * @param array $items Initial items to create the Bag with. |
||
29 | */ |
||
30 | public function __construct($items = array()) |
||
34 | |||
35 | /** |
||
36 | * Add an item to the bag |
||
37 | * |
||
38 | * @param mixed $key |
||
39 | * @param mixed $value |
||
40 | * @return $this |
||
41 | */ |
||
42 | public function add($key, $value) |
||
47 | |||
48 | /** |
||
49 | * Get an item from the bag by key, optionally returning a default if the key is not found. |
||
50 | * |
||
51 | * @param mixed $key |
||
52 | * @param mixed $default |
||
53 | * @return mixed|null |
||
54 | */ |
||
55 | public function get($key, $default = null) |
||
63 | |||
64 | /** |
||
65 | * Check if the bag contains a given key |
||
66 | * |
||
67 | * @param mixed $key |
||
68 | * @return bool |
||
69 | */ |
||
70 | public function has($key) |
||
74 | |||
75 | /** |
||
76 | * If the bag contains the given key, return the value, then remove it from the bag. |
||
77 | * |
||
78 | * @param $key |
||
79 | * @return mixed|null |
||
80 | */ |
||
81 | public function remove($key) |
||
91 | |||
92 | /** |
||
93 | * @return \ArrayIterator |
||
94 | */ |
||
95 | public function getIterator() |
||
99 | |||
100 | /** |
||
101 | * Get the underlying array of the contents of the bag. |
||
102 | * |
||
103 | * @return array |
||
104 | */ |
||
105 | public function all() |
||
109 | } |
||
110 |