-
-
Notifications
You must be signed in to change notification settings - Fork 452
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '4.x' into bugfix/ignore_exceptions
- Loading branch information
Showing
43 changed files
with
821 additions
and
1,519 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,36 +4,36 @@ | |
|
||
namespace Sentry; | ||
|
||
use Http\Discovery\Psr17FactoryDiscovery; | ||
use Psr\Log\LoggerInterface; | ||
use Sentry\HttpClient\HttpClientFactory; | ||
use Sentry\HttpClient\HttpClient; | ||
use Sentry\HttpClient\HttpClientInterface; | ||
use Sentry\Serializer\PayloadSerializer; | ||
use Sentry\Serializer\RepresentationSerializerInterface; | ||
use Sentry\Serializer\SerializerInterface; | ||
use Sentry\Transport\DefaultTransportFactory; | ||
use Sentry\Transport\TransportFactoryInterface; | ||
use Sentry\Transport\HttpTransport; | ||
use Sentry\Transport\TransportInterface; | ||
|
||
/** | ||
* The default implementation of {@link ClientBuilderInterface}. | ||
* A configurable builder for Client objects. | ||
* | ||
* @author Stefano Arlandini <[email protected]> | ||
* @internal | ||
*/ | ||
final class ClientBuilder implements ClientBuilderInterface | ||
final class ClientBuilder | ||
{ | ||
/** | ||
* @var Options The client options | ||
*/ | ||
private $options; | ||
|
||
/** | ||
* @var TransportFactoryInterface|null The transport factory | ||
* @var TransportInterface The transport | ||
*/ | ||
private $transportFactory; | ||
private $transport; | ||
|
||
/** | ||
* @var TransportInterface|null The transport | ||
* @var HttpClientInterface The HTTP client | ||
*/ | ||
private $transport; | ||
private $httpClient; | ||
|
||
/** | ||
* @var SerializerInterface|null The serializer to be injected in the client | ||
|
@@ -68,127 +68,97 @@ final class ClientBuilder implements ClientBuilderInterface | |
public function __construct(Options $options = null) | ||
{ | ||
$this->options = $options ?? new Options(); | ||
|
||
$this->httpClient = $this->options->getHttpClient() ?? new HttpClient($this->sdkIdentifier, $this->sdkVersion); | ||
$this->transport = $this->options->getTransport() ?? new HttpTransport( | ||
$this->options, | ||
$this->httpClient, | ||
new PayloadSerializer($this->options), | ||
$this->logger | ||
); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
* @param array<string, mixed> $options The client options, in naked array form | ||
*/ | ||
public static function create(array $options = []): ClientBuilderInterface | ||
public static function create(array $options = []): ClientBuilder | ||
{ | ||
return new self(new Options($options)); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getOptions(): Options | ||
{ | ||
return $this->options; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function setSerializer(SerializerInterface $serializer): ClientBuilderInterface | ||
public function setSerializer(SerializerInterface $serializer): ClientBuilder | ||
{ | ||
$this->serializer = $serializer; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function setRepresentationSerializer(RepresentationSerializerInterface $representationSerializer): ClientBuilderInterface | ||
public function setRepresentationSerializer(RepresentationSerializerInterface $representationSerializer): ClientBuilder | ||
{ | ||
$this->representationSerializer = $representationSerializer; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function setLogger(LoggerInterface $logger): ClientBuilderInterface | ||
public function setLogger(LoggerInterface $logger): ClientBuilder | ||
{ | ||
$this->logger = $logger; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function setSdkIdentifier(string $sdkIdentifier): ClientBuilderInterface | ||
public function setSdkIdentifier(string $sdkIdentifier): ClientBuilder | ||
{ | ||
$this->sdkIdentifier = $sdkIdentifier; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function setSdkVersion(string $sdkVersion): ClientBuilderInterface | ||
public function setSdkVersion(string $sdkVersion): ClientBuilder | ||
{ | ||
$this->sdkVersion = $sdkVersion; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function setTransportFactory(TransportFactoryInterface $transportFactory): ClientBuilderInterface | ||
public function getTransport(): TransportInterface | ||
{ | ||
$this->transportFactory = $transportFactory; | ||
|
||
return $this; | ||
return $this->transport; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getClient(): ClientInterface | ||
public function setTransport(TransportInterface $transport): ClientBuilder | ||
{ | ||
$this->transport = $this->transport ?? $this->createTransportInstance(); | ||
$this->transport = $transport; | ||
|
||
return new Client($this->options, $this->transport, $this->sdkIdentifier, $this->sdkVersion, $this->serializer, $this->representationSerializer, $this->logger); | ||
return $this; | ||
} | ||
|
||
/** | ||
* Creates a new instance of the transport mechanism. | ||
*/ | ||
private function createTransportInstance(): TransportInterface | ||
public function getHttpClient(): HttpClientInterface | ||
{ | ||
if (null !== $this->transport) { | ||
return $this->transport; | ||
} | ||
return $this->httpClient; | ||
} | ||
|
||
$transportFactory = $this->transportFactory ?? $this->createDefaultTransportFactory(); | ||
public function setHttpClient(HttpClientInterface $httpClient): ClientBuilder | ||
{ | ||
$this->httpClient = $httpClient; | ||
|
||
return $transportFactory->create($this->options); | ||
return $this; | ||
} | ||
|
||
/** | ||
* Creates a new instance of the {@see DefaultTransportFactory} factory. | ||
*/ | ||
private function createDefaultTransportFactory(): DefaultTransportFactory | ||
public function getClient(): ClientInterface | ||
{ | ||
$streamFactory = Psr17FactoryDiscovery::findStreamFactory(); | ||
$httpClientFactory = new HttpClientFactory( | ||
null, | ||
null, | ||
$streamFactory, | ||
null, | ||
return new Client( | ||
$this->options, | ||
$this->transport, | ||
$this->sdkIdentifier, | ||
$this->sdkVersion | ||
); | ||
|
||
return new DefaultTransportFactory( | ||
$streamFactory, | ||
Psr17FactoryDiscovery::findRequestFactory(), | ||
$httpClientFactory, | ||
$this->sdkVersion, | ||
$this->serializer, | ||
$this->representationSerializer, | ||
$this->logger | ||
); | ||
} | ||
|
Oops, something went wrong.