PluginProbe
WPIDE – File Manager & Code Editor / 3.5.10
WPIDE – File Manager & Code Editor v3.5.10
3.5.10 3.5.9 3.5.8 3.5.7 2.0.14 2.0.15 2.0.16 2.0.2 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.1 2.2 2.3 2.3.1 2.3.2 2.4.0 2.5 2.6 3.0 3.1 3.2 All 56 releases
wpide / vendor / php-di / php-di / src / Invoker / FactoryParameterResolver.php

FactoryParameterResolver.php in WPIDE – File Manager & Code Editor 3.5.10, at vendor/php-di/php-di/src/Invoker/FactoryParameterResolver.php

75 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare(strict_types=1);
4
5 namespace DI\Invoker;
6
7 use Invoker\ParameterResolver\ParameterResolver;
8 use Psr\Container\ContainerInterface;
9 use ReflectionFunctionAbstract;
10 use ReflectionNamedType;
11
12 /**
13 * Inject the container, the definition or any other service using type-hints.
14 *
15 * {@internal This class is similar to TypeHintingResolver and TypeHintingContainerResolver,
16 * we use this instead for performance reasons}
17 *
18 * @author Quim Calpe <[email protected]>
19 * @author Matthieu Napoli <[email protected]>
20 */
21 class FactoryParameterResolver implements ParameterResolver
22 {
23 /**
24 * @var ContainerInterface
25 */
26 private $container;
27
28 public function __construct(ContainerInterface $container)
29 {
30 $this->container = $container;
31 }
32
33 public function getParameters(
34 ReflectionFunctionAbstract $reflection,
35 array $providedParameters,
36 array $resolvedParameters
37 ) : array {
38 $parameters = $reflection->getParameters();
39
40 // Skip parameters already resolved
41 if (! empty($resolvedParameters)) {
42 $parameters = array_diff_key($parameters, $resolvedParameters);
43 }
44
45 foreach ($parameters as $index => $parameter) {
46 $parameterType = $parameter->getType();
47 if (!$parameterType) {
48 // No type
49 continue;
50 }
51 if (!$parameterType instanceof ReflectionNamedType) {
52 // Union types are not supported
53 continue;
54 }
55 if ($parameterType->isBuiltin()) {
56 // Primitive types are not supported
57 continue;
58 }
59
60 $parameterClass = $parameterType->getName();
61
62 if ($parameterClass === 'Psr\Container\ContainerInterface') {
63 $resolvedParameters[$index] = $this->container;
64 } elseif ($parameterClass === 'DI\Factory\RequestedEntry') {
65 // By convention the second parameter is the definition
66 $resolvedParameters[$index] = $providedParameters[1];
67 } elseif ($this->container->has($parameterClass)) {
68 $resolvedParameters[$index] = $this->container->get($parameterClass);
69 }
70 }
71
72 return $resolvedParameters;
73 }
74 }
75