Skip to content

Commit

Permalink
Invoker: Add check if method exist and is callable.
Browse files Browse the repository at this point in the history
  • Loading branch information
janbarasek authored Jul 18, 2021
1 parent a51da36 commit 01af3c4
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/ServiceMethodInvoker.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,17 @@ public function invoke(
array $params,
bool $dataMustBeArray = false
): mixed {
if (method_exists($service, $methodName) === false) {
throw new \InvalidArgumentException(
'Method "' . $methodName . '" in class "' . get_debug_type($service) . '" '
. 'does not exist or is not public and callable.',
);
}
if (is_callable([$service, $methodName]) === false) {
throw new \InvalidArgumentException(
'Method "' . $methodName . '" in class "' . get_debug_type($service) . '" is not callable.',
);
}
try {
$ref = new \ReflectionMethod($service, $methodName);
} catch (\ReflectionException $e) {
Expand All @@ -71,6 +82,17 @@ public function getInvokeArgs(
array $params,
bool $dataMustBeArray = false
): array {
if (method_exists($service, $methodName) === false) {
throw new \InvalidArgumentException(
'Method "' . $methodName . '" in class "' . get_debug_type($service) . '" '
. 'does not exist or is not public and callable.',
);
}
if (is_callable([$service, $methodName]) === false) {
throw new \InvalidArgumentException(
'Method "' . $methodName . '" in class "' . get_debug_type($service) . '" is not callable.',
);
}
$args = [];
try {
$parameters = (new \ReflectionMethod($service, $methodName))->getParameters();
Expand Down

0 comments on commit 01af3c4

Please # to comment.