forked from DesignPatternsPHP/DesignPatternsPHP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ShippingOrder.php
50 lines (44 loc) · 1014 Bytes
/
ShippingOrder.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
namespace DesignPatterns\Behavioral\State;
/**
* Class ShippingOrder.
*/
class ShippingOrder implements OrderInterface
{
/**
* @var array
*/
private $order;
/**
* @param array $order
*
* @throws \Exception
*/
public function __construct(array $order)
{
if (empty($order)) {
throw new \Exception('Order can not be empty!');
}
$this->order = $order;
}
/**
* @throws \Exception
*
* @return mixed|void
*/
public function shipOrder()
{
//Can not ship the order which status is shipping, throw exception;
throw new \Exception('Can not ship the order which status is shipping!');
}
/**
* @return mixed
*/
public function completeOrder()
{
$this->order['status'] = 'completed';
$this->order['updatedTime'] = time();
// Setting the new order status into database;
return $this->updateOrder($this->order);
}
}