Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php declare(strict_types=1);
2
 
3
namespace Invoker\ParameterResolver;
4
 
5
use ReflectionFunctionAbstract;
6
 
7
/**
8
 * Simply returns all the values of the $providedParameters array that are
9
 * indexed by the parameter position (i.e. a number).
10
 *
11
 * E.g. `->call($callable, ['foo', 'bar'])` will simply resolve the parameters
12
 * to `['foo', 'bar']`.
13
 *
14
 * Parameters that are not indexed by a number (i.e. parameter position)
15
 * will be ignored.
16
 */
17
class NumericArrayResolver implements ParameterResolver
18
{
19
    public function getParameters(
20
        ReflectionFunctionAbstract $reflection,
21
        array $providedParameters,
22
        array $resolvedParameters
23
    ): array {
24
        // Skip parameters already resolved
25
        if (! empty($resolvedParameters)) {
26
            $providedParameters = array_diff_key($providedParameters, $resolvedParameters);
27
        }
28
 
29
        foreach ($providedParameters as $key => $value) {
30
            if (is_int($key)) {
31
                $resolvedParameters[$key] = $value;
32
            }
33
        }
34
 
35
        return $resolvedParameters;
36
    }
37
}