1 | <?php |
||
13 | class Cart implements CurrencyAwareInterface |
||
14 | { |
||
15 | use CurrencyAwareTrait; |
||
16 | |||
17 | /** |
||
18 | * @var string |
||
19 | */ |
||
20 | protected $identifier; |
||
21 | |||
22 | /** |
||
23 | * @var \jamesdb\Cart\Storage\StorageInterface |
||
24 | */ |
||
25 | protected $storage; |
||
26 | |||
27 | /** |
||
28 | * Cart Contents. |
||
29 | * |
||
30 | * @var array |
||
31 | */ |
||
32 | protected $contents = []; |
||
33 | |||
34 | /** |
||
35 | * Event Emitter. |
||
36 | * |
||
37 | * @var \League\Event\Emitter |
||
38 | */ |
||
39 | protected $eventEmitter; |
||
40 | |||
41 | /** |
||
42 | * Constructor. |
||
43 | * |
||
44 | * @param string $identifier |
||
45 | * @param \jamesdb\Cart\Storage\StorageInterface $storage |
||
46 | */ |
||
47 | public function __construct($identifier, StorageInterface $storage) |
||
56 | 72 | ||
57 | 72 | /** |
|
58 | * Add an Event Listener to the Emitter. |
||
59 | 72 | * |
|
60 | 72 | * @param string $eventName |
|
61 | * @param callable|object $listener |
||
62 | * |
||
63 | * @return void |
||
64 | */ |
||
65 | public function addEventListener($eventName, $listener) |
||
69 | 3 | ||
70 | 3 | /** |
|
71 | * Returns the Event Emitter. |
||
72 | * |
||
73 | * @return \League\Event\Emitter |
||
74 | */ |
||
75 | public function getEventEmitter() |
||
79 | 9 | ||
80 | /** |
||
81 | * Add an item. |
||
82 | * |
||
83 | * @param \jamesdb\Cart\CartItem $item |
||
84 | * |
||
85 | * @return string |
||
86 | */ |
||
87 | public function add(CartItem $item) |
||
103 | |||
104 | /** |
||
105 | * Remove an item. |
||
106 | * |
||
107 | * @param string $rowId |
||
108 | * |
||
109 | * @throws \jamesdb\Cart\Exception\CartRemoveItemException |
||
110 | * |
||
111 | * @return boolean |
||
112 | 36 | */ |
|
113 | public function remove($rowId) |
||
131 | |||
132 | /** |
||
133 | * Update an item stored in the Cart. |
||
134 | * |
||
135 | * @param string $rowId |
||
136 | * @param array $data |
||
137 | * |
||
138 | 9 | * @throws \jamesdb\Cart\Exception\CartUpdateException |
|
139 | * |
||
140 | 9 | * @return boolean |
|
141 | */ |
||
142 | 9 | public function update($rowId, array $data = []) |
|
160 | |||
161 | /** |
||
162 | * Clear the cart. |
||
163 | * |
||
164 | * @return void |
||
165 | */ |
||
166 | public function clear() |
||
172 | 3 | ||
173 | 3 | /** |
|
174 | 3 | * Get a specific item from the cart. |
|
175 | * |
||
176 | * @param string $rowId |
||
177 | 6 | * |
|
178 | 6 | * @return array|null |
|
179 | 6 | */ |
|
180 | public function getItem($rowId) |
||
188 | |||
189 | /** |
||
190 | * Return items. |
||
191 | 72 | * |
|
192 | * @return array |
||
193 | 72 | */ |
|
194 | public function getItems() |
||
198 | |||
199 | /** |
||
200 | * Return a filtered array of cart items. |
||
201 | * |
||
202 | * @param string $key |
||
203 | * @param mixed $value |
||
204 | * |
||
205 | 45 | * @return array |
|
206 | */ |
||
207 | 45 | public function filter($key, $value) |
|
215 | |||
216 | /** |
||
217 | * Return the total amount of unique items. |
||
218 | * |
||
219 | 3 | * @return integer |
|
220 | */ |
||
221 | 3 | public function getTotalUniqueItems() |
|
225 | |||
226 | /** |
||
227 | * Return the total amount of items. |
||
228 | * |
||
229 | * @return integer |
||
230 | */ |
||
231 | public function getTotalItems() |
||
239 | |||
240 | /** |
||
241 | * Returns whether the cart is empty. |
||
242 | * |
||
243 | * @return boolean |
||
244 | */ |
||
245 | public function isEmpty() |
||
249 | |||
250 | /** |
||
251 | * Return the price including tax. |
||
252 | * |
||
253 | * @return integer |
||
254 | */ |
||
255 | public function getTotalPrice() |
||
265 | |||
266 | /** |
||
267 | * Return the price excluding tax. |
||
268 | * |
||
269 | * @return integer |
||
270 | 9 | */ |
|
271 | public function getTotalPriceExcludingTax() |
||
281 | |||
282 | 3 | /** |
|
283 | * Return the carts total tax. |
||
284 | 3 | * |
|
285 | 3 | * @return integer |
|
286 | 3 | */ |
|
287 | public function getTotalTax() |
||
297 | |||
298 | 3 | /** |
|
299 | * Restore the cart from storage. |
||
300 | 3 | * |
|
301 | 3 | * @throws \jamesdb\Cart\Exception\CartRestoreException |
|
302 | 3 | * |
|
303 | * @return boolean |
||
304 | 3 | */ |
|
305 | public function restore() |
||
330 | 72 | ||
331 | /** |
||
332 | 72 | * Export the cart to array. |
|
333 | * |
||
334 | 72 | * @return array |
|
335 | 18 | */ |
|
336 | public function toArray() |
||
345 | } |
||
346 |
Since your code implements the magic setter
_set
, this function will be called for any write access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.Since the property has write access only, you can use the @property-write annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.