1 | <?php |
||
9 | abstract class Model implements Common |
||
10 | { |
||
11 | const MESSAGE_ID_REQUIRED = 'Id is required'; |
||
12 | const MESSAGE_ID_CAN_NOT_CHANGED = 'Id can not be changed'; |
||
13 | |||
14 | private $client; |
||
15 | |||
16 | private $fields = []; |
||
17 | |||
18 | private $data = null; |
||
19 | |||
20 | private $id = null; |
||
21 | |||
22 | private $lastStatus = 0; |
||
23 | |||
24 | /** |
||
25 | * Model constructor. |
||
26 | * |
||
27 | * @param Client $client |
||
28 | * @param $fields |
||
29 | * @throws Exception |
||
30 | */ |
||
31 | 6 | public function __construct(Client $client, array $fields) |
|
44 | |||
45 | /** |
||
46 | * @return array |
||
47 | */ |
||
48 | public function getFields() |
||
52 | |||
53 | /** |
||
54 | * @param array $data |
||
55 | * @return $this |
||
56 | * @throws Exception |
||
57 | */ |
||
58 | 1 | public function post(array $data) |
|
66 | |||
67 | /** |
||
68 | * Set data to model |
||
69 | * |
||
70 | * @param array $data |
||
71 | * @param null $status |
||
72 | * @return $this |
||
73 | * @throws Exception |
||
74 | */ |
||
75 | 3 | public function set(array $data, $status = null) |
|
97 | |||
98 | /** |
||
99 | * @param array $data |
||
100 | * @return $this |
||
101 | * @throws Exception |
||
102 | */ |
||
103 | public function put(array $data) |
||
113 | |||
114 | /** |
||
115 | * @return null |
||
116 | */ |
||
117 | 5 | public function getId() |
|
121 | |||
122 | /** |
||
123 | * @param $id |
||
124 | * @return Model |
||
125 | * @throws Exception |
||
126 | */ |
||
127 | 1 | public function setId($id) |
|
131 | |||
132 | /** |
||
133 | * @param null $id |
||
134 | * @return $this |
||
135 | * @throws Exception |
||
136 | */ |
||
137 | public function delete($id = null) |
||
149 | |||
150 | /** |
||
151 | * @param $name |
||
152 | * @return mixed |
||
153 | * @throws Exception |
||
154 | */ |
||
155 | public function __get($name) |
||
165 | |||
166 | /** |
||
167 | * @param null $id |
||
168 | * @return null |
||
169 | * @throws Exception |
||
170 | */ |
||
171 | 2 | public function get($id = null) |
|
191 | |||
192 | /** |
||
193 | * @return Client |
||
194 | */ |
||
195 | 1 | protected function getClient() |
|
199 | } |