3 namespace Invoker\ParameterResolver;
5 use ReflectionFunctionAbstract;
8 * Tries to map an associative array (string-indexed) to the parameter names.
10 * E.g. `->call($callable, ['foo' => 'bar'])` will inject the string `'bar'`
11 * in the parameter named `$foo`.
13 * Parameters that are not indexed by a string are ignored.
15 * @author Matthieu Napoli <matthieu@mnapoli.fr>
17 class AssociativeArrayResolver implements ParameterResolver
19 public function getParameters(
20 ReflectionFunctionAbstract $reflection,
21 array $providedParameters,
22 array $resolvedParameters
24 $parameters = $reflection->getParameters();
26 // Skip parameters already resolved
27 if (! empty($resolvedParameters)) {
28 $parameters = array_diff_key($parameters, $resolvedParameters);
31 foreach ($parameters as $index => $parameter) {
32 if (array_key_exists($parameter->name, $providedParameters)) {
33 $resolvedParameters[$index] = $providedParameters[$parameter->name];
37 return $resolvedParameters;