New in Symfony 3.2: YAML deprecations
September 6, 2016 • Published by Javier Eguiluz
Warning: This post is about an unsupported Symfony version. Some of this information may be out of date. Read the most recent Symfony Docs.
Symfony 3.2 will introduce some minor YAML deprecations in order to make the Yaml component fully compliant with the YAML specification.
Deprecated missing spaces after map keys
When defining a map, YAML requires to add at least one white space after the
colon that separates the key and the value. In previous Symfony versions we
didn't require to include that white space. In Symfony 3.2 we've deprecated this
behavior and Symfony 4.0 will throw a ParseException
.
1 2 3 4 5 6 7 8 9 10 11
# It works in Symfony 3.1, it's deprecated in 3.2, it fails in 4.0
parameters:
foo:bar
published:true
default_page:1
# It works in every past, present and future Symfony version
parameters:
foo: bar
published: true
default_page: 1
Deprecated defining duplicated keys
In previous Symfony versions, when a single YAML file contained duplicated keys the first key was used and the rest were silently ignored:
1 2 3 4 5 6
# the second key is ignored and this document is parsed
# as: 'parameters' => array('key' => 'aaa')
parameters:
key: 'aaa'
# ...
key: 'bbb'
In Symfony 3.2 this behavior is deprecated and Symfony 4.0 will throw a
ParseException
, so it's time to check if your YAML files contain duplicated
keys.
Moved the yaml:lint
command to the Yaml component
Not strictly a deprecation, but in Symfony 3.2 we decided to move the yaml:lint
command from the FrameworkBundle to the Yaml component. This will allow you to
lint your YAML files without having to require the entire FrameworkBundle.
The only difference is that when using yaml:lint
via the component you can
check files and directories, whereas using it in the full-stack framework also
lets you check entire bundles:
1 2 3 4 5 6
# it works in the component and the framework
$ ./bin/console yaml:lint parameters.yml
$ ./bin/console yaml:lint app/config/
# it only works in the framework
$ ./bin/console yaml:lint @AppBundle
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.
Wat to go!
it is not in the forbidden indicator (http://www.yaml.org/spec/1.2/spec.html#c-flow-indicator) and it is explicitly allowed in values (http://www.yaml.org/spec/1.2/spec.html#ns-plain-char(c)).
It's more nuanced than that: http://www.yaml.org/spec/1.2/spec.html#: mapping value//