Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5405676

Browse filesBrowse files
[DI] fix reporting bindings on overriden services as unused
1 parent 68b823f commit 5405676
Copy full SHA for 5405676

File tree

Expand file treeCollapse file tree

6 files changed

+53
-17
lines changed
Filter options
Expand file treeCollapse file tree

6 files changed

+53
-17
lines changed

‎src/Symfony/Component/DependencyInjection/ContainerBuilder.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/ContainerBuilder.php
+25-7Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,8 @@ public function set($id, $service)
531531
throw new BadMethodCallException(sprintf('Setting service "%s" for an unknown or non-synthetic service definition on a compiled container is not allowed.', $id));
532532
}
533533

534-
unset($this->definitions[$id], $this->aliasDefinitions[$id], $this->removedIds[$id]);
534+
$this->removeId($id);
535+
unset($this->removedIds[$id]);
535536

536537
parent::set($id, $service);
537538
}
@@ -544,8 +545,7 @@ public function set($id, $service)
544545
public function removeDefinition($id)
545546
{
546547
if (isset($this->definitions[$id = $this->normalizeId($id)])) {
547-
unset($this->definitions[$id]);
548-
$this->removedIds[$id] = true;
548+
$this->removeId($id);
549549
}
550550
}
551551

@@ -876,7 +876,8 @@ public function setAlias($alias, $id)
876876
throw new InvalidArgumentException(sprintf('An alias can not reference itself, got a circular reference on "%s".', $alias));
877877
}
878878

879-
unset($this->definitions[$alias], $this->removedIds[$alias]);
879+
$this->removeId($alias);
880+
unset($this->removedIds[$alias]);
880881

881882
return $this->aliasDefinitions[$alias] = $id;
882883
}
@@ -889,8 +890,7 @@ public function setAlias($alias, $id)
889890
public function removeAlias($alias)
890891
{
891892
if (isset($this->aliasDefinitions[$alias = $this->normalizeId($alias)])) {
892-
unset($this->aliasDefinitions[$alias]);
893-
$this->removedIds[$alias] = true;
893+
$this->removeId($alias);
894894
}
895895
}
896896

@@ -1019,7 +1019,8 @@ public function setDefinition($id, Definition $definition)
10191019

10201020
$id = $this->normalizeId($id);
10211021

1022-
unset($this->aliasDefinitions[$id], $this->removedIds[$id]);
1022+
$this->removeId($id);
1023+
unset($this->removedIds[$id]);
10231024

10241025
return $this->definitions[$id] = $definition;
10251026
}
@@ -1656,4 +1657,21 @@ private function inVendors($path)
16561657

16571658
return false;
16581659
}
1660+
1661+
private function removeId($id)
1662+
{
1663+
$this->removedIds[$id] = true;
1664+
unset($this->aliasDefinitions[$id]);
1665+
1666+
if (!isset($this->definitions[$id])) {
1667+
return;
1668+
}
1669+
1670+
foreach ($this->definitions[$id]->getBindings() as $binding) {
1671+
list($value, $identifier) = $binding->getValues();
1672+
$binding->setValues(array($value, $identifier, true));
1673+
}
1674+
1675+
unset($this->definitions[$id]);
1676+
}
16591677
}

‎src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveBindingsPassTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveBindingsPassTest.php
+18Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,22 @@ public function testScalarSetter()
111111

112112
$this->assertEquals(array(array('setDefaultLocale', array('fr'))), $definition->getMethodCalls());
113113
}
114+
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' => $binding));
123+
$container->register('bar', 'stdClass')
124+
->setBindings(array('$foo' => $binding));
125+
126+
$container->register('foo', 'stdClass');
127+
128+
(new ResolveBindingsPass())->process($container);
129+
130+
$this->assertInstanceOf('stdClass', $container->get('foo'));
131+
}
114132
}

‎src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveChildDefinitionsPassTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveChildDefinitionsPassTest.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ protected function process(ContainerBuilder $container)
434434

435435
/**
436436
* @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException
437-
* @expectedExceptionMessageRegExp /^Circular reference detected for service "c", path: "c -> b -> a -> c"./
437+
* @expectedExceptionMessageRegExp /^Circular reference detected for service "a", path: "a -> c -> b -> a"./
438438
*/
439439
public function testProcessDetectsChildDefinitionIndirectCircularReference()
440440
{

‎src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php
+1-1Lines 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);

‎src/Symfony/Component/DependencyInjection/Tests/Fixtures/config/instanceof.expected.yml

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Tests/Fixtures/config/instanceof.expected.yml
+3-3Lines 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

‎src/Symfony/Component/DependencyInjection/Tests/Fixtures/config/prototype.expected.yml

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Tests/Fixtures/config/prototype.expected.yml
+5-5Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.