3da7039bbbf8c61fa0ffa5a3cf1b0e119e4ecb58
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 An ActionController is an Action that operates like a typical MVC Controller.
24 It will look at the Request's data for a key named 'action', which should
25 correspond to a method named 'Action$action'.
27 class ActionController
extends Action
30 Forwards the request/response pair to an internal method based on a key in
33 public function Invoke(Request
$request, Response
$response)
35 $method = $this->_GetActionMethod($request);
36 if (!method_exists($this, $method)) {
37 $response->response_code
= ResponseCode
::NOT_FOUND
;
38 $this->controller()->Stop();
42 $this->$method($request, $response);
46 Returns the method name to invoke based on the Request.
49 protected function _GetActionMethod(Request
$request)
51 if (!isset($request->data
['action']))
53 return 'Action' . $request->data
['action'];