3 namespace Invoker\ParameterResolver\Container;
5 use Interop\Container\ContainerInterface;
6 use Invoker\ParameterResolver\ParameterResolver;
7 use ReflectionFunctionAbstract;
10 * Inject entries from a DI container using the parameter names.
12 * @author Matthieu Napoli <matthieu@mnapoli.fr>
14 class ParameterNameContainerResolver implements ParameterResolver
17 * @var ContainerInterface
22 * @param ContainerInterface $container The container to get entries from.
24 public function __construct(ContainerInterface $container)
26 $this->container = $container;
29 public function getParameters(
30 ReflectionFunctionAbstract $reflection,
31 array $providedParameters,
32 array $resolvedParameters
34 $parameters = $reflection->getParameters();
36 // Skip parameters already resolved
37 if (! empty($resolvedParameters)) {
38 $parameters = array_diff_key($parameters, $resolvedParameters);
41 foreach ($parameters as $index => $parameter) {
42 $name = $parameter->name;
44 if ($name && $this->container->has($name)) {
45 $resolvedParameters[$index] = $this->container->get($name);
49 return $resolvedParameters;