Skip to content

AutoWiring and HttpMethodsClient #261

Closed
@soullivaneuh

Description

@soullivaneuh
Q A
Bug? no
New Feature? yes
Version 1.10.0

With the following configuration:

httplug:
    clients:
        default:
            factory: 'httplug.factory.guzzle6'
            config:
                timeout: 5

The bundle provide autowiring for the default http client:

  Http\Client\HttpAsyncClient                                                                     
      alias to httplug.async_client.default                                                       
  Http\Client\HttpClient                                                                          
      alias to httplug.client.default                                                             

It's also possible to enable the http methods client:

httplug:
    clients:
        default:
            factory: 'httplug.factory.guzzle6'
            config:
                timeout: 5
            http_methods_client: true

But the autowiring still rely on HttpClient interface:

  Http\Client\HttpAsyncClient                                                                     
      alias to httplug.async_client.default                                                       
  Http\Client\HttpClient                                                                          
      alias to httplug.client.default.http_methods                                                

So, we of course have a HttpMethodsClient, but the following code sample does not rely on anything:

public function faviconRedirectAction(string $domain, int $minSize, HttpClient $client): Response
{
    dump($client);die;

And we have to check this with instanceof in order to not make some tools like PHPStan crying a lot.

It would be wonderful to be able to do something like this:

public function faviconRedirectAction(string $domain, int $minSize, HttpMethodsClient $client): Response
{
    dump($client);die;

And directly have autowiring working.

What do you think?

The workaround for people interested like me is pretty simple, one line on your services definition:

services:
    Http\Client\Common\HttpMethodsClient: '@httplug.client.default.http_methods'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions