PluginProbe
The Innovative Form Builder – IvyForms / 1.5
The Innovative Form Builder – IvyForms v1.5
1.5.1 1.5 1.4.1 1.4 trunk 0.1.2 0.2 0.2.1 0.3 0.3.1 0.4 0.5 0.6 0.6.1 0.6.1-backup 0.6.1.1 0.7 0.8 0.8.1 0.8.2 0.9 0.9.1 1.0 1.1 1.1.1 All 27 releases
ivyforms / backend / scope-vendor / php-di / invoker / src / ParameterResolver / AssociativeArrayResolver.php

AssociativeArrayResolver.php in The Innovative Form Builder – IvyForms 1.5, at backend/scope-vendor/php-di/invoker/src/ParameterResolver/AssociativeArrayResolver.php

38 lines 1.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php declare(strict_types=1);
2
3 namespace IvyForms\Vendor\Invoker\ParameterResolver;
4
5 use ReflectionFunctionAbstract;
6
7 /**
8 * Tries to map an associative array (string-indexed) to the parameter names.
9 *
10 * E.g. `->call($callable, ['foo' => 'bar'])` will inject the string `'bar'`
11 * in the parameter named `$foo`.
12 *
13 * Parameters that are not indexed by a string are ignored.
14 */
15 class AssociativeArrayResolver implements ParameterResolver
16 {
17 public function getParameters(
18 ReflectionFunctionAbstract $reflection,
19 array $providedParameters,
20 array $resolvedParameters
21 ): array {
22 $parameters = $reflection->getParameters();
23
24 // Skip parameters already resolved
25 if (! empty($resolvedParameters)) {
26 $parameters = array_diff_key($parameters, $resolvedParameters);
27 }
28
29 foreach ($parameters as $index => $parameter) {
30 if (array_key_exists($parameter->name, $providedParameters)) {
31 $resolvedParameters[$index] = $providedParameters[$parameter->name];
32 }
33 }
34
35 return $resolvedParameters;
36 }
37 }
38