8000 bug #45063 [DependencyInjection] remove arbitratry limitation to excl… · symfony/symfony@b8656d4 · GitHub
[go: up one dir, main page]

Skip to content

Commit b8656d4

Browse files
bug #45063 [DependencyInjection] remove arbitratry limitation to exclude inline services from bindings (nicolas-grekas)
This PR was merged into the 4.4 branch. Discussion ---------- [DependencyInjection] remove arbitratry limitation to exclude inline services from bindings | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #40469 | License | MIT | Doc PR | - Commits ------- e959849 [DependencyInjection] remove arbitratry limitation to exclude inline services from bindings
2 parents a010891 + e959849 commit b8656d4

File tree

4 files changed

+4
-8
lines changed

4 files changed

+4
-8
lines changed

src/Symfony/Component/DependencyInjection/Loader/Configurator/Traits/BindTrait.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@
1212
namespace Symfony\Component\DependencyInjection\Loader\Configurator\Traits;
1313

1414
use Symfony\Component\DependencyInjection\Argument\BoundArgument;
15-
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
1615
use Symfony\Component\DependencyInjection\Loader\Configurator\DefaultsConfigurator;
1716
use Symfony\Component\DependencyInjection\Loader\Configurator\InstanceofConfigurator;
18-
use Symfony\Component\DependencyInjection\Reference;
1917

2018
trait BindTrait
2119
{
@@ -34,9 +32,6 @@ trait BindTrait
3432
final public function bind(string $nameOrFqcn, $valueOrRef): self
3533
{
3634
$valueOrRef = static::processValue($valueOrRef, true);
37-
if (!preg_match('/^(?:(?:array|bool|float|int|string|iterable)[ \t]*+)?\$/', $nameOrFqcn) && !$valueOrRef instanceof Reference) {
38-
throw new InvalidArgumentException(sprintf('Invalid binding for service "%s": named arguments must start with a "$", and FQCN must map to references. Neither applies to binding "%s".', $this->id, $nameOrFqcn));
39-
}
4035
$bindings = $this->definition->getBindings();
4136
$type = $this instanceof DefaultsConfigurator ? BoundArgument::DEFAULTS_BINDING : ($this instanceof InstanceofConfigurator ? BoundArgument::INSTANCEOF_BINDING : BoundArgument::SERVICE_BINDING);
4237
$bindings[$nameOrFqcn] = new BoundArgument($valueOrRef, true, $type, $this->path ?? null);

src/Symfony/Component/DependencyInjection/Tests/Fixtures/Prototype/Foo.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
class Foo implements FooInterface, Sub\BarInterface
66
{
7-
public function __construct($bar = null, iterable $foo = null)
7+
public function __construct($bar = null, iterable $foo = null, object $baz = null)
88
{
99
}
1010

src/Symfony/Component/DependencyInjection/Tests/Fixtures/config/defaults.expected.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ services:
1515
- { name: t, a: b }
1616
autowire: true
1717
autoconfigure: true
18-
arguments: ['@bar', !tagged_iterator foo]
18+
arguments: ['@bar', !tagged_iterator foo, !service { class: Baz }]
1919
bar:
2020
class: Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Foo
2121
public: true
2222
tags:
2323
- { name: t, a: b }
2424
autowire: true
25-
arguments: [null, !tagged_iterator foo]
25+
arguments: [null, !tagged_iterator foo, !service { class: Baz }]
2626
calls:
2727
- [setFoo, ['@bar']]
2828

src/Symfony/Component/DependencyInjection/Tests/Fixtures/config/defaults.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
->tag('t', ['a' => 'b'])
1616
->bind(Foo::class, ref('bar'))
1717
->bind('iterable $foo', tagged_iterator('foo'))
18+
->bind('object $baz', inline('Baz'))
1819
->public();
1920

2021
$s->set(Foo::class)->args([ref('bar')])->public();

0 commit comments

Comments
 (0)
0