8000 [DependencyInjection] remove deprecated YAML configuration features a… · hhamon/symfony@854efce · GitHub
[go: up one dir, main page]

Skip to content

Commit 854efce

Browse files
author
Hugo Hamon
committed
[DependencyInjection] remove deprecated YAML configuration features and syntax
1 parent 8514e22 commit 854efce

File tree

4 files changed

+40
-15
lines changed

4 files changed

+40
-15
lines changed

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

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,9 @@ private function isUsingShortSyntax(array $service)
315315
private function parseDefinition($id, $service, $file, array $defaults)
316316
{
317317
if (preg_match('/^_[a-zA-Z0-9_]*$/', $id)) {
318-
@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);
318+
throw new InvalidArgumentException(sprintf('Service names that start with an underscore are reserved. Rename the "%s" service or define it in XML instead.', $id));
319319
}
320+
320321
if (is_string($service) && 0 === strpos($service, '@')) {
321322
$public = isset($defaults['public']) ? $defaults['public'] : true;
322323
$this->container->setAlias($id, new Alias(substr($service, 1), $public));
@@ -344,7 +345,7 @@ private function parseDefinition($id, $service, $file, array $defaults)
344345

345346
foreach ($service as $key => $value) {
346347
if (!in_array($key, array('alias', 'public'))) {
347-
@trigger_error(sprintf('The configuration key "%s" is unsupported for the service "%s" which is defined as an alias in "%s". Allowed configuration keys for service aliases are "alias" and "public". The YamlFileLoader will raise an exception in Symfony 4.0, instead of silently ignoring unsupported attributes.', $key, $id, $file), E_USER_DEPRECATED);
348+
throw new InvalidArgumentException(sprintf('The configuration key "%s" is unsupported for the service "%s" which is defined as an alias in "%s". Allowed configuration keys for service aliases are "alias" and "public".', $key, $id, $file));
348349
}
349350
}
350351

@@ -740,11 +741,6 @@ private function resolveServices($value, $file, $isParameter = false)
740741
$invalidBehavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE;
741742
}
742743

743-
if ('=' === substr($value, -1)) {
744-
@trigger_error(sprintf('The "=" suffix that used to disable strict references in Symfony 2.x is deprecated since 3.3 and will be unsupported in 4.0. Remove it in "%s".', $value), E_USER_DEPRECATED);
745-
$value = substr($value, 0, -1);
746-
}
747-
748744
if (null !== $invalidBehavior) {
749745
$value = new Reference($value, $invalidBehavior);
750746
}
@@ -782,7 +778,7 @@ private function loadFromExtensions(array $content)
782778
*/
783779
private function checkDefinition($id, array $definition, $file)
784780
{
785-
if ($throw = $this->isLoadingInstanceof) {
781+
if ($this->isLoadingInstanceof) {
786782
$keywords = self::$instanceofKeywords;
787783
} elseif ($throw = isset($definition['resource'])) {
788784
$keywords = self::$prototypeKeywords;
@@ -792,11 +788,7 @@ private function checkDefinition($id, array $definition, $file)
792788

793789
foreach ($definition as $key => $value) {
794790
if (!isset($keywords[$key])) {
795-
if ($throw) {
796-
throw new InvalidArgumentException(sprintf('The configuration key "%s" is unsupported for definition "%s" in "%s". Allowed configuration keys are "%s".', $key, $id, $file, implode('", "', $keywords)));
797-
}
798-
799-
@trigger_error(sprintf('The configuration key "%s" is unsupported for service definition "%s" in "%s". Allowed configuration keys are "%s". The YamlFileLoader object will raise an exception instead in Symfony 4.0 when detecting an unsupported service configuration key.', $key, $id, $file, implode('", "', $keywords)), E_USER_DEPRECATED);
791+
throw new InvalidArgumentException(sprintf('The configuration key "%s" is unsupported for definition "%s" in "%s". Allowed configuration keys are "%s".', $key, $id, $file, implode('", "', $keywords)));
800792
}
801793
}
802794
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
services:
2+
foo:
3+
class: stdClass
4+
public: false
5+
6+
bar:
7+
alias: foo
8+
public: true
9+
# keys other than "alias" and "public" are invalid when defining an alias.
10+
calls:
11+
- [doSomething]

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

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -510,8 +510,8 @@ public function testInvalidTagsWithDefaults()
510510
}
511511

512512
/**
513-
* @group legacy
514-
* @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.
513+
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
514+
* @expectedExceptionMessage Service names that start with an underscore are reserved. Rename the "_foo" service or define it in XML instead.
515515
*/
516516
public function testUnderscoreServiceId()
517517
{
@@ -633,6 +633,28 @@ public function testEmptyInstanceofThrowsClearException()
633633
$loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml'));
634634
$loader->load('bad_empty_instanceof.yml');
635635
}
636+
637+
/**
638+
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
639+
* @expectedExceptionMessageRegExp /^The configuration key "private" is unsupported for definition "bar"/
640+
*/
641+
public function testUnsupportedKeywordThrowsException()
642+
{
643+
$container = new ContainerBuilder();
644+
$loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml'));
645+
$loader->load('bad_keyword.yml');
646+
}
647+
648+
/**
649+
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
650+
* @expectedExceptionMessageRegExp /^The configuration key "calls" is unsupported for the service "bar" which is defined as an alias/
651+
*/
652+
public function testUnsupportedKeywordInServiceAliasThrowsException()
653+
{
654+
$container = new ContainerBuilder();
655+
$loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml'));
656+
$loader->lo 4C05 ad('bad_alias.yml');
657+
}
636658
}
637659

638660
interface FooInterface

0 commit comments

Comments
 (0)
0