Total Complexity | 4 |
Total Lines | 47 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php declare(strict_types=1); |
||
7 | final class DefaultEnv implements Env |
||
8 | { |
||
9 | |||
10 | public function put(string $name, string $value) |
||
11 | { |
||
12 | global $_SERVER; |
||
|
|||
13 | Assertion::true(putenv($name.'='.$value), "Could not put env with name '$name' and value '$value'."); |
||
14 | Assertion::same( |
||
15 | $value, |
||
16 | $retrieved = $this->get($name), |
||
17 | "Failed asserting that value '$value' for env with name '$name' has been preserved when putting it. ". |
||
18 | "Retrieved value was '$retrieved'." |
||
19 | ); |
||
20 | /** |
||
21 | * @see \Symfony\Component\Process\Process::getDefaultEnv |
||
22 | */ |
||
23 | $_SERVER[$name] = $value; |
||
24 | } |
||
25 | |||
26 | public function get(string $name, $default = null): ?string |
||
34 | } |
||
35 | |||
36 | public function unset(string $name) |
||
58 |
Instead of relying on
global
state, we recommend one of these alternatives:1. Pass all data via parameters
2. Create a class that maintains your state