1 | <?php |
||
17 | abstract class Rest implements RestInterface |
||
18 | { |
||
19 | /** |
||
20 | * @var mixed $datas Datas receive by request |
||
21 | */ |
||
22 | protected $datas; |
||
23 | |||
24 | /** |
||
25 | * @var string $responseFormat (json|xml) The response format to use |
||
26 | */ |
||
27 | protected $responseFormat; |
||
28 | |||
29 | /** |
||
30 | * Constructor |
||
31 | * Get datas from the request |
||
32 | */ |
||
33 | public function __construct() |
||
38 | |||
39 | /** |
||
40 | * Getter accessor for datas property |
||
41 | * |
||
42 | * @return miex |
||
43 | */ |
||
44 | public function getDatas() |
||
48 | |||
49 | /** |
||
50 | * Getter accessor for responseFormat property |
||
51 | * |
||
52 | * @return string |
||
53 | */ |
||
54 | public function getResponseFormat() |
||
58 | |||
59 | /** |
||
60 | * Method called for GET request |
||
61 | * |
||
62 | * @return void |
||
63 | */ |
||
64 | public function getRequest() |
||
69 | |||
70 | /** |
||
71 | * Method called for POST request |
||
72 | * |
||
73 | * @return void |
||
74 | */ |
||
75 | public function postRequest() |
||
80 | |||
81 | /** |
||
82 | * Method called for PUT request |
||
83 | * |
||
84 | * @return void |
||
85 | */ |
||
86 | public function putRequest() |
||
91 | |||
92 | /** |
||
93 | * Method called for DELETE request |
||
94 | * |
||
95 | * @return void |
||
96 | */ |
||
97 | public function deleteRequest() |
||
102 | |||
103 | /** |
||
104 | * Get datas receive from the request |
||
105 | * |
||
106 | * @link http://stackoverflow.com/questions/8945879/how-to-get-body-of-a-post-in-php |
||
107 | * |
||
108 | * @return void |
||
109 | */ |
||
110 | protected function obtainDatasFromRequest() |
||
137 | |||
138 | /** |
||
139 | * Get the response format to use from header "Accept" or |
||
140 | * the get parameter "format" |
||
141 | * |
||
142 | * The get parameter have the priority on the "Accept" header |
||
143 | * |
||
144 | * @return void |
||
145 | */ |
||
146 | protected function obtainResponseFormat() |
||
159 | |||
160 | /** |
||
161 | * Get the format to use from the "Accept" http header |
||
162 | * |
||
163 | * Header format : text/html,application/xhtml+xml,application/xml;q=0.9 |
||
164 | * |
||
165 | * @return null|string |
||
166 | */ |
||
167 | protected function obtainResponseFormatFromAcceptHeader() |
||
192 | |||
193 | /** |
||
194 | * Get the response format to use from the get paramter "format" |
||
195 | * |
||
196 | * @return string|null |
||
197 | */ |
||
198 | protected function obtainResponseFormatFromGetParameter() |
||
212 | |||
213 | /** |
||
214 | * Send a response for the api request with the correct format |
||
215 | * |
||
216 | * @param mixed $response Datas to send |
||
217 | * |
||
218 | * @return void |
||
219 | */ |
||
220 | protected function sendResponse(&$response) |
||
228 | |||
229 | /** |
||
230 | * Send the response for json format |
||
231 | * |
||
232 | * @param mixed $response Datas to send |
||
233 | * |
||
234 | * @return void |
||
235 | */ |
||
236 | protected function sendJsonResponse(&$response) |
||
241 | |||
242 | /** |
||
243 | * Send the response for xml format |
||
244 | * |
||
245 | * @param mixed $response Datas to send |
||
246 | * |
||
247 | * @return void |
||
248 | */ |
||
249 | protected function sendXmlResponse(&$response) |
||
256 | } |
||
257 |