PluginProbe
Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA & Google Consent Mode / 3.5.0
Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA & Google Consent Mode v3.5.0
4.7.3 4.7.2 4.7.1 trunk 2.3.0 2.4.0 2.4.1 2.4.2 2.5.0 3.0.0 3.0.1 3.1.0 3.10.0 3.10.1 3.11.1 3.11.2 3.11.3 3.2.0 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 All 93 releases
cookiebot / addons / lib / ioc / php-di / invoker / src / ParameterResolver / AssociativeArrayResolver.php

AssociativeArrayResolver.php in Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA & Google Consent Mode 3.5.0, at addons/lib/ioc/php-di/invoker/src/ParameterResolver/AssociativeArrayResolver.php

40 lines 1.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace 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 * @author Matthieu Napoli <matthieu@mnapoli.fr>
16 */
17 class AssociativeArrayResolver implements ParameterResolver
18 {
19 public function getParameters(
20 ReflectionFunctionAbstract $reflection,
21 array $providedParameters,
22 array $resolvedParameters
23 ) {
24 $parameters = $reflection->getParameters();
25
26 // Skip parameters already resolved
27 if (! empty($resolvedParameters)) {
28 $parameters = array_diff_key($parameters, $resolvedParameters);
29 }
30
31 foreach ($parameters as $index => $parameter) {
32 if (array_key_exists($parameter->name, $providedParameters)) {
33 $resolvedParameters[$index] = $providedParameters[$parameter->name];
34 }
35 }
36
37 return $resolvedParameters;
38 }
39 }
40