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 53a1e98

Browse filesBrowse files
[DI] Deprecate underscore-services in YamlFileLoader
1 parent b3b3dac commit 53a1e98
Copy full SHA for 53a1e98

File tree

3 files changed

+17
-1
lines changed
Filter options

3 files changed

+17
-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
@@ -182,7 +182,7 @@ private function parseDefaults(array &$content, $file)
182182
throw new InvalidArgumentException(sprintf('Service defaults must be an array, "%s" given in "%s".', gettype($defaults), $file));
183183
}
184184
if (isset($defaults['alias']) || isset($defaults['class']) || isset($defaults['factory'])) {
185-
@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);
185+
// @deprecated code path, to be removed in 4.0
186186

187187
return array();
188188
}
@@ -239,6 +239,9 @@ private function parseDefaults(array &$content, $file)
239239
*/
240240
private function parseDefinition($id, $service, $file, array $defaults)
241241
{
242+
if (preg_match('/^_[a-zA-Z0-9_]*$/', $id)) {
243+
@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);
244+
}
242245
if (is_string($service) && 0 === strpos($service, '@')) {
243246
$public = isset($defaults['public']) ? $defaults['public'] : true;
244247
$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
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,4 +433,14 @@ public function testInvalidTagsWithDefaults()
433433
$loader = new YamlFileLoader(new ContainerBuilder(), new FileLocator(self::$fixturesPath.'/yaml'));
434434
$loader->load('services31_invalid_tags.yml');
435435
}
436+
437+
/**
438+
* @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.
439+
*/
440+
public function testUnderscoreServiceId()
441+
{
442+
$container = new ContainerBuilder();
443+
$loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml'));
444+
$loader->load('services_underscore.yml');
445+
}
436446
}

0 commit comments

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