Skip to content

[FrameworkBundle][HttpClient] Refactor http_client decoration strategy #49513

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

Merged
merged 1 commit into from
Feb 24, 2023

Conversation

fancyweb
Copy link
Contributor

Q A
Branch? 6.3
Bug fix? no
New feature? no
Deprecations? no
Tickets #49302 (comment)
License MIT
Doc PR -

@nicolas-grekas
Copy link
Member

Rebase unlocked after #49302

@fancyweb fancyweb force-pushed the fwb/http-client-cfg branch 2 times, most recently from 52e5f75 to 237f7b6 Compare February 24, 2023 08:48
@@ -2413,7 +2406,7 @@ private function registerHttpClientConfiguration(array $config, ContainerBuilder
->register($name.'.uri_template', UriTemplateHttpClient::class)
->setDecoratedService($name, null, 7) // Between TraceableHttpClient (5) and RetryableHttpClient (10)
->setArguments([
new Reference('.inner'),
new Reference($name.'.uri_template.inner'),
Copy link
Member

Choose a reason for hiding this comment

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

let's be consistent with the rest of the file


->set('http_client', HttpClientInterface::class)
->factory('current')
->args([[service('http_client.transport')]])
Copy link
Member

@nicolas-grekas nicolas-grekas Feb 24, 2023

Choose a reason for hiding this comment

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

Here is the master trick of this PR :)
This creates what I'd call a "tagged alias".

@nicolas-grekas
Copy link
Member

Thank you @fancyweb.

@nicolas-grekas nicolas-grekas merged commit 3b207f2 into symfony:6.3 Feb 24, 2023
nicolas-grekas added a commit that referenced this pull request Feb 24, 2023
… used as service factory (nicolas-grekas)

This PR was merged into the 6.3 branch.

Discussion
----------

[DependencyInjection] Optimize out "current()" when it's used as service factory

| Q             | A
| ------------- | ---
| Branch?       | 6.3
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | -

Sometimes, we need to use the "identity function" as a service factory.
One example is #49513, where we use that to create a "tagged alias".

In PHP, the identity function is `current([$foo])`.
Let's optimize out such calls.

Commits
-------

834a550 [DependencyInjection] Optimize out "current()" when it's used as service factory
@fancyweb fancyweb deleted the fwb/http-client-cfg branch February 24, 2023 14:53
fabpot added a commit that referenced this pull request Jan 2, 2025
… (HypeMC)

This PR was merged into the 6.4 branch.

Discussion
----------

[HttpClient] Fix `reset()` not called on decorated clients

| Q             | A
| ------------- | ---
| Branch?       | 6.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Issues        | -
| License       | MIT

This was broken in #49513 for the main HTTP client and, as far as I can tell, never worked for scoped clients. The problem is that some decorator clients, like the `ThrottlingHttpClient`, have their own `reset()` method, which never gets called when using the `services_resetter` service. Scoped clients don't decorate the main one but instead use it as a dependency.

Commits
-------

8f5f98a [HttpClient] Fix reset not called on decorated clients
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.

3 participants