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

symfony httplug adapter needs php-http httplug to be installed #202

Merged
merged 1 commit into from May 25, 2022

Conversation

dbu
Copy link
Contributor

@dbu dbu commented Nov 11, 2021

if we don't check for the httplug client interface, we trigger a warning:
https://github.com/symfony/http-client/blob/290eb481973b4984eb59377585f6afbc65a0f645/HttplugClient.php#L44

Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Related tickets fixes #201
Documentation -
License MIT

What's in this PR?

avoid having symfony trigger a warning when symfony httplug client is not usable due to missing dependencies.

@dbu
Copy link
Contributor Author

dbu commented Nov 11, 2021

i don't have time to do #200 - we should convert from travis-ci to github actions to have the tests actually run in this repository.

src/Psr18ClientDiscovery.php Show resolved Hide resolved
['class' => Guzzle7::class, 'condition' => Guzzle7::class],
['class' => Guzzle6::class, 'condition' => Guzzle6::class],
['class' => Curl::class, 'condition' => Curl::class],
['class' => React::class, 'condition' => React::class],
],
HttpClient::class => [
['class' => SymfonyHttplug::class, 'condition' => [SymfonyHttplug::class, RequestFactory::class, [self::class, 'isPsr17FactoryInstalled']]],
['class' => SymfonyHttplug::class, 'condition' => [SymfonyHttplug::class, HttpClient::class, RequestFactory::class, [self::class, 'isPsr17FactoryInstalled']]],
Copy link

@asgrim asgrim Nov 11, 2021

Choose a reason for hiding this comment

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

Unfortunately this does not seem to change anything. Symfony throws a \LogicException outside of the class structure, so as soon as the file is loaded, and php-http/httplug is missing, the \LogicException is thrown.

Then in \Http\Discovery\Strategy\CommonClassesStrategy::getPsr18Candidates, that \LogicException is caught, and converted to a trigger_error:

try {
if (is_subclass_of($c['class'], Psr18Client::class)) {
$candidates[] = $c;
}
} catch (\Throwable $e) {
trigger_error(sprintf('Got exception "%s (%s)" while checking if a PSR-18 Client is available', get_class($e), $e->getMessage()), E_USER_WARNING);
}

In trying to debug this, the only ways I found this was working was to turn that try/catch into silence (not ideal...):

            try {
                if (is_subclass_of($c['class'], Psr18Client::class)) {
                    $candidates[] = $c;
                }
            } catch (\Throwable $e) {
                //trigger_error(sprintf('Got exception "%s (%s)" while checking if a PSR-18 Client is available', get_class($e), $e->getMessage()), E_USER_WARNING);
            }

but ALSO you would need to add HttpClient::class as a condition to symfonyPsr18Instantiate under the Psr18Client::class definitions:

        Psr18Client::class => [
            [
                'class' => [self::class, 'symfonyPsr18Instantiate'],
                'condition' => [HttpClient::class, SymfonyPsr18::class, Psr17RequestFactory::class],
            ],

Silencing the exception feels very wrong, but with a clear comment explaining why, it might be OK, as it doesn't look like there is a logger around to log a warning to.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

right the problem occurs before conditions are even checked. i realized that we need to use our safe class exists here as well. changed to use that and in my small reproducer that makes the trigger_error go away.

@dbu dbu force-pushed the fix-symfony-client-strategy branch 3 times, most recently from b373504 to 9ff61d3 Compare May 25, 2022 06:49
@dbu
Copy link
Contributor Author

dbu commented May 25, 2022

@asgrim old issue... i re-read the thing and updated the PR to something that should actually solve the problem you encountered and is cleaner

@asgrim
Copy link

asgrim commented May 25, 2022

Thank you @dbu !

@dbu dbu force-pushed the fix-symfony-client-strategy branch from 9ff61d3 to 94ddf9e Compare May 25, 2022 07:23
@dbu dbu merged commit 3943279 into master May 25, 2022
@dbu dbu deleted the fix-symfony-client-strategy branch May 25, 2022 07:23
@dbu
Copy link
Contributor Author

dbu commented May 25, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Undocumented error triggered when using Discovery with Symfony when php-http/httplug not installed
2 participants