Skip to content

Commit ea68e28

Browse files
committed
bug #29853 Revert "bug #29597 [DI] fix reporting bindings on overriden services as unused" (mmarynich)
This PR was merged into the 3.4 branch. Discussion ---------- Revert "bug #29597 [DI] fix reporting bindings on overriden services as unused" This reverts commit 44e9a91, reversing changes made to 91b28ff. | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #29836 | License | MIT | Doc PR | 4.2.2 release changed the way tagged service are injected As asked by @nicolas-grekas #29836 (comment) Commits ------- b3e17d2 Revert "bug #29597 [DI] fix reporting bindings on overriden services as unused (nicolas-grekas)"
2 parents 6573cd3 + b3e17d2 commit ea68e28

File tree

7 files changed

+17
-69
lines changed

7 files changed

+17
-69
lines changed

src/Symfony/Component/DependencyInjection/Compiler/ResolveBindingsPass.php

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

src/Symfony/Component/DependencyInjection/ContainerBuilder.php

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

124124
private $removedIds = array();
125125

126-
private $removedBindingIds = array();
127-
128126
private static $internalTypes = array(
129127
'int' => true,
130128
'float' => true,
@@ -533,8 +531,7 @@ public function set($id, $service)
533531
throw new BadMethodCallException(sprintf('Setting service "%s" for an unknown or non-synthetic service definition on a compiled container is not allowed.', $id));
534532
}
535533

536-
$this->removeId($id);
537-
unset($this->removedIds[$id]);
534+
unset($this->definitions[$id], $this->aliasDefinitions[$id], $this->removedIds[$id]);
538535

539536
parent::set($id, $service);
540537
}
@@ -547,7 +544,8 @@ public function set($id, $service)
547544
public function removeDefinition($id)
548545
{
549546
if (isset($this->definitions[$id = $this->normalizeId($id)])) {
550-
$this->removeId($id);
547+
unset($this->definitions[$id]);
548+
$this->removedIds[$id] = true;
551549
}
552550
}
553551

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

881-
$this->removeId($alias);
882-
unset($this->removedIds[$alias]);
879+
unset($this->definitions[$alias], $this->removedIds[$alias]);
883880

884881
return $this->aliasDefinitions[$alias] = $id;
885882
}
@@ -892,7 +889,8 @@ public function setAlias($alias, $id)
892889
public function removeAlias($alias)
893890
{
894891
if (isset($this->aliasDefinitions[$alias = $this->normalizeId($alias)])) {
895-
$this->removeId($alias);
892+
unset($this->aliasDefinitions[$alias]);
893+
$this->removedIds[$alias] = true;
896894
}
897895
}
898896

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

10221020
$id = $this->normalizeId($id);
10231021

1024-
$this->removeId($id);
1025-
unset($this->removedIds[$id]);
1022+
unset($this->aliasDefinitions[$id], $this->removedIds[$id]);
10261023

10271024
return $this->definitions[$id] = $definition;
10281025
}
@@ -1555,18 +1552,6 @@ public static function getInitializedConditionals($value)
15551552
return $services;
15561553
}
15571554

1558-
/**
1559-
* Gets removed binding ids.
1560-
*
1561-
* @return array
1562-
*
1563-
* @internal
1564-
*/
1565-
public function getRemovedBindingIds()
1566-
{
1567-
return $this->removedBindingIds;
1568-
}
1569-
15701555
/**
15711556
* Computes a reasonably unique hash of a value.
15721557
*
@@ -1671,21 +1656,4 @@ private function inVendors($path)
16711656

16721657
return false;
16731658
}
1674-
1675-
private function removeId($id)
1676-
{
1677-
$this->removedIds[$id] = true;
1678-
unset($this->aliasDefinitions[$id]);
1679-
1680-
if (!isset($this->definitions[$id])) {
1681-
return;
1682-
}
1683-
1684-
foreach ($this->definitions[$id]->getBindings() as $binding) {
1685-
list(, $identifier) = $binding->getValues();
1686-
$this->removedBindingIds[$identifier] = true;
1687-
}
1688-
1689-
unset($this->definitions[$id]);
1690-
}
16911659
}

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

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -111,22 +111,4 @@ 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' => 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-
}
132114
}

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

Lines 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 "a", path: "a -> c -> b -> a"./
437+
* @expectedExceptionMessageRegExp /^Circular reference detected for service "c", path: "c -> b -> a -> c"./
438438
*/
439439
public function testProcessDetectsChildDefinitionIndirectCircularReference()
440440
{

src/Symfony/Component/DependencyInjection/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('foo', 'bar', 'service_container', 'baz'), array_keys($container->getDefinitions()), '->merge() merges definitions already defined ones');
562+
$this->assertEquals(array('service_container', 'foo', 'bar', '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

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

2017
shared: false
2118
configurator: c
19+
foo:
20+
class: App\FooService
21+
public: true

src/Symfony/Component/DependencyInjection/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\Sub\Bar:
8-
class: Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Sub\Bar
7+
Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Foo:
8+
class: Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Foo
99
public: true
1010
tags:
1111
- { name: foo }
1212
- { name: baz }
1313
deprecated: '%service_id%'
14-
lazy: true
1514
arguments: [1]
1615
factory: f
17-
Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Foo:
18-
class: Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Foo
16+
Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Sub\Bar:
17+
class: Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Sub\Bar
1918
public: true
2019
tags:
2120
- { name: foo }
2221
- { name: baz }
2322
deprecated: '%service_id%'
23+
lazy: true
2424
arguments: [1]
2525
factory: f

0 commit comments

Comments
 (0)