Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7c9a5c1

Browse filesBrowse files
committed
feature #21484 [DI] Deprecate underscore-services in YamlFileLoader (nicolas-grekas)
This PR was merged into the 3.3-dev branch. Discussion ---------- [DI] Deprecate underscore-services in YamlFileLoader | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | yes | Tests pass? | no | Fixed tickets | - | License | MIT | Doc PR | - As discussed when introducing `_defaults` Commits ------- 7781082 [DI] Deprecate underscore-services in YamlFileLoader
2 parents a70ee67 + 7781082 commit 7c9a5c1
Copy full SHA for 7c9a5c1

File tree

3 files changed

+18
-1
lines changed
Filter options

3 files changed

+18
-1
lines changed

‎src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ private function parseDefaults(array &$content, $file)
210210
throw new InvalidArgumentException(sprintf('Service defaults must be an array, "%s" given in "%s".', gettype($defaults), $file));
211211
}
212212
if (isset($defaults['alias']) || isset($defaults['class']) || isset($defaults['factory'])) {
213-
@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);
213+
// @deprecated code path, to be removed in 4.0
214214

215215
return array();
216216
}
@@ -282,6 +282,9 @@ private function isUsingShortSyntax(array $service)
282282
*/
283283
private function parseDefinition($id, $service, $file, array $defaults)
284284
{
285+
if (preg_match('/^_[a-zA-Z0-9_]*$/', $id)) {
286+
@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);
287+
}
285288
if (is_string($service) && 0 === strpos($service, '@')) {
286289
$public = isset($defaults['public']) ? $defaults['public'] : true;
287290
$this->container->setAlias($id, new Alias(substr($service, 1), $public));
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
services:
2+
_foo:
3+
class: Foo

‎src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,4 +488,15 @@ public function testInvalidTagsWithDefaults()
488488
$loader = new YamlFileLoader(new ContainerBuilder(), new FileLocator(self::$fixturesPath.'/yaml'));
489489
$loader->load('services31_invalid_tags.yml');
490490
}
491+
492+
/**
493+
* @group legacy
494+
* @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.
495+
*/
496+
public function testUnderscoreServiceId()
497+
{
498+
$container = new ContainerBuilder();
499+
$loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml'));
500+
$loader->load('services_underscore.yml');
501+
}
491502
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.