Skip to content

Register client alias to support Symfony 5.3 Target attribute #393

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
Jul 5, 2021

Conversation

ruudk
Copy link
Contributor

@ruudk ruudk commented Jul 5, 2021

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Related tickets
Documentation if this is a new feature, link to pull request in https://github.com/php-http/documentation that adds relevant documentation
License MIT

What's in this PR?

When you are using Symfony 5.3 and you have multiple clients defined, you can use the Target
attribute to select the client that you want.

Why?

Improve Developer Experience.

Example Usage

Example:

final class MyService
{
    public function __construct(
        #[Target('my_client_alias')] 
        HttpClient $client
    ) {}
}

It will now automatically inject httplug.client.my_client_alias.

For more information:
https://symfony.com/blog/new-in-symfony-5-3-service-autowiring-with-attributes

Checklist

  • Updated CHANGELOG.md to describe BC breaks / deprecations | new feature | bugfix
  • Documentation pull request created (if not simply a bugfix)

When you are using Symfony 5.3 and you have multiple clients defined, you can use the `Target`
attribute to select the client that you want.

Example:
```php
final class MyService
{
    public function __construct(
        #[Target('my_client_alias')] HttpClient $client
    ) {}
}
```

It will now automatically inject `httplug.client.my_client_alias`.

For more information:
https://symfony.com/blog/new-in-symfony-5-3-service-autowiring-with-attributes
Copy link
Collaborator

@dbu dbu left a comment

Choose a reason for hiding this comment

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

very neat, thanks!

@dbu dbu merged commit f93fbab into php-http:master Jul 5, 2021
@dbu
Copy link
Collaborator

dbu commented Jul 5, 2021

could you add a note in https://github.com/php-http/documentation/blob/master/integrations/symfony-bundle.rst#usage that the bundle supports the target attribute?

@ruudk ruudk deleted the target-attribute branch July 10, 2021 07:33
@ruudk
Copy link
Contributor Author

ruudk commented Jul 10, 2021

@dbu Thanks for merging it. I created the PR to improve the docs php-http/documentation#287.

When you have time could you please create a new tagged release? Thanks 🙏

@dbu
Copy link
Collaborator

dbu commented Jul 10, 2021

thanks for the contribution and the documentation. i just tagged 1.21.0 with this feature.

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.

2 participants