Skip to content

Commit 50af6d3

Browse files
Merge branch '4.2'
* 4.2: [Twig] Remove spaces to fix whitespace in tags [Twig] Replace for-loops with blocks for attributes fixed CS [Tests] Change to willThrowException [Console] fix PHPDoc in Command Update FileLoaderLoadException.php Fix wrong calls to clearstatcache Add Vietnamese translation for validators Allow running PHPUnit with "xdebug.scream" ON [VarDumper] Add descriptors tests [Cache] fix bad optim [Yaml] detect circular references [DI] fix reporting bindings on overriden services as unused [Routing] minor fix or previous PR
2 parents 9426384 + b405d16 commit 50af6d3

8 files changed

+74
-22
lines changed

Compiler/ResolveBindingsPass.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ class ResolveBindingsPass extends AbstractRecursivePass
3434
*/
3535
public function process(ContainerBuilder $container)
3636
{
37+
$this->usedBindings = $container->getRemovedBindingIds();
38+
3739
try {
3840
parent::process($container);
3941

ContainerBuilder.php

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
124124

125125
private $removedIds = array();
126126

127+
private $removedBindingIds = array();
128+
127129
private static $internalTypes = array(
128130
'int' => true,
129131
'float' => true,
@@ -500,7 +502,8 @@ public function set($id, $service)
500502
throw new BadMethodCallException(sprintf('Setting service "%s" for an unknown or non-synthetic service definition on a compiled container is not allowed.', $id));
501503
}
502504

503-
unset($this->definitions[$id], $this->aliasDefinitions[$id], $this->removedIds[$id]);
505+
$this->removeId($id);
506+
unset($this->removedIds[$id]);
504507

505508
parent::set($id, $service);
506509
}
@@ -513,8 +516,7 @@ public function set($id, $service)
513516
public function removeDefinition($id)
514517
{
515518
if (isset($this->definitions[$id = (string) $id])) {
516-
unset($this->definitions[$id]);
517-
$this->removedIds[$id] = true;
519+
$this->removeId($id);
518520
}
519521
}
520522

@@ -836,7 +838,8 @@ public function setAlias($alias, $id)
836838
throw new InvalidArgumentException(sprintf('An alias can not reference itself, got a circular reference on "%s".', $alias));
837839
}
838840

839-
unset($this->definitions[$alias], $this->removedIds[$alias]);
841+
$this->removeId($alias);
842+
unset($this->removedIds[$alias]);
840843

841844
return $this->aliasDefinitions[$alias] = $id;
842845
}
@@ -849,8 +852,7 @@ public function setAlias($alias, $id)
849852
public function removeAlias($alias)
850853
{
851854
if (isset($this->aliasDefinitions[$alias = (string) $alias])) {
852-
unset($this->aliasDefinitions[$alias]);
853-
$this->removedIds[$alias] = true;
855+
$this->removeId($alias);
854856
}
855857
}
856858

@@ -979,7 +981,8 @@ public function setDefinition($id, Definition $definition)
979981

980982
$id = (string) $id;
981983

982-
unset($this->aliasDefinitions[$id], $this->removedIds[$id]);
984+
$this->removeId($id);
985+
unset($this->removedIds[$id]);
983986

984987
return $this->definitions[$id] = $definition;
985988
}
@@ -1508,6 +1511,18 @@ public static function getInitializedConditionals($value)
15081511
return $services;
15091512
}
15101513

