1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Directus – <http://getdirectus.com> |
5
|
|
|
* |
6
|
|
|
* @link The canonical repository – <https://github.com/directus/directus> |
7
|
|
|
* @copyright Copyright 2006-2016 RANGER Studio, LLC – <http://rangerstudio.com> |
8
|
|
|
* @license GNU General Public License (v3) – <http://www.gnu.org/copyleft/gpl.html> |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Directus\SDK\Response; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Entry |
15
|
|
|
* |
16
|
|
|
* @author Welling Guzmán <[email protected]> |
17
|
|
|
*/ |
18
|
|
|
class Entry implements ResponseInterface, \ArrayAccess |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @var array |
22
|
|
|
*/ |
23
|
|
|
protected $data = null; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var array |
27
|
|
|
*/ |
28
|
|
|
protected $metadata = null; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Entry constructor. |
32
|
|
|
* |
33
|
|
|
* @param $data |
34
|
|
|
*/ |
35
|
22 |
|
public function __construct($data) |
36
|
|
|
{ |
37
|
22 |
|
$this->data = $data; |
38
|
22 |
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Get the entry data |
42
|
|
|
* |
43
|
|
|
* @return array |
44
|
|
|
*/ |
45
|
6 |
|
public function getData() |
46
|
|
|
{ |
47
|
6 |
|
return $this->data; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Get the entry metadata |
52
|
|
|
* |
53
|
|
|
* @return array |
54
|
|
|
*/ |
55
|
6 |
|
public function getMetaData() |
56
|
|
|
{ |
57
|
6 |
|
return $this->metadata; |
58
|
|
|
} |
59
|
|
|
|
60
|
2 |
|
public function offsetExists($offset) |
61
|
|
|
{ |
62
|
2 |
|
return array_key_exists($offset, $this->data); |
63
|
|
|
} |
64
|
|
|
|
65
|
2 |
|
public function offsetGet($offset) |
66
|
|
|
{ |
67
|
2 |
|
return $this->data[$offset]; |
68
|
|
|
} |
69
|
|
|
|
70
|
2 |
|
public function offsetSet($offset, $value) |
71
|
|
|
{ |
72
|
2 |
|
throw new \BadMethodCallException('Entry is read only'); |
73
|
|
|
} |
74
|
|
|
|
75
|
2 |
|
public function offsetUnset($offset) |
76
|
|
|
{ |
77
|
2 |
|
throw new \BadMethodCallException('Entry is read only'); |
78
|
|
|
} |
79
|
|
|
|
80
|
2 |
|
public function __get($name) |
81
|
|
|
{ |
82
|
2 |
|
if (array_key_exists($name, $this->data)) { |
83
|
|
|
return $this->data[$name]; |
84
|
|
|
} |
85
|
|
|
|
86
|
2 |
|
throw new \InvalidArgumentException('Invalid property: ' . $name); |
87
|
|
|
} |
88
|
|
|
|
89
|
2 |
|
public function __set($name, $value) |
90
|
|
|
{ |
91
|
2 |
|
throw new \BadMethodCallException('Entry is read only'); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Gets the object representation of this entry |
96
|
|
|
* |
97
|
|
|
* @return object |
98
|
|
|
*/ |
99
|
4 |
|
public function jsonSerialize() |
100
|
|
|
{ |
101
|
|
|
return (object) [ |
102
|
4 |
|
'metadata' => $this->getMetaData(), |
103
|
4 |
|
'data' => $this->getData() |
104
|
4 |
|
]; |
105
|
|
|
} |
106
|
|
|
} |