summaryrefslogtreecommitdiff
path: root/vendor/open-telemetry/sdk/Common/Adapter/HttpDiscovery/PsrClientResolver.php
blob: 46fb36312942048747203e84fd1fcbc2d09eda39 (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
<?php

declare(strict_types=1);

namespace OpenTelemetry\SDK\Common\Adapter\HttpDiscovery;

use Http\Discovery\Psr18ClientDiscovery;
use OpenTelemetry\SDK\Common\Http\Psr\Client\ResolverInterface;
use Psr\Http\Client\ClientInterface;

final class PsrClientResolver implements ResolverInterface
{
    private ?ClientInterface $client;

    public function __construct(?ClientInterface $client = null)
    {
        $this->client = $client;
    }

    public static function create(?ClientInterface $client = null): self
    {
        return new self($client);
    }

    public function resolvePsrClient(): ClientInterface
    {
        return $this->client ??= Psr18ClientDiscovery::find();
    }
}