1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Lifeboat\Resource; |
4
|
|
|
|
5
|
|
|
use Lifeboat\Connector; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class ResourceList |
9
|
|
|
* @package Lifeboat\Resource |
10
|
|
|
* |
11
|
|
|
* @property array $_object_data |
12
|
|
|
*/ |
13
|
|
|
class ObjectResource extends ApiResource { |
14
|
|
|
|
15
|
|
|
private $_object_data = []; |
16
|
|
|
|
17
|
|
|
public function __construct(Connector $connector, array $_object_data = []) |
18
|
|
|
{ |
19
|
|
|
$this->setClient($connector); |
20
|
|
|
foreach ($_object_data as $k => $v) { |
21
|
|
|
$this->__set($k, $v); |
22
|
|
|
} |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @param string $field |
27
|
|
|
* @return mixed |
28
|
|
|
*/ |
29
|
|
|
public function __get(string $field) |
30
|
|
|
{ |
31
|
|
|
return $this->_object_data[$field] ?? null; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @param string $field |
36
|
|
|
* @param $value |
37
|
|
|
* @return $this |
38
|
|
|
*/ |
39
|
|
|
public function __set(string $field, $value): ObjectResource |
40
|
|
|
{ |
41
|
|
|
$this->_object_data[$field] = $value; |
42
|
|
|
return $this; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function offsetGet($offset) |
46
|
|
|
{ |
47
|
|
|
return $this->_object_data[$offset] ?? null; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function offsetSet($offset, $value) |
51
|
|
|
{ |
52
|
|
|
return $this->_object_data[$offset] = $value; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @param mixed $offset |
57
|
|
|
* @return void |
58
|
|
|
*/ |
59
|
|
|
public function offsetUnset($offset): void |
60
|
|
|
{ |
61
|
|
|
unset($this->_object_data[$offset]); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @param mixed $offset |
66
|
|
|
* @return bool |
67
|
|
|
*/ |
68
|
|
|
public function offsetExists($offset): bool |
69
|
|
|
{ |
70
|
|
|
return array_key_exists($offset, $this->_object_data); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @return int |
75
|
|
|
*/ |
76
|
|
|
public function count(): int |
77
|
|
|
{ |
78
|
|
|
return count($this->_object_data); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @return array |
83
|
|
|
*/ |
84
|
|
|
public function keys(): array |
85
|
|
|
{ |
86
|
|
|
return \array_keys($this->_object_data); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @return array |
91
|
|
|
*/ |
92
|
|
|
public function values(): array |
93
|
|
|
{ |
94
|
|
|
return \array_values($this->_object_data); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|