feature #24484 [DI] Throw accurate failures when accessing removed services (nicolas-grekas)

This PR was merged into the 3.4 branch.

Discussion
----------

[DI] Throw accurate failures when accessing removed services

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #24444
| License       | MIT
| Doc PR        | -

See linked issue.
This will throw a useful message when accessing a removed service.
When setting a removed service, a deprecation notice will be thrown also so that in master we can throw an exception then.

Commits
-------

fe7f26d4f3 [DI] Throw accurate failures when accessing removed services
This commit is contained in:
Fabien Potencier 2017-10-09 21:07:35 -07:00
commit d48bcbfcf6
33 changed files with 377 additions and 77 deletions

View File

@ -50,6 +50,7 @@ class Container implements ResettableContainerInterface
protected $aliases = array();
protected $loading = array();
protected $resolving = array();
protected $syntheticIds = array();
/**
* @internal
@ -179,31 +180,34 @@ class Container implements ResettableContainerInterface
throw new InvalidArgumentException('You cannot set service "service_container".');
}
if (isset($this->aliases[$id])) {
unset($this->aliases[$id]);
}
$wasSet = isset($this->services[$id]);
$this->services[$id] = $service;
if (null === $service) {
unset($this->services[$id]);
}
if (isset($this->privates[$id])) {
if (null === $service) {
if (isset($this->privates[$id]) || !(isset($this->fileMap[$id]) || isset($this->methodMap[$id]))) {
if (isset($this->syntheticIds[$id]) || (!isset($this->privates[$id]) && !isset($this->getRemovedIds()[$id]))) {
// no-op
} elseif (null === $service) {
@trigger_error(sprintf('The "%s" service is private, unsetting it is deprecated since Symfony 3.2 and will fail in 4.0.', $id), E_USER_DEPRECATED);
unset($this->privates[$id]);
} else {
@trigger_error(sprintf('The "%s" service is private, replacing it is deprecated since Symfony 3.2 and will fail in 4.0.', $id), E_USER_DEPRECATED);
}
} elseif ($wasSet && (isset($this->fileMap[$id]) || isset($this->methodMap[$id]))) {
} elseif (isset($this->services[$id])) {
if (null === $service) {
@trigger_error(sprintf('The "%s" service is already initialized, unsetting it is deprecated since Symfony 3.3 and will fail in 4.0.', $id), E_USER_DEPRECATED);
} else {
@trigger_error(sprintf('The "%s" service is already initialized, replacing it is deprecated since Symfony 3.3 and will fail in 4.0.', $id), E_USER_DEPRECATED);
}
}
if (isset($this->aliases[$id])) {
unset($this->aliases[$id]);
}
if (null === $service) {
unset($this->services[$id]);
return;
}
$this->services[$id] = $service;
}
/**
@ -275,7 +279,7 @@ class Container implements ResettableContainerInterface
// calling $this->normalizeId($id) unless necessary.
for ($i = 2;;) {
if (isset($this->privates[$id])) {
@trigger_error(sprintf('The "%s" service is private, getting it from the container is deprecated since Symfony 3.2 and will fail in 4.0. You should either make the service public, or stop getting services directly from the container and use dependency injection instead.', $id), E_USER_DEPRECATED);
@trigger_error(sprintf('The "%s" service is private, getting it from the container is deprecated since Symfony 3.2 and will fail in 4.0. You should either make the service public, or stop using the container directly and use dependency injection instead.', $id), E_USER_DEPRECATED);
}
if (isset($this->aliases[$id])) {
$id = $this->aliases[$id];
@ -325,6 +329,12 @@ class Container implements ResettableContainerInterface
if (!$id) {
throw new ServiceNotFoundException($id);
}
if (isset($this->syntheticIds[$id])) {
throw new ServiceNotFoundException($id, null, null, array(), sprintf('The "%s" service is synthetic, it needs to be set at boot time before it can be used.', $id));
}
if (isset($this->getRemovedIds()[$id])) {
throw new ServiceNotFoundException($id, null, null, array(), sprintf('The "%s" service or alias has been removed or inlined when the container was compiled. You should either make it public, or stop using the container directly and use dependency injection instead.', $id));
}
$alternatives = array();
foreach ($this->getServiceIds() as $knownId) {
@ -397,6 +407,16 @@ class Container implements ResettableContainerInterface
return array_unique(array_merge($ids, array_keys($this->methodMap), array_keys($this->fileMap), array_keys($this->services)));
}
/**
* Gets service ids that existed at compile time.
*
* @return array
*/
public function getRemovedIds()
{
return array();
}
/**
* Camelizes a string.
*

View File

@ -121,6 +121,8 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
private $autoconfiguredInstanceof = array();
private $removedIds = array();
public function __construct(ParameterBagInterface $parameterBag = null)
{
parent::__construct($parameterBag);
@ -517,7 +519,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));
}
unset($this->definitions[$id], $this->aliasDefinitions[$id]);
unset($this->definitions[$id], $this->aliasDefinitions[$id], $this->removedIds[$id]);
parent::set($id, $service);
}
@ -529,7 +531,10 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
*/
public function removeDefinition($id)
{
unset($this->definitions[$this->normalizeId($id)]);
if (isset($this->definitions[$id = $this->normalizeId($id)])) {
unset($this->definitions[$id]);
$this->removedIds[$id] = true;
}
}
/**
@ -793,6 +798,16 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
return array_unique(array_merge(array_keys($this->getDefinitions()), array_keys($this->aliasDefinitions), parent::getServiceIds()));
}
/**
* Gets removed service or alias ids.
*
* @return array
*/
public function getRemovedIds()
{
return $this->removedIds;
}
/**
* Adds the service aliases.
*
@ -841,7 +856,7 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
throw new InvalidArgumentException(sprintf('An alias can not reference itself, got a circular reference on "%s".', $alias));
}
unset($this->definitions[$alias]);
unset($this->definitions[$alias], $this->removedIds[$alias]);
return $this->aliasDefinitions[$alias] = $id;
}
@ -853,7 +868,10 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
*/
public function removeAlias($alias)
{
unset($this->aliasDefinitions[$this->normalizeId($alias)]);
if (isset($this->aliasDefinitions[$alias = $this->normalizeId($alias)])) {
unset($this->aliasDefinitions[$alias]);
$this->removedIds[$alias] = true;
}
}
/**
@ -981,7 +999,7 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
$id = $this->normalizeId($id);
unset($this->aliasDefinitions[$id]);
unset($this->aliasDefinitions[$id], $this->removedIds[$id]);
return $this->definitions[$id] = $definition;
}

View File

@ -172,6 +172,16 @@ use Symfony\Component\DependencyInjection\Argument\RewindableGenerator;
EOF;
$files = array();
if ($ids = array_keys($this->container->getRemovedIds())) {
sort($ids);
$c = "<?php\n\nreturn array(\n";
foreach ($ids as $id) {
$c .= ' '.$this->export($id)." => true,\n";
}
$files['removed-ids.php'] = $c .= ");\n";
}
foreach ($this->generateServiceFiles() as $file => $c) {
$files[$file] = $fileStart.$c;
}
@ -888,6 +898,7 @@ EOF;
}
$code .= $this->addNormalizedIds();
$code .= $this->addSyntheticIds();
$code .= $this->addMethodMap();
$code .= $this->asFiles ? $this->addFileMap() : '';
$code .= $this->addPrivateServices();
@ -896,6 +907,8 @@ EOF;
}
EOF;
$code .= $this->addRemovedIds();
if ($this->container->isCompiled()) {
$code .= <<<EOF
@ -978,6 +991,58 @@ EOF;
return $code ? " \$this->normalizedIds = array(\n".$code." );\n" : '';
}
/**
* Adds the syntheticIds definition.
*
* @return string
*/
private function addSyntheticIds()
{
$code = '';
$definitions = $this->container->getDefinitions();
ksort($definitions);
foreach ($definitions as $id => $definition) {
if ($definition->isSynthetic() && 'service_container' !== $id) {
$code .= ' '.$this->export($id)." => true,\n";
}
}
return $code ? " \$this->syntheticIds = array(\n{$code} );\n" : '';
}
/**
* Adds the removedIds definition.
*
* @return string
*/
private function addRemovedIds()
{
if (!$ids = $this->container->getRemovedIds()) {
return '';
}
if ($this->asFiles) {
$code = "require __DIR__.'/removed-ids.php'";
} else {
$code = '';
$ids = array_keys($ids);
sort($ids);
foreach ($ids as $id) {
$code .= ' '.$this->export($id)." => true,\n";
}
$code = "array(\n{$code} )";
}
return <<<EOF
public function getRemovedIds()
{
return {$code};
}
EOF;
}
/**
* Adds the methodMap property definition.
*

View File

@ -24,9 +24,11 @@ class ServiceNotFoundException extends InvalidArgumentException implements NotFo
private $sourceId;
private $alternatives;
public function __construct($id, $sourceId = null, \Exception $previous = null, array $alternatives = array())
public function __construct($id, $sourceId = null, \Exception $previous = null, array $alternatives = array(), $msg = null)
{
if (null === $sourceId) {
if (null !== $msg) {
// no-op
} elseif (null === $sourceId) {
$msg = sprintf('You have requested a non-existent service "%s".', $id);
} else {
$msg = sprintf('The service "%s" has a dependency on a non-existent service "%s".', $sourceId, $id);

View File

@ -333,16 +333,28 @@ class ContainerTest extends TestCase
/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException
* @expectedExceptionMessage You have requested a non-existent service "request".
* @expectedExceptionMessage The "request" service is synthetic, it needs to be set at boot time before it can be used.
*/
public function testGetSyntheticServiceThrows()
{
require_once __DIR__.'/Fixtures/php/services9.php';
require_once __DIR__.'/Fixtures/php/services9_compiled.php';
$container = new \ProjectServiceContainer();
$container->get('request');
}
/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException
* @expectedExceptionMessage The "inlined" service or alias has been removed or inlined when the container was compiled. You should either make it public, or stop using the container directly and use dependency injection instead.
*/
public function testGetRemovedServiceThrows()
{
require_once __DIR__.'/Fixtures/php/services9_compiled.php';
$container = new \ProjectServiceContainer();
$container->get('inlined');
}
public function testHas()
{
$sc = new ProjectServiceContainer();
@ -505,7 +517,7 @@ class ContainerTest extends TestCase
/**
* @group legacy
* @expectedDeprecation The "internal" service is private, getting it from the container is deprecated since Symfony 3.2 and will fail in 4.0. You should either make the service public, or stop getting services directly from the container and use dependency injection instead.
* @expectedDeprecation The "internal" service is private, getting it from the container is deprecated since Symfony 3.2 and will fail in 4.0. You should either make the service public, or stop using the container directly and use dependency injection instead.
*/
public function testRequestAnInternalSharedPrivateServiceIsDeprecated()
{

View File

@ -287,37 +287,17 @@ class PhpDumperTest extends TestCase
/**
* @group legacy
* @expectedDeprecation The "bar" service is already initialized, replacing it is deprecated since Symfony 3.3 and will fail in 4.0.
* @expectedDeprecation The "decorator_service" service is already initialized, replacing it is deprecated since Symfony 3.3 and will fail in 4.0.
*/
public function testOverrideServiceWhenUsingADumpedContainer()
{
require_once self::$fixturesPath.'/php/services9.php';
require_once self::$fixturesPath.'/includes/foo.php';
require_once self::$fixturesPath.'/php/services9_compiled.php';
$container = new \ProjectServiceContainer();
$container->setParameter('foo_bar', 'foo_bar');
$container->get('bar');
$container->set('bar', $bar = new \stdClass());
$container->get('decorator_service');
$container->set('decorator_service', $decorator = new \stdClass());
$this->assertSame($bar, $container->get('bar'), '->set() overrides an already defined service');
}
/**
* @group legacy
* @expectedDeprecation The "bar" service is already initialized, replacing it is deprecated since Symfony 3.3 and will fail in 4.0.
*/
public function testOverrideServiceWhenUsingADumpedContainerAndServiceIsUsedFromAnotherOne()
{
require_once self::$fixturesPath.'/php/services9.php';
require_once self::$fixturesPath.'/includes/foo.php';
require_once self::$fixturesPath.'/includes/classes.php';
$container = new \ProjectServiceContainer();
$container->setParameter('foo_bar', 'foo_bar');
$container->get('bar');
$container->set('bar', $bar = new \stdClass());
$this->assertSame($bar, $container->get('foo')->bar, '->set() overrides an already defined service');
$this->assertSame($decorator, $container->get('decorator_service'), '->set() overrides an already defined service');
}
/**
@ -799,14 +779,14 @@ class PhpDumperTest extends TestCase
/**
* @group legacy
* @expectedDeprecation The "private" service is private, getting it from the container is deprecated since Symfony 3.2 and will fail in 4.0. You should either make the service public, or stop getting services directly from the container and use dependency injection instead.
* @expectedDeprecation The "private_alias" service is private, getting it from the container is deprecated since Symfony 3.2 and will fail in 4.0. You should either make the service public, or stop getting services directly from the container and use dependency injection instead.
* @expectedDeprecation The "decorated_private" service is private, getting it from the container is deprecated since Symfony 3.2 and will fail in 4.0. You should either make the service public, or stop getting services directly from the container and use dependency injection instead.
* @expectedDeprecation The "decorated_private_alias" service is private, getting it from the container is deprecated since Symfony 3.2 and will fail in 4.0. You should either make the service public, or stop getting services directly from the container and use dependency injection instead.
* @expectedDeprecation The "private_not_inlined" service is private, getting it from the container is deprecated since Symfony 3.2 and will fail in 4.0. You should either make the service public, or stop getting services directly from the container and use dependency injection instead.
* @expectedDeprecation The "private_not_removed" service is private, getting it from the container is deprecated since Symfony 3.2 and will fail in 4.0. You should either make the service public, or stop getting services directly from the container and use dependency injection instead.
* @expectedDeprecation The "private_child" service is private, getting it from the container is deprecated since Symfony 3.2 and will fail in 4.0. You should either make the service public, or stop getting services directly from the container and use dependency injection instead.
* @expectedDeprecation The "private_parent" service is private, getting it from the container is deprecated since Symfony 3.2 and will fail in 4.0. You should either make the service public, or stop getting services directly from the container and use dependency injection instead.
* @expectedDeprecation The "private" service is private, getting it from the container is deprecated since Symfony 3.2 and will fail in 4.0. You should either make the service public, or stop using the container directly and use dependency injection instead.
* @expectedDeprecation The "private_alias" service is private, getting it from the container is deprecated since Symfony 3.2 and will fail in 4.0. You should either make the service public, or stop using the container directly and use dependency injection instead.
* @expectedDeprecation The "decorated_private" service is private, getting it from the container is deprecated since Symfony 3.2 and will fail in 4.0. You should either make the service public, or stop using the container directly and use dependency injection instead.
* @expectedDeprecation The "decorated_private_alias" service is private, getting it from the container is deprecated since Symfony 3.2 and will fail in 4.0. You should either make the service public, or stop using the container directly and use dependency injection instead.
* @expectedDeprecation The "private_not_inlined" service is private, getting it from the container is deprecated since Symfony 3.2 and will fail in 4.0. You should either make the service public, or stop using the container directly and use dependency injection instead.
* @expectedDeprecation The "private_not_removed" service is private, getting it from the container is deprecated since Symfony 3.2 and will fail in 4.0. You should either make the service public, or stop using the container directly and use dependency injection instead.
* @expectedDeprecation The "private_child" service is private, getting it from the container is deprecated since Symfony 3.2 and will fail in 4.0. You should either make the service public, or stop using the container directly and use dependency injection instead.
* @expectedDeprecation The "private_parent" service is private, getting it from the container is deprecated since Symfony 3.2 and will fail in 4.0. You should either make the service public, or stop using the container directly and use dependency injection instead.
*/
public function testLegacyPrivateServices()
{

View File

@ -40,9 +40,6 @@ return function (ContainerConfigurator $c) {
->args(array(ref('deprecated_service')))
->share(false);
$s->alias('alias_for_foo', 'foo')->private()->public();
$s->alias('alias_for_alias', ref('alias_for_foo'));
$s->set('method_call1', 'Bar\FooClass')
->file(realpath(__DIR__.'/../includes/foo.php'))
->call('setBar', array(ref('foo')))
@ -125,4 +122,7 @@ return function (ContainerConfigurator $c) {
$s->set('tagged_iterator', 'Bar')
->public()
->args(array(tagged('foo')));
$s->alias('alias_for_foo', 'foo')->private()->public();
$s->alias('alias_for_alias', ref('alias_for_foo'));
};

View File

@ -48,8 +48,6 @@ $container->getParameterBag()->add(array(
'foo_class' => 'Bar\FooClass',
'foo' => 'bar',
));
$container->setAlias('alias_for_foo', 'foo')->setPublic(true);
$container->setAlias('alias_for_alias', 'alias_for_foo')->setPublic(true);
$container
->register('method_call1', 'Bar\FooClass')
->setFile(realpath(__DIR__.'/../includes/foo.php'))
@ -172,5 +170,7 @@ $container
->addArgument(new TaggedIteratorArgument('foo'))
->setPublic(true)
;
$container->setAlias('alias_for_foo', 'foo')->setPublic(true);
$container->setAlias('alias_for_alias', 'alias_for_foo')->setPublic(true);
return $container;

View File

@ -28,6 +28,14 @@ class Container extends AbstractContainer
$this->aliases = array();
}
public function getRemovedIds()
{
return array(
'Psr\\Container\\ContainerInterface' => true,
'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true,
);
}
public function compile()
{
throw new LogicException('You cannot compile a dumped container that was already compiled.');

View File

@ -26,6 +26,14 @@ class ProjectServiceContainer extends Container
$this->aliases = array();
}
public function getRemovedIds()
{
return array(
'Psr\\Container\\ContainerInterface' => true,
'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true,
);
}
public function compile()
{
throw new LogicException('You cannot compile a dumped container that was already compiled.');

View File

@ -31,6 +31,14 @@ class ProjectServiceContainer extends Container
$this->aliases = array();
}
public function getRemovedIds()
{
return array(
'Psr\\Container\\ContainerInterface' => true,
'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true,
);
}
public function compile()
{
throw new LogicException('You cannot compile a dumped container that was already compiled.');

View File

@ -35,6 +35,14 @@ class ProjectServiceContainer extends Container
$this->aliases = array();
}
public function getRemovedIds()
{
return array(
'Psr\\Container\\ContainerInterface' => true,
'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true,
);
}
public function compile()
{
throw new LogicException('You cannot compile a dumped container that was already compiled.');

View File

@ -29,6 +29,15 @@ class ProjectServiceContainer extends Container
$this->aliases = array();
}
public function getRemovedIds()
{
return array(
'Psr\\Container\\ContainerInterface' => true,
'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true,
'foo' => true,
);
}
public function compile()
{
throw new LogicException('You cannot compile a dumped container that was already compiled.');

View File

@ -30,6 +30,14 @@ class ProjectServiceContainer extends Container
$this->aliases = array();
}
public function getRemovedIds()
{
return array(
'Psr\\Container\\ContainerInterface' => true,
'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true,
);
}
public function compile()
{
throw new LogicException('You cannot compile a dumped container that was already compiled.');

View File

@ -29,6 +29,14 @@ class ProjectServiceContainer extends Container
$this->aliases = array();
}
public function getRemovedIds()
{
return array(
'Psr\\Container\\ContainerInterface' => true,
'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true,
);
}
public function compile()
{
throw new LogicException('You cannot compile a dumped container that was already compiled.');

View File

@ -35,6 +35,14 @@ class Symfony_DI_PhpDumper_Test_EnvParameters extends Container
$this->aliases = array();
}
public function getRemovedIds()
{
return array(
'Psr\\Container\\ContainerInterface' => true,
'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true,
);
}
public function compile()
{
throw new LogicException('You cannot compile a dumped container that was already compiled.');

View File

@ -34,6 +34,14 @@ class ProjectServiceContainer extends Container
$this->aliases = array();
}
public function getRemovedIds()
{
return array(
'Psr\\Container\\ContainerInterface' => true,
'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true,
);
}
public function compile()
{
throw new LogicException('You cannot compile a dumped container that was already compiled.');

View File

@ -28,6 +28,14 @@ class ProjectServiceContainer extends Container
$this->aliases = array();
}
public function getRemovedIds()
{
return array(
'Psr\\Container\\ContainerInterface' => true,
'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true,
);
}
public function compile()
{
throw new LogicException('You cannot compile a dumped container that was already compiled.');

View File

@ -26,6 +26,9 @@ class ProjectServiceContainer extends Container
'psr\\container\\containerinterface' => 'Psr\\Container\\ContainerInterface',
'symfony\\component\\dependencyinjection\\containerinterface' => 'Symfony\\Component\\DependencyInjection\\ContainerInterface',
);
$this->syntheticIds = array(
'request' => true,
);
$this->methodMap = array(
'bar' => 'getBarService',
'baz' => 'getBazService',

View File

@ -1,5 +1,18 @@
Array
(
[Container%s/removed-ids.php] => <?php
return array(
'Psr\\Container\\ContainerInterface' => true,
'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true,
'configurator_service' => true,
'configurator_service_simple' => true,
'decorated.pif-pouf' => true,
'decorator_service.inner' => true,
'inlined' => true,
'new_factory' => true,
);
[Container%s/getBarService.php] => <?php
use Symfony\Component\DependencyInjection\Argument\RewindableGenerator;
@ -286,6 +299,9 @@ class Container%s extends Container
$this->parameters = $this->getDefaultParameters();
$this->services = array();
$this->syntheticIds = array(
'request' => true,
);
$this->methodMap = array(
'foo_bar' => 'getFooBarService',
);
@ -322,6 +338,11 @@ class Container%s extends Container
);
}
public function getRemovedIds()
{
return require __DIR__.'/removed-ids.php';
}
public function compile()
{
throw new LogicException('You cannot compile a dumped container that was already compiled.');

View File

@ -24,6 +24,9 @@ class ProjectServiceContainer extends Container
$this->parameters = $this->getDefaultParameters();
$this->services = array();
$this->syntheticIds = array(
'request' => true,
);
$this->methodMap = array(
'bar' => 'getBarService',
'baz' => 'getBazService',
@ -58,6 +61,20 @@ class ProjectServiceContainer extends Container
);
}
public function getRemovedIds()
{
return array(
'Psr\\Container\\ContainerInterface' => true,
'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true,
'configurator_service' => true,
'configurator_service_simple' => true,
'decorated.pif-pouf' => true,
'decorator_service.inner' => true,
'inlined' => true,
'new_factory' => true,
);
}
public function compile()
{
throw new LogicException('You cannot compile a dumped container that was already compiled.');

View File

@ -35,6 +35,14 @@ class ProjectServiceContainer extends Container
$this->aliases = array();
}
public function getRemovedIds()
{
return array(
'Psr\\Container\\ContainerInterface' => true,
'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true,
);
}
public function compile()
{
throw new LogicException('You cannot compile a dumped container that was already compiled.');

View File

@ -28,6 +28,14 @@ class Symfony_DI_PhpDumper_Test_Base64Parameters extends Container
$this->aliases = array();
}
public function getRemovedIds()
{
return array(
'Psr\\Container\\ContainerInterface' => true,
'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true,
);
}
public function compile()
{
throw new LogicException('You cannot compile a dumped container that was already compiled.');

View File

@ -55,6 +55,17 @@ class Symfony_DI_PhpDumper_Test_Legacy_Privates extends Container
);
}
public function getRemovedIds()
{
return array(
'Psr\\Container\\ContainerInterface' => true,
'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true,
'foo' => true,
'private_alias_decorator.inner' => true,
'private_decorator.inner' => true,
);
}
public function compile()
{
throw new LogicException('You cannot compile a dumped container that was already compiled.');

View File

@ -40,6 +40,17 @@ class ProjectServiceContainer extends Container
$this->aliases = array();
}
public function getRemovedIds()
{
return array(
'Psr\\Container\\ContainerInterface' => true,
'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true,
'translator.loader_1_locator' => true,
'translator.loader_2_locator' => true,
'translator.loader_3_locator' => true,
);
}
public function compile()
{
throw new LogicException('You cannot compile a dumped container that was already compiled.');

View File

@ -34,6 +34,14 @@ class ProjectServiceContainer extends Container
$this->aliases = array();
}
public function getRemovedIds()
{
return array(
'Psr\\Container\\ContainerInterface' => true,
'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true,
);
}
public function compile()
{
throw new LogicException('You cannot compile a dumped container that was already compiled.');

View File

@ -33,6 +33,15 @@ class ProjectServiceContainer extends Container
$this->aliases = array();
}
public function getRemovedIds()
{
return array(
'Psr\\Container\\ContainerInterface' => true,
'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true,
'private_bar' => true,
);
}
public function compile()
{
throw new LogicException('You cannot compile a dumped container that was already compiled.');

View File

@ -35,6 +35,14 @@ class Symfony_DI_PhpDumper_Test_Rot13Parameters extends Container
$this->aliases = array();
}
public function getRemovedIds()
{
return array(
'Psr\\Container\\ContainerInterface' => true,
'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true,
);
}
public function compile()
{
throw new LogicException('You cannot compile a dumped container that was already compiled.');

View File

@ -38,6 +38,15 @@ class ProjectServiceContainer extends Container
$this->aliases = array();
}
public function getRemovedIds()
{
return array(
'Psr\\Container\\ContainerInterface' => true,
'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true,
'service_locator.jmktfsv' => true,
);
}
public function compile()
{
throw new LogicException('You cannot compile a dumped container that was already compiled.');

View File

@ -35,6 +35,15 @@ class Symfony_DI_PhpDumper_Test_Uninitialized_Reference extends Container
$this->aliases = array();
}
public function getRemovedIds()
{
return array(
'Psr\\Container\\ContainerInterface' => true,
'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true,
'foo2' => true,
);
}
public function compile()
{
throw new LogicException('You cannot compile a dumped container that was already compiled.');

View File

@ -43,8 +43,6 @@
</argument>
</call>
</service>
<service id="alias_for_foo" alias="foo" />
<service id="another_alias_for_foo" alias="foo" public="false" />
<service id="request" class="Request" synthetic="true" lazy="true"/>
<service id="decorator_service" decorates="decorated" />
<service id="decorator_service_with_name" decorates="decorated" decoration-inner-name="decorated.pif-pouf"/>
@ -61,5 +59,7 @@
<service id="new_factory4" class="BazClass">
<factory method="getInstance" />
</service>
<service id="alias_for_foo" alias="foo" />
<service id="another_alias_for_foo" alias="foo" public="false" />
</services>
</container>

View File

@ -17,16 +17,10 @@ services:
class: FooClass
calls:
- [ setBar, [ foo, '@foo', [true, false] ] ]
alias_for_foo: '@foo'
another_alias_for_foo:
alias: foo
public: false
request:
class: Request
synthetic: true
lazy: true
another_third_alias_for_foo:
alias: foo
decorator_service:
decorates: decorated
decorator_service_with_name:
@ -41,3 +35,9 @@ services:
new_factory3: { class: FooBarClass, factory: [BazClass, getInstance]}
new_factory4: { class: BazClass, factory: [~, getInstance]}
Acme\WithShortCutArgs: [foo, '@baz']
alias_for_foo: '@foo'
another_alias_for_foo:
alias: foo
public: false
another_third_alias_for_foo:
alias: foo

View File

@ -139,12 +139,6 @@ services:
class: LazyContext
arguments: [!iterator ['@foo.baz', '@?invalid'], !iterator []]
public: true
alias_for_foo:
alias: 'foo'
public: true
alias_for_alias:
alias: 'foo'
public: true
tagged_iterator_foo:
class: Bar
tags:
@ -161,3 +155,9 @@ services:
Symfony\Component\DependencyInjection\ContainerInterface:
alias: service_container
public: false
alias_for_foo:
alias: 'foo'
public: true
alias_for_alias:
alias: 'foo'
public: true