1 | <?php |
||
19 | abstract class AbstractSyncedRoutine extends AbstractRoutine implements ParamSynced |
||
20 | { |
||
21 | /** |
||
22 | * @var Reflector |
||
23 | */ |
||
24 | protected $reflection; |
||
25 | |||
26 | /** |
||
27 | * Return parameters that can be used with the routine. |
||
28 | * |
||
29 | * @return array |
||
30 | */ |
||
31 | 20 | public function getParameters() |
|
32 | { |
||
33 | 20 | $reflection = $this->getReflection(); |
|
34 | 20 | if (!$reflection instanceof ReflectionObject && !$reflection instanceof ReflectionClass) { |
|
35 | 17 | return $this->getReflection()->getParameters(); |
|
|
|||
36 | } |
||
37 | |||
38 | 3 | return array(); |
|
39 | } |
||
40 | |||
41 | /** |
||
42 | * Executes the routine and return its result. |
||
43 | * |
||
44 | * @param Respect\Rest\Request $request |
||
45 | * @param array $params |
||
46 | * @return mixed |
||
47 | */ |
||
48 | 16 | public function execute(Request $request, $params) |
|
49 | { |
||
50 | 16 | $callback = $this->getCallback(); |
|
51 | 16 | if (is_string($callback)) { |
|
52 | 1 | $reflection = $this->getReflection(); |
|
53 | 1 | $routineInstance = $reflection->newInstanceArgs($params); |
|
54 | |||
55 | 1 | return $routineInstance(); |
|
56 | } |
||
57 | |||
58 | 15 | return call_user_func_array($callback, $params); |
|
59 | } |
||
60 | |||
61 | /** |
||
62 | * Returns a concrete ReflectionFunctionAbstract for this routine callback. |
||
63 | * |
||
64 | * @return Reflector |
||
65 | */ |
||
66 | 20 | protected function getReflection() |
|
79 | } |
||
80 |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: