Description
Q | A |
---|---|
Bug report? | yes |
Feature request? | no |
BC Break report? | no |
RFC? | no |
Symfony version | 3.3.4 |
When using multiple bundles (using the "old" structure from before the AppBundle / bundle-less usage) which use the services.yml
convention to describe the services, and using anonymous services in multiple of these services files the dumped container doesn't work. This is because every anonymous service gets assigned an id based on a counter and the hash of the filename (YamlFileLoader
line 691: $id = sprintf('%d_%s', ++$this->anonymousServicesCount, hash('sha256', $file));
). But the $file
is only the services.yml
(as specified in the ->load
call), and the anonymousServicesCount
is an instance variable and resetted in the ->load
call. This leads to duplicate ids for these anonymous services and will override the previous anonymous service.
A simple test case for this is an Extension which uses two file loaders (which works the same as using multiple bundles each with its own extension using a single loader):
$loader = new YamlFileLoader(
$container,
new FileLocator(__DIR__.'/../Resources/config/foo')
);
$loader->load('services.yml');
$loader = new YamlFileLoader(
$container,
new FileLocator(__DIR__.'/../Resources/config/bar')
);
$loader->load('services.yml');
As services files the following can then be used:
services:
AppBundle\Hello:
arguments:
- !service {class: AppBundle\World}
and
services:
AppBundle\Foo:
arguments:
- !service {class: AppBundle\Bar }
The dumped container will then contain just one anonymous service, being 1_21ea027d6c8c91cadbe51f665e92e08366c04a3d9e7e6eb94ba265237673a195
(in a proper setup there will be two more from the Config component), while there should be two (one to create the AppBundle\World
instance and another to create the AppBundle\Bar
instance).
Further inspection then of course also reveals that both the AppBundle\Hello
and AppBundle\Foo
creation methods also reference the same service id, being that 1_21ea027d6c8c91cadbe51f665e92e08366c04a3d9e7e6eb94ba265237673a195
service.