-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathOrder.php
executable file
·81 lines (68 loc) · 1.72 KB
/
Order.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
/**
* PHP Billing Library
*
* @link https://github.com/hiqdev/php-billing
* @package php-billing
* @license BSD-3-Clause
* @copyright Copyright (c) 2017-2020, HiQDev (http://hiqdev.com/)
*/
namespace hiqdev\php\billing\order;
use hiqdev\php\billing\action\ActionInterface;
use hiqdev\php\billing\customer\CustomerInterface;
/**
* @author Andrii Vasyliev <sol@hiqdev.com>
*/
class Order implements OrderInterface
{
/**
* @var int|string|null
*/
protected $id;
/**
* @var CustomerInterface
*/
protected $customer;
/**
* @var ActionInterface[] array: actionKey => action
*/
protected $actions = [];
public function __construct($id, CustomerInterface $customer, array $actions = [])
{
$this->id = $id;
$this->customer = $customer;
$this->actions = $actions;
}
public static function fromAction(ActionInterface $action)
{
return new static(null, $action->getCustomer(), [$action]);
}
public static function fromActions(array $actions)
{
$action = reset($actions);
if (!$action instanceof ActionInterface) {
throw new \Exception('wrong actions given in ' . __METHOD__);
}
return new static(null, $action->getCustomer(), $actions);
}
public function getId()
{
return $this->id;
}
public function getCustomer()
{
return $this->customer;
}
/**
* Returns actions.
* @return ActionInterface[] array: actionKey => action
*/
public function getActions()
{
return $this->actions;
}
public function jsonSerialize(): array
{
return array_filter(get_object_vars($this));
}
}