Total Complexity | 4 |
Total Lines | 35 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
14 | final class AssistedWebContextParam implements ParamInterface |
||
15 | { |
||
16 | /** |
||
17 | * $GLOBALS for testing |
||
18 | * |
||
19 | * @var array<string, array<string, mixed>> |
||
20 | */ |
||
21 | private static array $globals = []; |
||
22 | |||
23 | public function __construct( |
||
24 | private readonly AbstractWebContextParam $webContextParam, |
||
25 | private readonly ParamInterface $defaultParam, |
||
26 | ) { |
||
27 | } |
||
28 | |||
29 | /** |
||
30 | * {@inheritDoc} |
||
31 | */ |
||
32 | #[Override] |
||
33 | public function __invoke(string $varName, array $query, InjectorInterface $injector) |
||
34 | { |
||
35 | $superGlobals = static::$globals ?: $GLOBALS; |
||
|
|||
36 | /** @var array<string, array<string, string>> $superGlobals */ |
||
37 | $webContextParam = $this->webContextParam; |
||
38 | assert(is_string($webContextParam::GLOBAL_KEY)); |
||
39 | /** @psalm-suppress MixedArrayOffset */ |
||
40 | $phpWebContext = $superGlobals[$webContextParam::GLOBAL_KEY]; |
||
41 | |||
42 | return $phpWebContext[$this->webContextParam->key] ?? ($this->defaultParam)($varName, $query, $injector); |
||
43 | } |
||
44 | |||
45 | /** @param array<string, array<string, mixed>> $globals */ |
||
46 | public static function setSuperGlobalsOnlyForTestingPurpose(array $globals): void |
||
49 | } |
||
50 | } |
||
51 |