]>
src.bluestatic.org Git - hoplite.git/blob - http/rest_adapter.php
3 // Copyright (c) 2011 Blue Static
5 // This program is free software: you can redistribute it and/or modify it
6 // under the terms of the GNU General Public License as published by the Free
7 // Software Foundation, either version 3 of the License, or any later version.
9 // This program is distributed in the hope that it will be useful, but WITHOUT
10 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 // You should have received a copy of the GNU General Public License along with
15 // this program. If not, see <http://www.gnu.org/licenses/>.
17 namespace hoplite\http
;
19 require_once HOPLITE_ROOT
. '/http/action_controller.php';
20 require_once HOPLITE_ROOT
. '/http/response_code.php';
21 require_once HOPLITE_ROOT
. '/http/rest_action.php';
24 This abstract class adapts a RESTful interface into a web frontend that only
25 supports GET and POST. The |action| parameter will control what is performed.
27 abstract class RestAdapter
extends ActionController
29 /*! @var RestAction The RESTful interface which will be adapted. */
30 protected $action = NULL;
32 public function FilterRequest(Request
$request, Response
$response)
34 $this->action
= $this->_GetRestAction();
37 /*! Gets the RestAction that will be adapted. */
38 protected abstract function _GetRestAction();
40 public function ActionFetch(Request
$request, Response
$response)
42 if ($request->http_method
!= 'GET' && $request->http_method
!= 'POST') {
43 $response->response_code
= ResponseCode
::METHOD_NOT_ALLOWED
;
46 $this->action
->DoGet($request, $response);
49 public function ActionInsert(Request
$request, Response
$response)
51 if ($request->http_method
!= 'POST') {
52 $response->response_code
= ResponseCode
::METHOD_NOT_ALLOWED
;
55 $this->action
->DoPut($request, $response);
58 public function ActionUpdate(Request
$request, Response
$response)
60 if ($request->http_method
!= 'POST') {
61 $response->response_code
= ResponseCode
::METHOD_NOT_ALLOWED
;
64 $this->action
->DoPost($request, $response);
67 public function ActionDelete(Request
$request, Response
$response)
69 if ($request->http_method
!= 'POST') {
70 $response->response_code
= ResponseCode
::METHOD_NOT_ALLOWED
;
73 $this->action
->DoDelete($request, $response);