1 | <?php |
||
15 | abstract class Model implements Common |
||
16 | { |
||
17 | const MESSAGE_ID_REQUIRED = 'Id is required'; |
||
18 | const MESSAGE_ID_CAN_NOT_CHANGED = 'Id can not be changed'; |
||
19 | |||
20 | private $client; |
||
21 | |||
22 | private $fields = []; |
||
23 | |||
24 | private $data = null; |
||
25 | |||
26 | private $id = null; |
||
27 | |||
28 | private $lastStatus = 0; |
||
29 | |||
30 | /** |
||
31 | * Model constructor. |
||
32 | * |
||
33 | * @param Client $client |
||
34 | * @param $fields |
||
35 | * @throws Exception |
||
36 | */ |
||
37 | 10 | public function __construct(Client $client, array $fields) |
|
50 | |||
51 | 4 | public function get($id = null) |
|
65 | |||
66 | /** |
||
67 | * Set data to model |
||
68 | * |
||
69 | * @param array $data |
||
70 | * @param null $status |
||
71 | * @return $this |
||
72 | * @throws Exception |
||
73 | */ |
||
74 | 10 | public function set(array $data, $status = null) |
|
97 | |||
98 | 8 | public function getFields() |
|
104 | |||
105 | 8 | public function getId() |
|
109 | |||
110 | 1 | public function post(array $data) |
|
118 | |||
119 | 1 | public function put(array $data) |
|
120 | { |
||
121 | 1 | $this->set($data); |
|
122 | |||
123 | 1 | $response = $this->client->getResponse($this->getUrl(__FUNCTION__, [$this->getId()]), $data); |
|
124 | |||
125 | $this->set($response['data'], $response['status']); |
||
126 | |||
127 | return $this; |
||
128 | } |
||
129 | |||
130 | 1 | public function delete($id = null) |
|
142 | |||
143 | 5 | public function __get($name) |
|
151 | } |