| 1 |
<?php |
| 2 |
|
| 3 |
declare (strict_types=1); |
| 4 |
namespace WCPOS\Vendor\Sentry; |
| 5 |
|
| 6 |
use WCPOS\Vendor\Psr\Log\LoggerInterface; |
| 7 |
use WCPOS\Vendor\Sentry\HttpClient\HttpClient; |
| 8 |
use WCPOS\Vendor\Sentry\HttpClient\HttpClientInterface; |
| 9 |
use WCPOS\Vendor\Sentry\Serializer\PayloadSerializer; |
| 10 |
use WCPOS\Vendor\Sentry\Serializer\RepresentationSerializerInterface; |
| 11 |
use WCPOS\Vendor\Sentry\Transport\HttpTransport; |
| 12 |
use WCPOS\Vendor\Sentry\Transport\TransportInterface; |
| 13 |
/** |
| 14 |
* A configurable builder for Client objects. |
| 15 |
*/ |
| 16 |
final class ClientBuilder |
| 17 |
{ |
| 18 |
/** |
| 19 |
* @var Options The client options |
| 20 |
*/ |
| 21 |
private $options; |
| 22 |
/** |
| 23 |
* @var TransportInterface|null The transport |
| 24 |
*/ |
| 25 |
private $transport; |
| 26 |
/** |
| 27 |
* @var HttpClientInterface|null The HTTP client |
| 28 |
*/ |
| 29 |
private $httpClient; |
| 30 |
/** |
| 31 |
* @var RepresentationSerializerInterface|null The representation serializer to be injected in the client |
| 32 |
*/ |
| 33 |
private $representationSerializer; |
| 34 |
/** |
| 35 |
* @var LoggerInterface|null A PSR-3 logger to log internal errors and debug messages |
| 36 |
*/ |
| 37 |
private $logger; |
| 38 |
/** |
| 39 |
* @var string The SDK identifier, to be used in {@see Event} and {@see SentryAuth} |
| 40 |
*/ |
| 41 |
private $sdkIdentifier = Client::SDK_IDENTIFIER; |
| 42 |
/** |
| 43 |
* @var string The SDK version of the Client |
| 44 |
*/ |
| 45 |
private $sdkVersion = Client::SDK_VERSION; |
| 46 |
/** |
| 47 |
* Class constructor. |
| 48 |
* |
| 49 |
* @param Options|null $options The client options |
| 50 |
*/ |
| 51 |
public function __construct(?Options $options = null) |
| 52 |
{ |
| 53 |
$this->options = $options ?? new Options(); |
| 54 |
} |
| 55 |
/** |
| 56 |
* @param array<string, mixed> $options The client options, in naked array form |
| 57 |
*/ |
| 58 |
public static function create(array $options = []) : self |
| 59 |
{ |
| 60 |
return new self(new Options($options)); |
| 61 |
} |
| 62 |
public function getOptions() : Options |
| 63 |
{ |
| 64 |
return $this->options; |
| 65 |
} |
| 66 |
public function setRepresentationSerializer(RepresentationSerializerInterface $representationSerializer) : self |
| 67 |
{ |
| 68 |
$this->representationSerializer = $representationSerializer; |
| 69 |
return $this; |
| 70 |
} |
| 71 |
public function getLogger() : ?LoggerInterface |
| 72 |
{ |
| 73 |
return $this->logger ?? $this->options->getLogger(); |
| 74 |
} |
| 75 |
public function setLogger(LoggerInterface $logger) : self |
| 76 |
{ |
| 77 |
$this->logger = $logger; |
| 78 |
return $this; |
| 79 |
} |
| 80 |
public function setSdkIdentifier(string $sdkIdentifier) : self |
| 81 |
{ |
| 82 |
$this->sdkIdentifier = $sdkIdentifier; |
| 83 |
return $this; |
| 84 |
} |
| 85 |
public function setSdkVersion(string $sdkVersion) : self |
| 86 |
{ |
| 87 |
$this->sdkVersion = $sdkVersion; |
| 88 |
return $this; |
| 89 |
} |
| 90 |
public function getTransport() : TransportInterface |
| 91 |
{ |
| 92 |
return $this->transport ?? $this->options->getTransport() ?? new HttpTransport($this->options, $this->getHttpClient(), new PayloadSerializer($this->options), $this->getLogger()); |
| 93 |
} |
| 94 |
public function setTransport(TransportInterface $transport) : self |
| 95 |
{ |
| 96 |
$this->transport = $transport; |
| 97 |
return $this; |
| 98 |
} |
| 99 |
public function getHttpClient() : HttpClientInterface |
| 100 |
{ |
| 101 |
return $this->httpClient ?? $this->options->getHttpClient() ?? new HttpClient($this->sdkIdentifier, $this->sdkVersion); |
| 102 |
} |
| 103 |
public function setHttpClient(HttpClientInterface $httpClient) : self |
| 104 |
{ |
| 105 |
$this->httpClient = $httpClient; |
| 106 |
return $this; |
| 107 |
} |
| 108 |
public function getClient() : ClientInterface |
| 109 |
{ |
| 110 |
return new Client($this->options, $this->getTransport(), $this->sdkIdentifier, $this->sdkVersion, $this->representationSerializer, $this->getLogger()); |
| 111 |
} |
| 112 |
} |
| 113 |
|