1 | <?php |
||
13 | abstract class ResourceObject implements AcceptTransferInterface, ArrayAccess, Countable, IteratorAggregate, JsonSerializable, ToStringInterface |
||
14 | { |
||
15 | /** |
||
16 | * Uri |
||
17 | * |
||
18 | * @var AbstractUri |
||
19 | */ |
||
20 | public $uri; |
||
21 | |||
22 | /** |
||
23 | * Status code |
||
24 | * |
||
25 | * @var int |
||
26 | */ |
||
27 | public $code = 200; |
||
28 | |||
29 | /** |
||
30 | * Resource header |
||
31 | * |
||
32 | * @var array |
||
33 | */ |
||
34 | public $headers = []; |
||
35 | |||
36 | /** |
||
37 | * Resource representation |
||
38 | * |
||
39 | * @var null|string |
||
40 | */ |
||
41 | public $view; |
||
42 | |||
43 | /** |
||
44 | * Body |
||
45 | * |
||
46 | * @var mixed |
||
47 | */ |
||
48 | public $body; |
||
49 | |||
50 | /** |
||
51 | * Renderer |
||
52 | * |
||
53 | * @var \BEAR\Resource\RenderInterface |
||
54 | */ |
||
55 | protected $renderer; |
||
56 | |||
57 | /** |
||
58 | * Return representational string |
||
59 | * |
||
60 | * Return object hash if representation renderer is not set. |
||
61 | * |
||
62 | * @return string |
||
63 | */ |
||
64 | 15 | public function __toString() |
|
77 | |||
78 | 1 | public function __sleep() |
|
79 | { |
||
80 | 1 | if (is_array($this->body)) { |
|
81 | 1 | foreach ($this->body as &$item) { |
|
82 | 1 | if ($item instanceof RequestInterface) { |
|
83 | $item = ($item)(); |
||
84 | } |
||
85 | } |
||
86 | } |
||
87 | |||
88 | 1 | return ['uri', 'code', 'headers', 'body', 'view']; |
|
89 | } |
||
90 | |||
91 | /** |
||
92 | * Returns the body value at the specified index |
||
93 | * |
||
94 | * @param mixed $offset offset |
||
95 | */ |
||
96 | 12 | public function offsetGet($offset) |
|
100 | |||
101 | /** |
||
102 | * Sets the body value at the specified index to renew |
||
103 | * |
||
104 | * @param mixed $offset offset |
||
105 | * @param mixed $value value |
||
106 | */ |
||
107 | 37 | public function offsetSet($offset, $value) |
|
111 | |||
112 | /** |
||
113 | * Returns whether the requested index in body exists |
||
114 | * |
||
115 | * @param mixed $offset offset |
||
116 | * |
||
117 | * @return bool |
||
118 | */ |
||
119 | 3 | public function offsetExists($offset) |
|
123 | |||
124 | /** |
||
125 | * Set the value at the specified index |
||
126 | * |
||
127 | * @param mixed $offset offset |
||
128 | */ |
||
129 | 1 | public function offsetUnset($offset) |
|
133 | |||
134 | /** |
||
135 | * Get the number of public properties in the ArrayObject |
||
136 | * |
||
137 | * @return int |
||
138 | */ |
||
139 | 1 | public function count() |
|
143 | |||
144 | /** |
||
145 | * Sort the entries by key |
||
146 | */ |
||
147 | 2 | public function ksort() |
|
154 | |||
155 | /** |
||
156 | * Sort the entries by key |
||
157 | */ |
||
158 | 2 | public function asort() |
|
165 | |||
166 | /** |
||
167 | * Get array iterator |
||
168 | * |
||
169 | * @return \ArrayIterator |
||
170 | */ |
||
171 | 2 | public function getIterator() |
|
177 | |||
178 | /** |
||
179 | * Set renderer |
||
180 | * |
||
181 | * @return $this |
||
182 | * @Ray\Di\Di\Inject(optional=true) |
||
183 | */ |
||
184 | 50 | public function setRenderer(RenderInterface $renderer) |
|
190 | |||
191 | /** |
||
192 | * {@inheritdoc} |
||
193 | */ |
||
194 | 16 | public function toString() |
|
205 | |||
206 | 12 | public function jsonSerialize() |
|
216 | |||
217 | /** |
||
218 | * {@inheritdoc} |
||
219 | */ |
||
220 | 1 | public function transfer(TransferInterface $responder, array $server) |
|
224 | |||
225 | 12 | private function evaluate($body) |
|
239 | } |
||
240 |