Revert "bug #29597 [DI] fix reporting bindings on overriden services as unused (nicolas-grekas)"
This reverts commit44e9a91f30
, reversing changes made to91b28ff081
.
This commit is contained in:
parent
a5c52b81f2
commit
b3e17d2101
@ -34,8 +34,6 @@ class ResolveBindingsPass extends AbstractRecursivePass
|
|||||||
*/
|
*/
|
||||||
public function process(ContainerBuilder $container)
|
public function process(ContainerBuilder $container)
|
||||||
{
|
{
|
||||||
$this->usedBindings = $container->getRemovedBindingIds();
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
parent::process($container);
|
parent::process($container);
|
||||||
|
|
||||||
|
@ -123,8 +123,6 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
|
|||||||
|
|
||||||
private $removedIds = array();
|
private $removedIds = array();
|
||||||
|
|
||||||
private $removedBindingIds = array();
|
|
||||||
|
|
||||||
private static $internalTypes = array(
|
private static $internalTypes = array(
|
||||||
'int' => true,
|
'int' => true,
|
||||||
'float' => true,
|
'float' => true,
|
||||||
@ -533,8 +531,7 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
|
|||||||
throw new BadMethodCallException(sprintf('Setting service "%s" for an unknown or non-synthetic service definition on a compiled container is not allowed.', $id));
|
throw new BadMethodCallException(sprintf('Setting service "%s" for an unknown or non-synthetic service definition on a compiled container is not allowed.', $id));
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->removeId($id);
|
unset($this->definitions[$id], $this->aliasDefinitions[$id], $this->removedIds[$id]);
|
||||||
unset($this->removedIds[$id]);
|
|
||||||
|
|
||||||
parent::set($id, $service);
|
parent::set($id, $service);
|
||||||
}
|
}
|
||||||
@ -547,7 +544,8 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
|
|||||||
public function removeDefinition($id)
|
public function removeDefinition($id)
|
||||||
{
|
{
|
||||||
if (isset($this->definitions[$id = $this->normalizeId($id)])) {
|
if (isset($this->definitions[$id = $this->normalizeId($id)])) {
|
||||||
$this->removeId($id);
|
unset($this->definitions[$id]);
|
||||||
|
$this->removedIds[$id] = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -878,8 +876,7 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
|
|||||||
throw new InvalidArgumentException(sprintf('An alias can not reference itself, got a circular reference on "%s".', $alias));
|
throw new InvalidArgumentException(sprintf('An alias can not reference itself, got a circular reference on "%s".', $alias));
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->removeId($alias);
|
unset($this->definitions[$alias], $this->removedIds[$alias]);
|
||||||
unset($this->removedIds[$alias]);
|
|
||||||
|
|
||||||
return $this->aliasDefinitions[$alias] = $id;
|
return $this->aliasDefinitions[$alias] = $id;
|
||||||
}
|
}
|
||||||
@ -892,7 +889,8 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
|
|||||||
public function removeAlias($alias)
|
public function removeAlias($alias)
|
||||||
{
|
{
|
||||||
if (isset($this->aliasDefinitions[$alias = $this->normalizeId($alias)])) {
|
if (isset($this->aliasDefinitions[$alias = $this->normalizeId($alias)])) {
|
||||||
$this->removeId($alias);
|
unset($this->aliasDefinitions[$alias]);
|
||||||
|
$this->removedIds[$alias] = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1021,8 +1019,7 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
|
|||||||
|
|
||||||
$id = $this->normalizeId($id);
|
$id = $this->normalizeId($id);
|
||||||
|
|
||||||
$this->removeId($id);
|
unset($this->aliasDefinitions[$id], $this->removedIds[$id]);
|
||||||
unset($this->removedIds[$id]);
|
|
||||||
|
|
||||||
return $this->definitions[$id] = $definition;
|
return $this->definitions[$id] = $definition;
|
||||||
}
|
}
|
||||||
@ -1555,18 +1552,6 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
|
|||||||
return $services;
|
return $services;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets removed binding ids.
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*
|
|
||||||
* @internal
|
|
||||||
*/
|
|
||||||
public function getRemovedBindingIds()
|
|
||||||
{
|
|
||||||
return $this->removedBindingIds;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Computes a reasonably unique hash of a value.
|
* Computes a reasonably unique hash of a value.
|
||||||
*
|
*
|
||||||
@ -1671,21 +1656,4 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function removeId($id)
|
|
||||||
{
|
|
||||||
$this->removedIds[$id] = true;
|
|
||||||
unset($this->aliasDefinitions[$id]);
|
|
||||||
|
|
||||||
if (!isset($this->definitions[$id])) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($this->definitions[$id]->getBindings() as $binding) {
|
|
||||||
list(, $identifier) = $binding->getValues();
|
|
||||||
$this->removedBindingIds[$identifier] = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
unset($this->definitions[$id]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -111,22 +111,4 @@ class ResolveBindingsPassTest extends TestCase
|
|||||||
|
|
||||||
$this->assertEquals(array(array('setDefaultLocale', array('fr'))), $definition->getMethodCalls());
|
$this->assertEquals(array(array('setDefaultLocale', array('fr'))), $definition->getMethodCalls());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testOverriddenBindings()
|
|
||||||
{
|
|
||||||
$container = new ContainerBuilder();
|
|
||||||
|
|
||||||
$binding = new BoundArgument('bar');
|
|
||||||
|
|
||||||
$container->register('foo', 'stdClass')
|
|
||||||
->setBindings(array('$foo' => clone $binding));
|
|
||||||
$container->register('bar', 'stdClass')
|
|
||||||
->setBindings(array('$foo' => clone $binding));
|
|
||||||
|
|
||||||
$container->register('foo', 'stdClass');
|
|
||||||
|
|
||||||
(new ResolveBindingsPass())->process($container);
|
|
||||||
|
|
||||||
$this->assertInstanceOf('stdClass', $container->get('foo'));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -434,7 +434,7 @@ class ResolveChildDefinitionsPassTest extends TestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException
|
* @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException
|
||||||
* @expectedExceptionMessageRegExp /^Circular reference detected for service "a", path: "a -> c -> b -> a"./
|
* @expectedExceptionMessageRegExp /^Circular reference detected for service "c", path: "c -> b -> a -> c"./
|
||||||
*/
|
*/
|
||||||
public function testProcessDetectsChildDefinitionIndirectCircularReference()
|
public function testProcessDetectsChildDefinitionIndirectCircularReference()
|
||||||
{
|
{
|
||||||
|
@ -559,7 +559,7 @@ class ContainerBuilderTest extends TestCase
|
|||||||
$config->setDefinition('baz', new Definition('BazClass'));
|
$config->setDefinition('baz', new Definition('BazClass'));
|
||||||
$config->setAlias('alias_for_foo', 'foo');
|
$config->setAlias('alias_for_foo', 'foo');
|
||||||
$container->merge($config);
|
$container->merge($config);
|
||||||
$this->assertEquals(array('foo', 'bar', 'service_container', 'baz'), array_keys($container->getDefinitions()), '->merge() merges definitions already defined ones');
|
$this->assertEquals(array('service_container', 'foo', 'bar', 'baz'), array_keys($container->getDefinitions()), '->merge() merges definitions already defined ones');
|
||||||
|
|
||||||
$aliases = $container->getAliases();
|
$aliases = $container->getAliases();
|
||||||
$this->assertArrayHasKey('alias_for_foo', $aliases);
|
$this->assertArrayHasKey('alias_for_foo', $aliases);
|
||||||
|
@ -4,9 +4,6 @@ services:
|
|||||||
class: Symfony\Component\DependencyInjection\ContainerInterface
|
class: Symfony\Component\DependencyInjection\ContainerInterface
|
||||||
public: true
|
public: true
|
||||||
synthetic: true
|
synthetic: true
|
||||||
foo:
|
|
||||||
class: App\FooService
|
|
||||||
public: true
|
|
||||||
Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Foo:
|
Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Foo:
|
||||||
class: Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Foo
|
class: Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Foo
|
||||||
public: true
|
public: true
|
||||||
@ -19,3 +16,6 @@ services:
|
|||||||
|
|
||||||
shared: false
|
shared: false
|
||||||
configurator: c
|
configurator: c
|
||||||
|
foo:
|
||||||
|
class: App\FooService
|
||||||
|
public: true
|
||||||
|
@ -4,6 +4,15 @@ services:
|
|||||||
class: Symfony\Component\DependencyInjection\ContainerInterface
|
class: Symfony\Component\DependencyInjection\ContainerInterface
|
||||||
public: true
|
public: true
|
||||||
synthetic: true
|
synthetic: true
|
||||||
|
Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Foo:
|
||||||
|
class: Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Foo
|
||||||
|
public: true
|
||||||
|
tags:
|
||||||
|
- { name: foo }
|
||||||
|
- { name: baz }
|
||||||
|
deprecated: '%service_id%'
|
||||||
|
arguments: [1]
|
||||||
|
factory: f
|
||||||
Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Sub\Bar:
|
Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Sub\Bar:
|
||||||
class: Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Sub\Bar
|
class: Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Sub\Bar
|
||||||
public: true
|
public: true
|
||||||
@ -14,12 +23,3 @@ services:
|
|||||||
lazy: true
|
lazy: true
|
||||||
arguments: [1]
|
arguments: [1]
|
||||||
factory: f
|
factory: f
|
||||||
Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Foo:
|
|
||||||
class: Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Foo
|
|
||||||
public: true
|
|
||||||
tags:
|
|
||||||
- { name: foo }
|
|
||||||
- { name: baz }
|
|
||||||
deprecated: '%service_id%'
|
|
||||||
arguments: [1]
|
|
||||||
factory: f
|
|
||||||
|
Reference in New Issue
Block a user