[DI] Deprecate underscore-services in YamlFileLoader
This commit is contained in:
parent
55a34b7b51
commit
7781082587
@ -182,7 +182,7 @@ class YamlFileLoader extends FileLoader
|
||||
throw new InvalidArgumentException(sprintf('Service defaults must be an array, "%s" given in "%s".', gettype($defaults), $file));
|
||||
}
|
||||
if (isset($defaults['alias']) || isset($defaults['class']) || isset($defaults['factory'])) {
|
||||
@trigger_error('Giving a service the "_defaults" name is deprecated since Symfony 3.3 and will be forbidden in 4.0. Rename your service.', E_USER_DEPRECATED);
|
||||
// @deprecated code path, to be removed in 4.0
|
||||
|
||||
return array();
|
||||
}
|
||||
@ -239,6 +239,9 @@ class YamlFileLoader extends FileLoader
|
||||
*/
|
||||
private function parseDefinition($id, $service, $file, array $defaults)
|
||||
{
|
||||
if (preg_match('/^_[a-zA-Z0-9_]*$/', $id)) {
|
||||
@trigger_error(sprintf('Service names that start with an underscore are deprecated since Symfony 3.3 and will be reserved in 4.0. Rename the "%s" service or define it in XML instead.', $id), E_USER_DEPRECATED);
|
||||
}
|
||||
if (is_string($service) && 0 === strpos($service, '@')) {
|
||||
$public = isset($defaults['public']) ? $defaults['public'] : true;
|
||||
$this->container->setAlias($id, new Alias(substr($service, 1), $public));
|
||||
|
@ -0,0 +1,3 @@
|
||||
services:
|
||||
_foo:
|
||||
class: Foo
|
@ -436,4 +436,15 @@ class YamlFileLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
$loader = new YamlFileLoader(new ContainerBuilder(), new FileLocator(self::$fixturesPath.'/yaml'));
|
||||
$loader->load('services31_invalid_tags.yml');
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
* @expectedDeprecation Service names that start with an underscore are deprecated since Symfony 3.3 and will be reserved in 4.0. Rename the "_foo" service or define it in XML instead.
|
||||
*/
|
||||
public function testUnderscoreServiceId()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml'));
|
||||
$loader->load('services_underscore.yml');
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user