Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

nicolas-grekas
Copy link
Contributor

@nicolas-grekas nicolas-grekas commented Oct 24, 2022

Related to #1411 and FriendsOfPHP/well-known-implementations#2

In this PR, I propose to rely on FriendsOfPHP/well-known-implementations to ensure a working out-of-the-box experience. This package is a composer-plugin that will install the most suited async-http-implementation depending on the existing dependencies of the projects that require sentry-php.

The package also provides a discovery mechanism that covers roughly the same purpose as php-http/discovery, but that plays well with the plugin part of the package.

The attached patch removes php-http/discovery from the mandatory dependencies, but also removes the dependency on guzzlehttp/psr7.

@@ -89,6 +89,7 @@
"sort-packages": true,
"allow-plugins": {
"composer/package-versions-deprecated": true,
"friendsofphp/well-known-implementations": false,
Copy link
Contributor Author

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.

Psr17FactoryDiscovery::findResponseFactory(),
$streamFactory,
null,
null,
Copy link
Contributor Author

@nicolas-grekas nicolas-grekas Oct 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first two arguments of HttpClientFactory are never used. We can thus make them nullable and skip injecting factories there.

UriFactoryInterface $uriFactory,
ResponseFactoryInterface $responseFactory,
?UriFactoryInterface $uriFactory,
?ResponseFactoryInterface $responseFactory,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those arguments are never used, no need to force passing anything.

@@ -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) {
Copy link
Contributor Author

@nicolas-grekas nicolas-grekas Oct 24, 2022

Choose a reason for hiding this comment

The 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)

@@ -22,6 +22,6 @@ public function fetchRequest(): ?ServerRequestInterface
return null;
}

return ServerRequest::fromGlobals();
return (new WellKnownPsr17Factory())->createServerRequestFromGlobals();
Copy link
Contributor Author

@nicolas-grekas nicolas-grekas Oct 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This removes the coupling to guzzlehttp/psr7: "well-known-implem" provides the same feature, but compatible with any PSR-7 implementations.

@@ -12,8 +10,6 @@

require_once __DIR__ . '/../vendor/autoload.php';

ClassDiscovery::appendStrategy(MockClientStrategy::class);
Copy link
Contributor Author

@nicolas-grekas nicolas-grekas Oct 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"well-known-implem" will discover and auto-load php-http/mock-client when no other implem is found.

@cleptric
Copy link
Member

cleptric commented Oct 24, 2022

Thanks for proposing this @nicolas-grekas

This is definitely something we will consider when making a decision on the path forward in the next major version of the SDK.

@cleptric cleptric added this to the 4.0 milestone Oct 24, 2022
@cleptric cleptric marked this pull request as draft October 24, 2022 20:05
@cleptric
Copy link
Member

After talking to @nicolas-grekas at SymfonyCon, I'm going to close this.
There might be a change in how this will land in the Sentry SDK, so we can come back to this at a later date 🙂

@cleptric cleptric closed this Nov 21, 2022
@nicolas-grekas nicolas-grekas deleted the well-known branch January 20, 2023 16:51
@nicolas-grekas
Copy link
Contributor Author

@cleptric here is the result of what we talked about at SymfonyCon: php-http/discovery#208

@nicolas-grekas nicolas-grekas mentioned this pull request Jan 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants