ttrss/vendor/open-telemetry/sdk/Common/Configuration/Resolver/EnvironmentResolver.php

41 lines
894 B
PHP
Raw Normal View History

2023-10-20 14:12:29 +00:00
<?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;
}
}