summaryrefslogtreecommitdiff
path: root/vendor/open-telemetry/sdk/Common/Configuration/Resolver/PhpIniResolver.php
blob: c9a8f3b4e314b553566f29ac51a517addf99df4d (plain)
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
32
33
34
35
36
37
38
39
40
41
<?php

declare(strict_types=1);

namespace OpenTelemetry\SDK\Common\Configuration\Resolver;

use OpenTelemetry\SDK\Common\Configuration\Configuration;

/**
 * @interal
 * @psalm-suppress TypeDoesNotContainType
 */
class PhpIniResolver implements ResolverInterface
{
    private PhpIniAccessor $accessor;

    public function __construct(?PhpIniAccessor $accessor = null)
    {
        $this->accessor = $accessor ?? new PhpIniAccessor();
    }

    public function retrieveValue(string $variableName)
    {
        $value = $this->accessor->get($variableName) ?: '';
        if (is_array($value)) {
            return implode(',', $value);
        }

        return $value;
    }

    public function hasVariable(string $variableName): bool
    {
        $value = $this->accessor->get($variableName);
        if ($value === []) {
            return false;
        }

        return $value !== false && !Configuration::isEmpty($value);
    }
}