Skip to content

Commit 63f6ae4

Browse files
authored
invokeActionMethod(): Fix case when $methodName can be null.
1 parent 8dcec2b commit 63f6ae4

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

src/ApiManager.php

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,12 @@ private function route(string $route, array $params): array
282282
*/
283283
private function invokeActionMethod(Endpoint $endpoint, string $action, string $method, array $params): ?BaseResponse
284284
{
285-
$methodName = $this->getActionMethodName($endpoint, $method, $action);
285+
if (($methodName = $this->getActionMethodName($endpoint, $method, $action)) === null) {
286+
return new JsonResponse($this->convention, [
287+
'state' => 'error',
288+
'message' => 'Method for action "' . $action . '" and HTTP method "' . $method . '" is not implemented.',
289+
], 404);
290+
}
286291

287292
try {
288293
if ($this->checkPermission($endpoint, $methodName) === false) { // Forbidden or permission denied
@@ -303,14 +308,12 @@ private function invokeActionMethod(Endpoint $endpoint, string $action, string $
303308
$ref = null;
304309
$response = null;
305310

306-
if ($methodName !== null) {
307-
try {
308-
$response = (new ServiceMethodInvoker)->invoke($endpoint, $methodName, $params, true);
309-
} catch (ThrowResponse $e) {
310-
$response = $e->getResponse();
311-
} catch (RuntimeInvokeException $e) {
312-
throw new RuntimeStructuredApiException($e->getMessage(), $e->getCode(), $e);
313-
}
311+
try {
312+
$response = (new ServiceMethodInvoker)->invoke($endpoint, $methodName, $params, true);
313+
} catch (ThrowResponse $e) {
314+
$response = $e->getResponse();
315+
} catch (RuntimeInvokeException $e) {
316+
throw new RuntimeStructuredApiException($e->getMessage(), $e->getCode(), $e);
314317
}
315318

316319
if ($method !== 'GET' && $response === null) {

0 commit comments

Comments
 (0)