1 | <?php |
||
16 | abstract class Rest |
||
17 | { |
||
18 | /** |
||
19 | * @var mixed $datas Datas receive by request |
||
20 | */ |
||
21 | protected $datas; |
||
22 | |||
23 | /** |
||
24 | * @var string $responseFormat (json|xml) The response format to use |
||
25 | */ |
||
26 | protected $responseFormat; |
||
27 | |||
28 | /** |
||
29 | * Constructor |
||
30 | * Get datas from the request |
||
31 | */ |
||
32 | public function __construct() |
||
37 | |||
38 | /** |
||
39 | * Method called for GET request |
||
40 | * |
||
41 | * @return void |
||
42 | */ |
||
43 | public function getRequest() |
||
48 | |||
49 | /** |
||
50 | * Method called for POST request |
||
51 | * |
||
52 | * @return void |
||
53 | */ |
||
54 | public function postRequest() |
||
59 | |||
60 | /** |
||
61 | * Method called for PUT request |
||
62 | * |
||
63 | * @return void |
||
64 | */ |
||
65 | public function putRequest() |
||
70 | |||
71 | /** |
||
72 | * Method called for DELETE request |
||
73 | * |
||
74 | * @return void |
||
75 | */ |
||
76 | public function deleteRequest() |
||
81 | |||
82 | /** |
||
83 | * Get datas receive from the request |
||
84 | * |
||
85 | * @link http://stackoverflow.com/questions/8945879/how-to-get-body-of-a-post-in-php |
||
86 | * |
||
87 | * @return void |
||
88 | */ |
||
89 | protected function obtainsDatasFromRequest() |
||
103 | |||
104 | /** |
||
105 | * Get the response format to use from header "Accept" or |
||
106 | * the get parameter "format" |
||
107 | * |
||
108 | * The get parameter have the priority on the "Accept" header |
||
109 | * |
||
110 | * @return void |
||
111 | */ |
||
112 | protected function obtainResponseFormat() |
||
125 | |||
126 | /** |
||
127 | * Get the format to use from the "Accept" http header |
||
128 | * |
||
129 | * Header format : text/html,application/xhtml+xml,application/xml;q=0.9 |
||
130 | * |
||
131 | * @return null|string |
||
132 | */ |
||
133 | protected function obtainResponseFormatFromAcceptHeader() |
||
158 | |||
159 | /** |
||
160 | * Get the response format to use from the get paramter "format" |
||
161 | * |
||
162 | * @return string|null |
||
163 | */ |
||
164 | protected function obtainResponseFormatFromGetParameter() |
||
178 | |||
179 | /** |
||
180 | * Send a response for the api request with the correct format |
||
181 | * |
||
182 | * @param mixed $response Datas to send |
||
183 | * |
||
184 | * @return void |
||
185 | */ |
||
186 | protected function sendResponse(&$response) |
||
194 | |||
195 | /** |
||
196 | * Send the response for json format |
||
197 | * |
||
198 | * @param mixed $response Datas to send |
||
199 | * |
||
200 | * @return void |
||
201 | */ |
||
202 | protected function sendJsonResponse(&$response) |
||
207 | |||
208 | /** |
||
209 | * Send the response for xml format |
||
210 | * |
||
211 | * @param mixed $response Datas to send |
||
212 | * |
||
213 | * @return void |
||
214 | */ |
||
215 | protected function sendXmlResponse(&$response) |
||
222 | } |
||
223 |