Skip to content

[DependencyInjection] remove arbitratry limitation to exclude inline services from bindings #45063

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
Jan 19, 2022
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 @@ -12,10 +12,8 @@
namespace Symfony\Component\DependencyInjection\Loader\Configurator\Traits;

use Symfony\Component\DependencyInjection\Argument\BoundArgument;
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
use Symfony\Component\DependencyInjection\Loader\Configurator\DefaultsConfigurator;
use Symfony\Component\DependencyInjection\Loader\Configurator\InstanceofConfigurator;
use Symfony\Component\DependencyInjection\Reference;

trait BindTrait
{
Expand All @@ -34,9 +32,6 @@ trait BindTrait
final public function bind(string $nameOrFqcn, $valueOrRef): self
{
$valueOrRef = static::processValue($valueOrRef, true);
if (!preg_match('/^(?:(?:array|bool|float|int|string|iterable)[ \t]*+)?\$/', $nameOrFqcn) && !$valueOrRef instanceof Reference) {
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));
}
$bindings = $this->definition->getBindings();
$type = $this instanceof DefaultsConfigurator ? BoundArgument::DEFAULTS_BINDING : ($this instanceof InstanceofConfigurator ? BoundArgument::INSTANCEOF_BINDING : BoundArgument::SERVICE_BINDING);
$bindings[$nameOrFqcn] = new BoundArgument($valueOrRef, true, $type, $this->path ?? null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class Foo implements FooInterface, Sub\BarInterface
{
public function __construct($bar = null, iterable $foo = null)
public function __construct($bar = null, iterable $foo = null, object $baz = null)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ services:
- { name: t, a: b }
autowire: true
autoconfigure: true
arguments: ['@bar', !tagged_iterator foo]
arguments: ['@bar', !tagged_iterator foo, !service { class: Baz }]
bar:
class: Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Foo
public: true
tags:
- { name: t, a: b }
autowire: true
arguments: [null, !tagged_iterator foo]
arguments: [null, !tagged_iterator foo, !service { class: Baz }]
calls:
- [setFoo, ['@bar']]

Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
->tag('t', ['a' => 'b'])
->bind(Foo::class, ref('bar'))
->bind('iterable $foo', tagged_iterator('foo'))
->bind('object $baz', inline('Baz'))
->public();

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