1 | <?php |
||
12 | class Cart implements CurrencyAwareInterface |
||
13 | { |
||
14 | use CurrencyAwareTrait; |
||
15 | |||
16 | /** |
||
17 | * @var string |
||
18 | */ |
||
19 | protected $identifier; |
||
20 | |||
21 | /** |
||
22 | * @var \jamesdb\Cart\Storage\StorageInterface |
||
23 | */ |
||
24 | protected $storage; |
||
25 | |||
26 | /** |
||
27 | * Cart Contents. |
||
28 | * |
||
29 | * @var array |
||
30 | */ |
||
31 | protected $contents = []; |
||
32 | |||
33 | /** |
||
34 | * Event Emitter. |
||
35 | * |
||
36 | * @var \League\Event\Emitter |
||
37 | */ |
||
38 | protected $eventEmitter; |
||
39 | |||
40 | /** |
||
41 | * @var callback |
||
42 | */ |
||
43 | protected $formatterCallback; |
||
44 | |||
45 | /** |
||
46 | * Constructor. |
||
47 | 60 | * |
|
48 | * @param string $identifier |
||
49 | 60 | * @param \jamesdb\Cart\Storage\StorageInterface $storage |
|
50 | 60 | */ |
|
51 | 60 | public function __construct($identifier, StorageInterface $storage) |
|
61 | |||
62 | /** |
||
63 | * Add an Event Listener to the Emitter. |
||
64 | * |
||
65 | 9 | * @param string $eventName |
|
66 | * @param callable|object $listener |
||
67 | 9 | * |
|
68 | 9 | * @return void |
|
69 | */ |
||
70 | public function addEventListener($eventName, $listener) |
||
74 | |||
75 | 36 | /** |
|
76 | * Returns the Event Emitter. |
||
77 | 36 | * |
|
78 | * @return \League\Event\Emitter |
||
79 | */ |
||
80 | public function getEventEmitter() |
||
84 | |||
85 | /** |
||
86 | * Set the formatter callback. |
||
87 | 36 | * |
|
88 | * @param callable $callback |
||
89 | 36 | */ |
|
90 | public function setFormatterCallback(callable $callback) |
||
94 | 36 | ||
95 | /** |
||
96 | * Get the formatter callback. |
||
97 | 36 | * |
|
98 | * @throws \jamesdb\Cart\Exception\CartFormatterCallbackException |
||
99 | 36 | * |
|
100 | * @return callable |
||
101 | 36 | */ |
|
102 | public function getFormatterCallback() |
||
110 | |||
111 | /** |
||
112 | * Add an item. |
||
113 | 9 | * |
|
114 | 3 | * @param \jamesdb\Cart\CartItem $item |
|
115 | 9 | * |
|
116 | * @return string |
||
117 | 9 | */ |
|
118 | 3 | public function add(CartItem $item) |
|
134 | |||
135 | /** |
||
136 | * Remove an item. |
||
137 | * |
||
138 | * @param string $rowId |
||
139 | * |
||
140 | * @throws \jamesdb\Cart\Exception\CartRemoveItemException |
||
141 | * |
||
142 | 9 | * @return boolean |
|
143 | */ |
||
144 | 9 | public function remove($rowId) |
|
162 | |||
163 | /** |
||
164 | * Update an item stored in the Cart. |
||
165 | * |
||
166 | 60 | * @param string $rowId |
|
167 | * @param array $data |
||
168 | 60 | * |
|
169 | * @throws \jamesdb\Cart\Exception\CartUpdateException |
||
170 | 60 | * |
|
171 | 60 | * @return boolean |
|
172 | */ |
||
173 | public function update($rowId, array $data = []) |
||
191 | |||
192 | /** |
||
193 | * Clear the cart. |
||
194 | 3 | * |
|
195 | * @return void |
||
196 | 3 | */ |
|
197 | public function clear() |
||
203 | |||
204 | /** |
||
205 | * Get a specific item from the cart. |
||
206 | * |
||
207 | 3 | * @param string $rowId |
|
208 | * |
||
209 | * @return \jamesdb\Cart\CartItem|null |
||
210 | 3 | */ |
|
211 | 3 | public function getItem($rowId) |
|
219 | |||
220 | /** |
||
221 | 18 | * Return items. |
|
222 | * |
||
223 | 18 | * @return array |
|
224 | */ |
||
225 | public function getItems() |
||
229 | |||
230 | /** |
||
231 | 9 | * Return a filtered array of cart items. |
|
232 | * |
||
233 | 9 | * @param string $key |
|
234 | * @param mixed $value |
||
235 | 9 | * |
|
236 | 9 | * @return array |
|
237 | 9 | */ |
|
238 | public function filter($key, $value) |
||
246 | |||
247 | 9 | /** |
|
248 | * Return the total amount of unique items. |
||
249 | * |
||
250 | * @return integer |
||
251 | */ |
||
252 | public function getTotalUniqueItems() |
||
256 | |||
257 | 3 | /** |
|
258 | * Return the total amount of items. |
||
259 | 3 | * |
|
260 | 3 | * @return integer |
|
261 | 3 | */ |
|
262 | public function getTotalItems() |
||
270 | |||
271 | 3 | /** |
|
272 | * Returns whether the cart is empty. |
||
273 | 3 | * |
|
274 | * @return boolean |
||
275 | 3 | */ |
|
276 | 3 | public function isEmpty() |
|
280 | |||
281 | /** |
||
282 | * Return the price including tax. |
||
283 | * |
||
284 | * @return integer |
||
285 | */ |
||
286 | public function getTotalPrice() |
||
296 | |||
297 | /** |
||
298 | * Return the price excluding tax. |
||
299 | * |
||
300 | * @return integer |
||
301 | */ |
||
302 | public function getTotalPriceExcludingTax() |
||
312 | 6 | ||
313 | 3 | /** |
|
314 | 3 | * Return the carts total tax. |
|
315 | 3 | * |
|
316 | * @return integer |
||
317 | 3 | */ |
|
318 | public function getTotalTax() |
||
328 | 60 | ||
329 | /** |
||
330 | * Restore the cart from storage. |
||
331 | * |
||
332 | * @throws \jamesdb\Cart\Exception\CartRestoreException |
||
333 | * |
||
334 | * @return boolean |
||
335 | */ |
||
336 | 36 | public function restore() |
|
361 | |||
362 | /** |
||
363 | * Export the cart to array. |
||
364 | * |
||
365 | * @return array |
||
366 | */ |
||
367 | public function toArray() |
||
376 | } |
||
377 |
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.