Start stubbing out the design doc interfaces
[hoplite.git] / http / rest_action.php
1 <?php
2 // Hoplite
3 // Copyright (c) 2011 Blue Static
4 //
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.
8 //
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
12 // more details.
13 //
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/>.
16
17 namespace hoplite\http;
18
19 /*!
20 This abstract class is the base for handling all requests and filling out
21 response objects.
22 */
23 class RestAction extends Action
24 {
25 /*!
26 Performs the action and fills out the response's data model.
27 */
28 public function Invoke(Request $request, Response $response)
29 {
30 $valid_methods = array('get', 'post', 'delete', 'put');
31 $method = strtolower($request->http_method);
32 if (!in_array($method, $valid_methods)) {
33 $response->http_code = 405 /* METHOD_NOT_ALLOWED */;
34 $this->controller()->Stop();
35 return;
36 }
37
38 $invoke = 'Do' . ucwords($method);
39 $this->$invoke();
40 }
41
42 /*! Methods for each of the different HTTP methods. */
43 protected function _DoGet(Request $request, Response $response) {}
44 protected function _DoPost(Request $request, Response $response) {}
45 protected function _DoDelete(Request $request, Response $response) {}
46 protected function _DoPut(Request $request, Response $response) {}
47 }