Skip to content

Add autowiring for HTTPlug #32104

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
Jun 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Doctrine\Common\Annotations\AnnotationRegistry;
use Doctrine\Common\Annotations\Reader;
use Http\Client\HttpClient;
use Psr\Cache\CacheItemPoolInterface;
use Psr\Container\ContainerInterface as PsrContainerInterface;
use Psr\Http\Client\ClientInterface;
Expand Down Expand Up @@ -60,7 +61,6 @@
use Symfony\Component\Form\FormTypeExtensionInterface;
use Symfony\Component\Form\FormTypeGuesserInterface;
use Symfony\Component\Form\FormTypeInterface;
use Symfony\Component\HttpClient\Psr18Client;
use Symfony\Component\HttpClient\ScopingHttpClient;
use Symfony\Component\HttpKernel\CacheClearer\CacheClearerInterface;
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
Expand Down Expand Up @@ -1881,6 +1881,10 @@ private function registerHttpClientConfiguration(array $config, ContainerBuilder
$container->removeAlias(ClientInterface::class);
}

if (!interface_exists(HttpClient::class)) {
$container->removeDefinition(HttpClient::class);
}

foreach ($config['scoped_clients'] as $name => $scopeConfig) {
if ('http_client' === $name) {
throw new InvalidArgumentException(sprintf('Invalid scope name: "%s" is reserved.', $name));
Expand All @@ -1901,9 +1905,8 @@ private function registerHttpClientConfiguration(array $config, ContainerBuilder
$container->registerAliasForArgument($name, HttpClientInterface::class);

if ($hasPsr18) {
$container->register('psr18.'.$name, Psr18Client::class)
->setAutowired(true)
->setArguments([new Reference($name)]);
$container->setDefinition('psr18.'.$name, new ChildDefinition('psr18.http_client'))
->replaceArgument(0, new Reference($name));
Copy link
Member Author

Choose a reason for hiding this comment

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

this change is not related to httplug - it's just better way to wire the psr18 named aliases


$container->registerAliasForArgument('psr18.'.$name, ClientInterface::class, $name);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,11 @@
<argument type="service" id="Psr\Http\Message\StreamFactoryInterface" on-invalid="ignore" />
</service>
<service id="Psr\Http\Client\ClientInterface" alias="psr18.http_client" />

<service id="Http\Client\HttpClient" class="Symfony\Component\HttpClient\HttplugClient">
Copy link
Member Author

Choose a reason for hiding this comment

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

not an alias so that it's not listed in debug:autowiring - no need to promote the alias for autowiring

<argument type="service" id="http_client" />
<argument type="service" id="Http\Message\ResponseFactory" on-invalid="ignore" />
<argument type="service" id="Http\Message\StreamFactory" on-invalid="ignore" />
</service>
</services>
</container>