Skip to content

Commit

Permalink
Merge branch '4.4' into 5.3
Browse files Browse the repository at this point in the history
* 4.4:
  Throw exception if incompatible version of psr/simple-cache is used
  [DependencyInjection] copy synthetic status when resolving child definitions
  [HttpClient] Fix Failed to open stream: Too many open files
  [Console] use STDOUT/ERR in ConsoleOutput to save opening too many file descriptors
  [Cache] Set mtime of cache files 1 year into future if they do not expire
  [DependencyInjection] remove arbitratry limitation to exclude inline services from bindings
  • Loading branch information
fabpot committed Jan 22, 2022
2 parents 8fb0f58 + bc261bb commit 2afd8c0
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 8 deletions.
2 changes: 2 additions & 0 deletions Compiler/ResolveChildDefinitionsPass.php
Expand Up @@ -115,6 +115,8 @@ private function doResolveDefinition(ChildDefinition $definition): Definition

$def->setBindings($definition->getBindings() + $parentDef->getBindings());

$def->setSynthetic($definition->isSynthetic());

// overwrite with values specified in the decorator
$changes = $definition->getChanges();
if (isset($changes['class'])) {
Expand Down
5 changes: 0 additions & 5 deletions Loader/Configurator/Traits/BindTrait.php
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
17 changes: 17 additions & 0 deletions Tests/Compiler/ResolveChildDefinitionsPassTest.php
Expand Up @@ -421,4 +421,21 @@ public function testProcessDetectsChildDefinitionIndirectCircularReference()

$this->process($container);
}

public function testProcessCopiesSyntheticStatus()
{
$container = new ContainerBuilder();

$container->register('parent');

$container
->setDefinition('child', new ChildDefinition('parent'))
->setSynthetic(true)
;

$this->process($container);

$def = $container->getDefinition('child');
$this->assertTrue($def->isSynthetic());
}
}
2 changes: 1 addition & 1 deletion Tests/Fixtures/Prototype/Foo.php
Expand Up @@ -8,7 +8,7 @@
#[When(env: 'dev')]
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
4 changes: 2 additions & 2 deletions Tests/Fixtures/config/defaults.expected.yml
Expand Up @@ -15,14 +15,14 @@ services:
- 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:
- t: { a: b }
autowire: true
arguments: [null, !tagged_iterator foo]
arguments: [null, !tagged_iterator foo, !service { class: Baz }]
calls:
- [setFoo, ['@bar']]

1 change: 1 addition & 0 deletions Tests/Fixtures/config/defaults.php
Expand Up @@ -15,6 +15,7 @@
->tag('t', ['a' => 'b'])
->bind(Foo::class, service('bar'))
->bind('iterable $foo', tagged_iterator('foo'))
->bind('object $baz', inline('Baz'))
->public();

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

0 comments on commit 2afd8c0

Please sign in to comment.