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.php';
20 require_once HOPLITE_ROOT
. '/http/response_code.php';
23 This abstract class is the base for handling all requests and filling out
26 class RestAction
extends Action
29 Performs the action and fills out the response's data model.
31 public function Invoke(Request
$request, Response
$response)
33 $valid_methods = array('get', 'post', 'delete', 'put');
34 $method = strtolower($request->http_method
);
35 if (!in_array($method, $valid_methods)) {
36 $response->response_code
= ResponseCode
::METHOD_NOT_ALLOWED
;
37 $this->controller()->Stop();
41 $invoke = '_Do' . ucwords($method);
42 $this->$invoke($request, $response);
45 /*! Methods for each of the different HTTP methods. */
46 protected function _DoGet(Request
$request, Response
$response) {}
47 protected function _DoPost(Request
$request, Response
$response) {}
48 protected function _DoDelete(Request
$request, Response
$response) {}
49 protected function _DoPut(Request
$request, Response
$response) {}