Skip to content

Commit f9dbfbf

Browse files
Merge branch '4.4' into 5.0
* 4.4: [DependencyInjection] Fix binding tagged services to containers [ProxyManager] fix generating proxies for root-namespaced classes [DI] skip looking for config class when the extension class is anonymous Fix typo Docs - Update debug section of UPGRADE guides for 4.4 and 5.0 versions. [Dotenv] FIX missing getenv [HttpFoundation] fix pdo session handler for sqlsrv [HttpClient][Psr18Client] Remove Psr18ExceptionTrait [HttpKernel] ignore failuresgenerated by opcache.restrict_api
2 parents 78eb1ed + 79b0358 commit f9dbfbf

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
lines changed

Compiler/ResolveBindingsPass.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\DependencyInjection\Compiler;
1313

1414
use Symfony\Component\DependencyInjection\Argument\BoundArgument;
15+
use Symfony\Component\DependencyInjection\Argument\ServiceLocatorArgument;
1516
use Symfony\Component\DependencyInjection\Argument\TaggedIteratorArgument;
1617
use Symfony\Component\DependencyInjection\ContainerBuilder;
1718
use Symfony\Component\DependencyInjection\Definition;
@@ -126,8 +127,8 @@ protected function processValue($value, bool $isRoot = false)
126127
continue;
127128
}
128129

129-
if (null !== $bindingValue && !$bindingValue instanceof Reference && !$bindingValue instanceof Definition && !$bindingValue instanceof TaggedIteratorArgument) {
130-
throw new InvalidArgumentException(sprintf('Invalid value for binding key "%s" for service "%s": expected null, an instance of %s or an instance of %s or an instance of %s, %s given.', $key, $this->currentId, Reference::class, Definition::class, TaggedIteratorArgument::class, \gettype($bindingValue)));
130+
if (null !== $bindingValue && !$bindingValue instanceof Reference && !$bindingValue instanceof Definition && !$bindingValue instanceof TaggedIteratorArgument && !$bindingValue instanceof ServiceLocatorArgument) {
131+
throw new InvalidArgumentException(sprintf('Invalid value for binding key "%s" for service "%s": expected null, %s, %s, %s or ServiceLocatorArgument, %s given.', $key, $this->currentId, Reference::class, Definition::class, TaggedIteratorArgument::class, \gettype($bindingValue)));
131132
}
132133
}
133134

Extension/Extension.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ public function getAlias()
8181
public function getConfiguration(array $config, ContainerBuilder $container)
8282
{
8383
$class = \get_class($this);
84+
85+
if (false !== strpos($class, "\0")) {
86+
return null; // ignore anonymous classes
87+
}
88+
8489
$class = substr_replace($class, '\Configuration', strrpos($class, '\\'));
8590
$class = $container->getReflectionClass($class);
8691

Tests/Compiler/ResolveBindingsPassTest.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\DependencyInjection\Argument\BoundArgument;
16+
use Symfony\Component\DependencyInjection\Argument\ServiceLocatorArgument;
1617
use Symfony\Component\DependencyInjection\Argument\TaggedIteratorArgument;
1718
use Symfony\Component\DependencyInjection\Compiler\AutowireRequiredMethodsPass;
1819
use Symfony\Component\DependencyInjection\Compiler\DefinitionErrorExceptionPass;
@@ -35,6 +36,7 @@ public function testProcess()
3536

3637
$bindings = [
3738
CaseSensitiveClass::class => new BoundArgument(new Reference('foo')),
39+
'Psr\Container\ContainerInterface $container' => new BoundArgument(new ServiceLocatorArgument([]), true, BoundArgument::INSTANCEOF_BINDING),
3840
'iterable $objects' => new BoundArgument(new TaggedIteratorArgument('tag.name'), true, BoundArgument::INSTANCEOF_BINDING),
3941
];
4042

@@ -49,7 +51,13 @@ public function testProcess()
4951
$pass = new ResolveBindingsPass();
5052
$pass->process($container);
5153

52-
$this->assertEquals([0 => new Reference('foo'), 1 => '123', 4 => new TaggedIteratorArgument('tag.name')], $definition->getArguments());
54+
$expected = [
55+
0 => new Reference('foo'),
56+
1 => '123',
57+
3 => new ServiceLocatorArgument([]),
58+
4 => new TaggedIteratorArgument('tag.name'),
59+
];
60+
$this->assertEquals($expected, $definition->getArguments());
5361
$this->assertEquals([['setSensitiveClass', [new Reference('foo')]]], $definition->getMethodCalls());
5462
}
5563

Tests/Fixtures/NamedArgumentsDummy.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*/
1010
class NamedArgumentsDummy
1111
{
12-
public function __construct(CaseSensitiveClass $c, $apiKey, $hostName, ContainerInterface $interface, iterable $objects)
12+
public function __construct(CaseSensitiveClass $c, $apiKey, $hostName, ContainerInterface $container, iterable $objects)
1313
{
1414
}
1515

0 commit comments

Comments
 (0)