Skip to content

Do not register default HttpClient to prevent auto wire issues #312

@ruudk

Description

@ruudk
Q A
Bug? no
New Feature? yes
Version 1.14.0

Actual Behavior

We are heavily using Symfony's auto wire functionality. Sometimes, developer inject HttpClient in the constructor without actually specifying the exact httplug.client.name. No error is thrown, and HTTPlug just picks the httplug.client.default service (or the first client it can find)

Expected Behavior

Don't register a default Http\Client\HttpClient service and Symfony will automatically warn the developer that multiple services of Http\Client\HttpClient exist. Developer is then notified about this and will think :)

Possible Solutions

I really propose to get rid of this behaviour in the next major version of this bundle.

Related code

// If we do not have a client named 'default'
if (!array_key_exists('default', $config['clients'])) {
$serviceId = 'httplug.client.'.$first;
// Alias the first client to httplug.client.default
$container->setAlias('httplug.client.default', $serviceId);
$default = $first;
} else {
$default = 'default';
}

<service id="httplug.client.default" class="Http\Client\HttpClient">
<factory class="Http\Discovery\HttpClientDiscovery" method="find" />
</service>

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