[DependencyInjection] remove deprecated YAML configuration features and syntax
This commit is contained in:
parent
8514e22399
commit
854efce7ca
@ -315,8 +315,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);
|
||||
throw new InvalidArgumentException(sprintf('Service names that start with an underscore are reserved. Rename the "%s" service or define it in XML instead.', $id));
|
||||
}
|
||||
|
||||
if (is_string($service) && 0 === strpos($service, '@')) {
|
||||
$public = isset($defaults['public']) ? $defaults['public'] : true;
|
||||
$this->container->setAlias($id, new Alias(substr($service, 1), $public));
|
||||
@ -344,7 +345,7 @@ class YamlFileLoader extends FileLoader
|
||||
|
||||
foreach ($service as $key => $value) {
|
||||
if (!in_array($key, array('alias', 'public'))) {
|
||||
@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);
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
@ -740,11 +741,6 @@ class YamlFileLoader extends FileLoader
|
||||
$invalidBehavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE;
|
||||
}
|
||||
|
||||
if ('=' === substr($value, -1)) {
|
||||
@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);
|
||||
$value = substr($value, 0, -1);
|
||||
}
|
||||
|
||||
if (null !== $invalidBehavior) {
|
||||
$value = new Reference($value, $invalidBehavior);
|
||||
}
|
||||
@ -782,7 +778,7 @@ class YamlFileLoader extends FileLoader
|
||||
*/
|
||||
private function checkDefinition($id, array $definition, $file)
|
||||
{
|
||||
if ($throw = $this->isLoadingInstanceof) {
|
||||
if ($this->isLoadingInstanceof) {
|
||||
$keywords = self::$instanceofKeywords;
|
||||
} elseif ($throw = isset($definition['resource'])) {
|
||||
$keywords = self::$prototypeKeywords;
|
||||
@ -792,11 +788,7 @@ class YamlFileLoader extends FileLoader
|
||||
|
||||
foreach ($definition as $key => $value) {
|
||||
if (!isset($keywords[$key])) {
|
||||
if ($throw) {
|
||||
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)));
|
||||
}
|
||||
|
||||
@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);
|
||||
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)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,11 @@
|
||||
services:
|
||||
foo:
|
||||
class: stdClass
|
||||
public: false
|
||||
|
||||
bar:
|
||||
alias: foo
|
||||
public: true
|
||||
# keys other than "alias" and "public" are invalid when defining an alias.
|
||||
calls:
|
||||
- [doSomething]
|
@ -510,8 +510,8 @@ class YamlFileLoaderTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @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.
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
|
||||
* @expectedExceptionMessage Service names that start with an underscore are reserved. Rename the "_foo" service or define it in XML instead.
|
||||
*/
|
||||
public function testUnderscoreServiceId()
|
||||
{
|
||||
@ -633,6 +633,28 @@ class YamlFileLoaderTest extends TestCase
|
||||
$loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml'));
|
||||
$loader->load('bad_empty_instanceof.yml');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
|
||||
* @expectedExceptionMessageRegExp /^The configuration key "private" is unsupported for definition "bar"/
|
||||
*/
|
||||
public function testUnsupportedKeywordThrowsException()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml'));
|
||||
$loader->load('bad_keyword.yml');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
|
||||
* @expectedExceptionMessageRegExp /^The configuration key "calls" is unsupported for the service "bar" which is defined as an alias/
|
||||
*/
|
||||
public function testUnsupportedKeywordInServiceAliasThrowsException()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml'));
|
||||
$loader->load('bad_alias.yml');
|
||||
}
|
||||
}
|
||||
|
||||
interface FooInterface
|
||||
|
Reference in New Issue
Block a user