-
-
Notifications
You must be signed in to change notification settings - Fork 452
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Decouple from "guzzlehttp/psr7" and "php-http/discovery", replace by "friendsofphp/well-known-implementations" #1418
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
|
||
namespace Sentry; | ||
|
||
use Http\Discovery\Psr17FactoryDiscovery; | ||
use FriendsOfPHP\WellKnownImplementations\WellKnownPsr17Factory; | ||
use Psr\Log\LoggerInterface; | ||
use Sentry\HttpClient\HttpClientFactory; | ||
use Sentry\Serializer\RepresentationSerializerInterface; | ||
|
@@ -175,19 +175,19 @@ private function createTransportInstance(): TransportInterface | |
*/ | ||
private function createDefaultTransportFactory(): DefaultTransportFactory | ||
{ | ||
$streamFactory = Psr17FactoryDiscovery::findStreamFactory(); | ||
$psr17Factory = new WellKnownPsr17Factory(); | ||
$httpClientFactory = new HttpClientFactory( | ||
Psr17FactoryDiscovery::findUriFactory(), | ||
Psr17FactoryDiscovery::findResponseFactory(), | ||
$streamFactory, | ||
null, | ||
null, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The first two arguments of |
||
$psr17Factory, | ||
null, | ||
$this->sdkIdentifier, | ||
$this->sdkVersion | ||
); | ||
|
||
return new DefaultTransportFactory( | ||
$streamFactory, | ||
Psr17FactoryDiscovery::findRequestFactory(), | ||
$psr17Factory, | ||
$psr17Factory, | ||
$httpClientFactory, | ||
$this->logger | ||
); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,8 @@ | |
|
||
namespace Sentry\HttpClient; | ||
|
||
use FriendsOfPHP\WellKnownImplementations\ConcreteImplementation; | ||
use FriendsOfPHP\WellKnownImplementations\WellKnownHttplugClient; | ||
use GuzzleHttp\RequestOptions as GuzzleHttpClientOptions; | ||
use Http\Adapter\Guzzle6\Client as GuzzleHttpClient; | ||
use Http\Client\Common\Plugin\AuthenticationPlugin; | ||
|
@@ -14,7 +16,6 @@ | |
use Http\Client\Common\PluginClient; | ||
use Http\Client\Curl\Client as CurlHttpClient; | ||
use Http\Client\HttpAsyncClient as HttpAsyncClientInterface; | ||
use Http\Discovery\HttpAsyncClientDiscovery; | ||
use Psr\Http\Client\ClientInterface; | ||
use Psr\Http\Message\ResponseFactoryInterface; | ||
use Psr\Http\Message\StreamFactoryInterface; | ||
|
@@ -54,16 +55,16 @@ final class HttpClientFactory implements HttpClientFactoryInterface | |
/** | ||
* Constructor. | ||
* | ||
* @param UriFactoryInterface $uriFactory The PSR-7 URI factory | ||
* @param ResponseFactoryInterface $responseFactory The PSR-7 response factory | ||
* @param UriFactoryInterface|null $uriFactory The PSR-7 URI factory | ||
* @param ResponseFactoryInterface|null $responseFactory The PSR-7 response factory | ||
* @param StreamFactoryInterface $streamFactory The PSR-17 stream factory | ||
* @param HttpAsyncClientInterface|null $httpClient The HTTP client | ||
* @param string $sdkIdentifier The SDK identifier | ||
* @param string $sdkVersion The SDK version | ||
*/ | ||
public function __construct( | ||
UriFactoryInterface $uriFactory, | ||
ResponseFactoryInterface $responseFactory, | ||
?UriFactoryInterface $uriFactory, | ||
?ResponseFactoryInterface $responseFactory, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Those arguments are never used, no need to force passing anything. |
||
StreamFactoryInterface $streamFactory, | ||
?HttpAsyncClientInterface $httpClient, | ||
string $sdkIdentifier, | ||
|
@@ -110,7 +111,7 @@ public function create(Options $options): HttpAsyncClientInterface | |
*/ | ||
private function resolveClient(Options $options) | ||
{ | ||
if (class_exists(SymfonyHttplugClient::class)) { | ||
if (ConcreteImplementation::VENDOR_SYMFONY === ConcreteImplementation::HTTPLUG_VENDOR) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using these consts gives more control over which implementation should be used (the consts are generated by the plugin xor computed at autoload-time when the plugin is disabled) |
||
$symfonyConfig = [ | ||
'timeout' => $options->getHttpConnectTimeout(), | ||
'max_duration' => $options->getHttpTimeout(), | ||
|
@@ -123,7 +124,7 @@ private function resolveClient(Options $options) | |
return new SymfonyHttplugClient(SymfonyHttpClient::create($symfonyConfig)); | ||
} | ||
|
||
if (class_exists(GuzzleHttpClient::class)) { | ||
if (ConcreteImplementation::VENDOR_HTTPLUG_GUZZLE6 === ConcreteImplementation::HTTPLUG_VENDOR) { | ||
$guzzleConfig = [ | ||
GuzzleHttpClientOptions::TIMEOUT => $options->getHttpTimeout(), | ||
GuzzleHttpClientOptions::CONNECT_TIMEOUT => $options->getHttpConnectTimeout(), | ||
|
@@ -136,7 +137,7 @@ private function resolveClient(Options $options) | |
return GuzzleHttpClient::createWithConfig($guzzleConfig); | ||
} | ||
|
||
if (class_exists(CurlHttpClient::class)) { | ||
if (ConcreteImplementation::VENDOR_HTTPLUG_CURL === ConcreteImplementation::HTTPLUG_VENDOR) { | ||
$curlConfig = [ | ||
\CURLOPT_TIMEOUT => $options->getHttpTimeout(), | ||
\CURLOPT_CONNECTTIMEOUT => $options->getHttpConnectTimeout(), | ||
|
@@ -153,6 +154,6 @@ private function resolveClient(Options $options) | |
throw new \RuntimeException('The "http_proxy" option requires either the "php-http/curl-client", the "symfony/http-client" or the "php-http/guzzle6-adapter" package to be installed.'); | ||
} | ||
|
||
return HttpAsyncClientDiscovery::find(); | ||
return new WellKnownHttplugClient(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
|
||
namespace Sentry\Integration; | ||
|
||
use GuzzleHttp\Psr7\ServerRequest; | ||
use FriendsOfPHP\WellKnownImplementations\WellKnownPsr17Factory; | ||
use Psr\Http\Message\ServerRequestInterface; | ||
|
||
/** | ||
|
@@ -22,6 +22,6 @@ public function fetchRequest(): ?ServerRequestInterface | |
return null; | ||
} | ||
|
||
return ServerRequest::fromGlobals(); | ||
return (new WellKnownPsr17Factory())->createServerRequestFromGlobals(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This removes the coupling to |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +2,6 @@ | |
|
||
declare(strict_types=1); | ||
|
||
use Http\Discovery\ClassDiscovery; | ||
use Http\Discovery\Strategy\MockClientStrategy; | ||
use Sentry\Breadcrumb; | ||
use Sentry\Event; | ||
use Sentry\Tracing\Span; | ||
|
@@ -12,8 +10,6 @@ | |
|
||
require_once __DIR__ . '/../vendor/autoload.php'; | ||
|
||
ClassDiscovery::appendStrategy(MockClientStrategy::class); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "well-known-implem" will discover and auto-load |
||
|
||
// According to the Symfony documentation the proper way to register the mocked | ||
// functions for a certain class would be to configure the listener in the | ||
// phpunit.xml file, however in our case it doesn't work because PHPUnit loads | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Running the plugin is not needed for tests. Only the "lib" part of the package is used when running the CI.