8000 Documented how to parse and dump custom YAML tags by javiereguiluz · Pull Request #9212 · symfony/symfony-docs · GitHub
[go: up one dir, main page]

Skip to content

Documented how to parse and dump custom YAML tags #9212

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions components/yaml.rst
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,31 @@ Binary data is automatically parsed if they include the ``!!binary`` YAML tag
$parsed = Yaml::parse($dumped);
$imageContents = $parsed['logo'];

Parsing and Dumping Custom Tags
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. versionadded:: 3.3
Support for parsing and dumping custom tags was introduced in Symfony 3.3.

In addition to the built-in support of tags like ``!php/const`` and
``!!binary``, you can define your own custom YAML tags and parse them with the
``PARSE_CUSTOM_TAGS`` flag::

$data = "!my_tag { foo: bar }";
$parsed = Yaml::parse($data, Yaml::PARSE_CUSTOM_TAGS);
// $parsed = Symfony\Component\Yaml\Tag\TaggedValue('my_tag', array('foo' => 'bar'));
$tagName = $parsed->getTag(); // $tagName = 'my_tag'
$tagValue = $parsed->getValue(); // $tagValue = array('foo' => 'bar')

If the contents to dump contain :class:`Symfony\\Component\\Yaml\\Tag\\TaggedValue`
objects, they are automatically transformed into YAML tags::

use Symfony\Component\Yaml\Tag\TaggedValue;

$data = new TaggedValue('my_tag', array('foo' => 'bar'));
$dumped = Yaml::dump($data);
// $dumped = '!my_tag { foo: bar }'

Syntax Validation
~~~~~~~~~~~~~~~~~

Expand Down
0