-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathEnvVar.php
More file actions
31 lines (27 loc) · 732 Bytes
/
EnvVar.php
File metadata and controls
31 lines (27 loc) · 732 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?php
declare(strict_types=1);
namespace AsyncAws\Core;
/**
* Helper to safely read environment variables.
*
* @author Jérémy Derussé <[email protected]>
*
* @internal
*/
final class EnvVar
{
public static function get(string $name): ?string
{
if (isset($_ENV[$name])) {
// variable_order = *E*GPCS
return (string) $_ENV[$name];
} elseif (isset($_SERVER[$name]) && !\is_array($_SERVER[$name]) && 0 !== strpos($name, 'HTTP_')) {
// fastcgi_param, env var, ...
return (string) $_SERVER[$name];
} elseif (false === $env = getenv($name)) {
// getenv not thread safe
return null;
}
return $env;
}
}