. namespace hoplite\http; require_once HOPLITE_ROOT . '/http/action.php'; require_once HOPLITE_ROOT . '/http/response_code.php'; /*! An ActionController is an Action that operates like a typical MVC Controller. It will look at the Request's data for a key named 'action', which should correspond to a method named 'Action$action'. */ class ActionController extends Action { /*! Forwards the request/response pair to an internal method based on a key in the Request object. */ public function Invoke(Request $request, Response $response) { $method = $this->_GetActionMethod($request); if (!method_exists($this, $method)) { $response->response_code = ResponseCode::NOT_FOUND; $this->controller()->Stop(); return; } $this->$method($request, $response); } /*! Returns the method name to invoke based on the Request. @return string|NULL */ protected function _GetActionMethod(Request $request) { if (!isset($request->data['action'])) return NULL; return 'Action' . $request->data['action']; } }