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 Invoke(Request
$request, Response
$response)
34 $this->action
= $this->_GetRestAction();
35 parent
::Invoke($request, $response);
38 /*! Gets the RestAction that will be adapted. */
39 protected abstract function _GetRestAction();
41 public function ActionFetch(Request
$request, Response
$response)
43 if ($request->http_method
!= 'GET' && $request->http_method
!= 'POST') {
44 $response->response_code
= ResponseCode
::METHOD_NOT_ALLOWED
;
47 $this->action
->DoGet($request, $response);
50 public function ActionInsert(Request
$request, Response
$response)
52 if ($request->http_method
!= 'POST') {
53 $response->response_code
= ResponseCode
::METHOD_NOT_ALLOWED
;
56 $this->action
->DoPut($request, $response);
59 public function ActionUpdate(Request
$request, Response
$response)
61 if ($request->http_method
!= 'POST') {
62 $response->response_code
= ResponseCode
::METHOD_NOT_ALLOWED
;
65 $this->action
->DoPost($request, $response);
68 public function ActionDelete(Request
$request, Response
$response)
70 if ($request->http_method
!= 'POST') {
71 $response->response_code
= ResponseCode
::METHOD_NOT_ALLOWED
;
74 $this->action
->DoDelete($request, $response);