Commit 543df477 authored by Ad Schellevis's avatar Ad Schellevis

api, missing check for existing method.

parent b7f438d5
...@@ -132,24 +132,27 @@ class ApiControllerBase extends ControllerRoot ...@@ -132,24 +132,27 @@ class ApiControllerBase extends ControllerRoot
$dispatchError = null; $dispatchError = null;
// check number of parameters using reflection // check number of parameters using reflection
$object_info = new \ReflectionObject($this); $object_info = new \ReflectionObject($this);
$req_c = $object_info->getMethod($callMethodName)->getNumberOfRequiredParameters(); if ($object_info->hasMethod($callMethodName)) {
if ($req_c > count($dispatcher->getParams())) { // only inspect parameters if object exists
$dispatchError = 'action ' . $dispatcher->getActionName() . $req_c = $object_info->getMethod($callMethodName)->getNumberOfRequiredParameters();
' expects at least '. $req_c . ' parameter(s)'; if ($req_c > count($dispatcher->getParams())) {
} else { $dispatchError = 'action ' . $dispatcher->getActionName() .
// if body is send as json data, parse to $_POST first ' expects at least '. $req_c . ' parameter(s)';
$dispatchError = $this->parseJsonBodyData(); } else {
} // if body is send as json data, parse to $_POST first
if ($dispatchError != null) { $dispatchError = $this->parseJsonBodyData();
// send error to client }
$this->response->setStatusCode(400, "Bad Request"); if ($dispatchError != null) {
$this->response->setContentType('application/json', 'UTF-8'); // send error to client
$this->response->setJsonContent( $this->response->setStatusCode(400, "Bad Request");
array('message' => $dispatchError, $this->response->setContentType('application/json', 'UTF-8');
'status' => 400) $this->response->setJsonContent(
); array('message' => $dispatchError,
$this->response->send(); 'status' => 400)
return false; );
$this->response->send();
return false;
}
} }
return true; return true;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment