Merge branch '4.3' into 4.4

* 4.3:
  Re-enable push support for HttpClient
  [DependencyInjection] Accept existing interfaces as valid named args
  Fixed incompatibility between ServiceSubscriberTrait and classes with protected $container property
This commit is contained in:
Nicolas Grekas 2019-09-11 10:38:59 +02:00
commit 789448b65c
5 changed files with 20 additions and 4 deletions

View File

@ -53,7 +53,7 @@ class ResolveNamedArgumentsPass extends AbstractRecursivePass
$parameters = $r->getParameters();
}
if (isset($key[0]) && '$' !== $key[0] && !class_exists($key)) {
if (isset($key[0]) && '$' !== $key[0] && !class_exists($key) && !interface_exists($key, false)) {
throw new InvalidArgumentException(sprintf('Invalid service "%s": did you forget to add the "$" prefix to argument "%s"?', $this->currentId, $key));
}

View File

@ -12,6 +12,7 @@
namespace Symfony\Component\DependencyInjection\Tests\Compiler;
use PHPUnit\Framework\TestCase;
use Psr\Container\ContainerInterface;
use Symfony\Component\DependencyInjection\Compiler\ResolveNamedArgumentsPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
@ -152,6 +153,19 @@ class ResolveNamedArgumentsPassTest extends TestCase
$pass->process($container);
}
public function testInterfaceTypedArgument()
{
$container = new ContainerBuilder();
$definition = $container->register(NamedArgumentsDummy::class, NamedArgumentsDummy::class);
$definition->setArgument(ContainerInterface::class, $expected = new Reference('foo'));
$pass = new ResolveNamedArgumentsPass();
$pass->process($container);
$this->assertSame($expected, $definition->getArgument(3));
}
public function testResolvesMultipleArgumentsOfTheSameType()
{
$container = new ContainerBuilder();

View File

@ -2,12 +2,14 @@
namespace Symfony\Component\DependencyInjection\Tests\Fixtures;
use Psr\Container\ContainerInterface;
/**
* @author Kévin Dunglas <dunglas@gmail.com>
*/
class NamedArgumentsDummy
{
public function __construct(CaseSensitiveClass $c, $apiKey, $hostName)
public function __construct(CaseSensitiveClass $c, $apiKey, $hostName, ContainerInterface $interface)
{
}

View File

@ -58,7 +58,7 @@ final class CurlHttpClient implements HttpClientInterface, LoggerAwareInterface
*
* @see HttpClientInterface::OPTIONS_DEFAULTS for available options
*/
public function __construct(array $defaultOptions = [], int $maxHostConnections = 6, int $maxPendingPushes = 0)
public function __construct(array $defaultOptions = [], int $maxHostConnections = 6, int $maxPendingPushes = 50)
{
if (!\extension_loaded('curl')) {
throw new \LogicException('You cannot use the "Symfony\Component\HttpClient\CurlHttpClient" as the "curl" extension is not installed.');

View File

@ -22,7 +22,7 @@ use Psr\Container\ContainerInterface;
trait ServiceSubscriberTrait
{
/** @var ContainerInterface */
private $container;
protected $container;
public static function getSubscribedServices(): array
{