File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -377,6 +377,31 @@ Binary data is automatically parsed if they include the ``!!binary`` YAML tag
377377 $parsed = Yaml::parse($dumped);
378378 $imageContents = $parsed['logo'];
379379
380+ Parsing and Dumping Custom Tags
381+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
382+
383+ .. versionadded :: 3.3
384+ Support for parsing and dumping custom tags was introduced in Symfony 3.3.
385+
386+ In addition to the built-in support of tags like ``!php/const `` and
387+ ``!!binary ``, you can define your own custom YAML tags and parse them with the
388+ ``PARSE_CUSTOM_TAGS `` flag::
389+
390+ $data = "!my_tag { foo: bar }";
391+ $parsed = Yaml::parse($data, Yaml::PARSE_CUSTOM_TAGS);
392+ // $parsed = Symfony\Component\Yaml\Tag\TaggedValue('my_tag', array('foo' => 'bar'));
393+ $tagName = $parsed->getTag(); // $tagName = 'my_tag'
394+ $tagValue = $parsed->getValue(); // $tagValue = array('foo' => 'bar')
395+
396+ If the contents to dump contain :class: `Symfony\\ Component\\ Yaml\\ Tag\\ TaggedValue `
397+ objects, they are automatically transformed into YAML tags::
398+
399+ use Symfony\Component\Yaml\Tag\TaggedValue;
400+
401+ $data = new TaggedValue('my_tag', array('foo' => 'bar'));
402+ $dumped = Yaml::dump($data);
403+ // $dumped = '!my_tag { foo: bar }'
404+
380405Syntax Validation
381406~~~~~~~~~~~~~~~~~
382407
You can’t perform that action at this time.
0 commit comments