diff options
Diffstat (limited to 'vendor/open-telemetry/sdk/Common/Configuration/Resolver/EnvironmentResolver.php')
-rw-r--r-- | vendor/open-telemetry/sdk/Common/Configuration/Resolver/EnvironmentResolver.php | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/vendor/open-telemetry/sdk/Common/Configuration/Resolver/EnvironmentResolver.php b/vendor/open-telemetry/sdk/Common/Configuration/Resolver/EnvironmentResolver.php new file mode 100644 index 000000000..453f98e39 --- /dev/null +++ b/vendor/open-telemetry/sdk/Common/Configuration/Resolver/EnvironmentResolver.php @@ -0,0 +1,40 @@ +<?php + +declare(strict_types=1); + +namespace OpenTelemetry\SDK\Common\Configuration\Resolver; + +use OpenTelemetry\SDK\Common\Configuration\Configuration; + +/** + * @internal + */ +class EnvironmentResolver implements ResolverInterface +{ + public function hasVariable(string $variableName): bool + { + if (!Configuration::isEmpty($_SERVER[$variableName] ?? null)) { + return true; + } + $env = getenv($variableName); + if ($env === false) { + return false; + } + + return !Configuration::isEmpty($env); + } + + /** + * @psalm-suppress InvalidReturnStatement + * @psalm-suppress InvalidReturnType + */ + public function retrieveValue(string $variableName) + { + $value = getenv($variableName); + if ($value === false) { + $value = $_SERVER[$variableName] ?? null; + } + + return $value; + } +} |