New in Symfony 2.8: YAML deprecations
Warning: This post is about an unsupported Symfony version. Some of this information may be out of date. Read the most recent Symfony Docs.
in #16201, #16285 and #16433.
The upcoming Symfony 3.1 version will introduce lots of new and useful features for the Yaml component. But before enjoying those features, in Symfony 2.8 we needed to deprecate some features to make Yaml files comply with the Yaml specification. Make sure to fix all these changes before upgrading your applications to Symfony 3.
\ in double-quoted strings
This deprecation is common when defining the classes of the services:
1 2 3
app.user_manager: class: "AppBundle\Manager\UserManager" # ...
The alternative is either remove the double quotes or escape the
1 2 3 4 5 6
app.user_manager: # remove double quotes... class: AppBundle\Manager\UserManager # ...or escape backslashes class: "AppBundle\\Manager\\UserManager" # ...
Deprecated usage of
@ at the beginning of unquoted strings
This deprecation has a big impact because lots of services use the
notation to define their dependencies:
1 2 3
app.user_manager: # ... arguments: [@router, @logger, @doctrine.orm.entity_manager]
According to Yaml specification, unquoted strings cannot start with
@, so you
must wrap these arguments with single or double quotes:
1 2 3
app.user_manager: # ... arguments: ['@router', '@logger', '@doctrine.orm.entity_manager']
Deprecated usage of reserved characters at the beginning of unquoted strings
These deprecations should have a low impact for Symfony developers because it's uncommon to use these characters as the beginning of unquoted strings:
1 2 3
app.user_manager: # ... arguments: [`string`, |string, >string]
The solution is to wrap these strings with single or double quotes:
1 2 3
app.user_manager: # ... arguments: ['`string`', '|string', '>string']
Deprecations are always a pain for developers and we try to avoid them as much as possible. But allowing to create Yaml files which don't respect the official specification is unquestionably wrong. The recent Symfony 3.0 release was the perfect moment to fix these problems.
Help the Symfony project!
As with any Open-Source project, contributing code or documentation is the most common way to help, but we also have a wide range of sponsoring opportunities.
Comments are closed.
To ensure that comments stay relevant, they are closed for old posts.
What about using single quotes to wrap full qualified class names ?
Does this also need to double backslashes ?
What about parameters ? Since '@foo' must now be quoted, maybe it could be a good practice to quote '%parameters%' too ?
It is already used by some Symfony developers.
So I assume this will be as of 3.1