1514+
/**
1515+
* Gets removed binding ids.
1516+
*
1517+
* @return array
1518+
*
1519+
* @internal
1520+
*/
1521+
public function getRemovedBindingIds()
1522+
{
1523+
return $this->removedBindingIds;
1524+
}
1525+
15111526
/**
15121527
* Computes a reasonably unique hash of a value.
15131528
*
@@ -1616,4 +1631,21 @@ private function inVendors($path)
16161631

16171632
return false;
16181633
}
1634+
1635+
private function removeId($id)
1636+
{
1637+
$this->removedIds[$id] = true;
1638+
unset($this->aliasDefinitions[$id]);
1639+
1640+
if (!isset($this->definitions[$id])) {
1641+
return;
1642+
}
1643+
1644+
foreach ($this->definitions[$id]->getBindings() as $binding) {
1645+
list(, $identifier) = $binding->getValues();
1646+
$this->removedBindingIds[$identifier] = true;
1647+
}
1648+
1649+
unset($this->definitions[$id]);
1650+
}
16191651
}

Tests/Compiler/ResolveBindingsPassTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,24 @@ public function testScalarSetter()
112112
$this->assertEquals(array(array('setDefaultLocale', array('fr'))), $definition->getMethodCalls());
113113
}
114114

115+
public function testOverriddenBindings()
116+
{
117+
$container = new ContainerBuilder();
118+
119+
$binding = new BoundArgument('bar');
120+
121+
$container->register('foo', 'stdClass')
122+
->setBindings(array('$foo' => clone $binding));
123+
$container->register('bar', 'stdClass')
124+
->setBindings(array('$foo' => clone $binding));
125+
126+
$container->register('foo', 'stdClass');
127+
128+
(new ResolveBindingsPass())->process($container);
129+
130+
$this->assertInstanceOf('stdClass', $container->get('foo'));
131+
}
132+
115133
public function testTupleBinding()
116134
{
117135
$container = new ContainerBuilder();

Tests/Compiler/ResolveChildDefinitionsPassTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ protected function process(ContainerBuilder $container)
399399

400400
/**
401401
* @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException
402-
* @expectedExceptionMessageRegExp /^Circular reference detected for service "c", path: "c -> b -> a -> c"./
402+
* @expectedExceptionMessageRegExp /^Circular reference detected for service "a", path: "a -> c -> b -> a"./
403403
*/
404404
public function testProcessDetectsChildDefinitionIndirectCircularReference()
405405
{

Tests/ContainerBuilderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ public function testMerge()
559559
$config->setDefinition('baz', new Definition('BazClass'));
560560
$config->setAlias('alias_for_foo', 'foo');
561561
$container->merge($config);
562-
$this->assertEquals(array('service_container', 'foo', 'bar', 'baz'), array_keys($container->getDefinitions()), '->merge() merges definitions already defined ones');
562+
$this->assertEquals(array('foo', 'bar', 'service_container', 'baz'), array_keys($container->getDefinitions()), '->merge() merges definitions already defined ones');
563563

564564
$aliases = $container->getAliases();
565565
$this->assertArrayHasKey('alias_for_foo', $aliases);

Tests/Fixtures/config/instanceof.expected.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ services:
44
class: Symfony\Component\DependencyInjection\ContainerInterface
55
public: true
66
synthetic: true
7+
foo:
8+
class: App\FooService
9+
public: true
710
Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Foo:
811
class: Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Foo
912
public: true
@@ -16,6 +19,3 @@ services:
1619

1720
shared: false
1821
configurator: c
19-
foo:
20-
class: App\FooService
21-
public: true

Tests/Fixtures/config/prototype.expected.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,22 @@ services:
44
class: Symfony\Component\DependencyInjection\ContainerInterface
55
public: true
66
synthetic: true
7-
Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Foo:
8-
class: Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Foo
7+
Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Sub\Bar:
8+
class: Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Sub\Bar
99
public: true
1010
tags:
1111
- { name: foo }
1212
- { name: baz }
1313
deprecated: '%service_id%'
14+
lazy: true
1415
arguments: [1]
1516
factory: f
16-
Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Sub\Bar:
17-
class: Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Sub\Bar
17+
Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Foo:
18+
class: Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Foo
1819
public: true
1920
tags:
2021
- { name: foo }
2122
- { name: baz }
2223
deprecated: '%service_id%'
23-
lazy: true
2424
arguments: [1]
2525
factory: f

Tests/Fixtures/config/prototype_array.expected.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,22 @@ services:
44
class: Symfony\Component\DependencyInjection\ContainerInterface
55
public: true
66
synthetic: true
7-
Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Foo:
8-
class: Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Foo
7+
Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Sub\Bar:
8+
class: Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Sub\Bar
99
public: true
1010
tags:
1111
- { name: foo }
1212
- { name: baz }
1313
deprecated: '%service_id%'
14+
lazy: true
1415
arguments: [1]
1516
factory: f
16-
Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Sub\Bar:
17-
class: Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Sub\Bar
17+
Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Foo:
18+
class: Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Foo
1819
public: true
1920
tags:
2021
- { name: foo }
2122
- { name: baz }
2223
deprecated: '%service_id%'
23-
lazy: true
2424
arguments: [1]
2525
factory: f

0 commit comments

Comments
 (0)