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 @@ -333,6 +333,31 @@ syntax to parse them as proper PHP constants::
333
333
$parameters = Yaml::parse($yaml, Yaml::PARSE_CONSTANT);
334
334
// $parameters = array('foo' => 'PHP_INT_SIZE', 'bar' => 8);
335
335
336
+ Parsing and Dumping Custom Tags
337
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
338
+
339
+ .. versionadded :: 3.3
340
+ Support for parsing and dumping custom tags was introduced in Symfony 3.3.
341
+
342
+ In addition to the built-in support of tags like ``!php/const `` and
343
+ ``!!binary ``, you can define your own custom YAML tags and parse them with the
344
+ ``PARSE_CUSTOM_TAGS `` flag::
345
+
346
+ $data = "!my_tag { foo: bar }";
347
+ $parsed = Yaml::parse($data, Yaml::PARSE_CUSTOM_TAGS);
348
+ // $parsed = Symfony\Component\Yaml\Tag\TaggedValue('my_tag', array('foo' => 'bar'));
349
+ $tagName = $parsed->getTag(); // $tagName = 'my_tag'
350
+ $tagValue = $parsed->getValue(); // $tagValue = array('foo' => 'bar')
351
+
352
+ If the contents to dump contain :class: `Symfony\\ Component\\ Yaml\\ Tag\\ TaggedValue `
353
+ objects, they are automatically transformed into YAML tags::
354
+
355
+ use Symfony\Component\Yaml\Tag\TaggedValue;
356
+
357
+ $data = new TaggedValue('my_tag', array('foo' => 'bar'));
358
+ $dumped = Yaml::parse($data);
359
+ // $dumped = '!my_tag { foo: bar }'
360
+
336
361
Syntax Validation
337
362
~~~~~~~~~~~~~~~~~
338
363
You can’t perform that action at this time.
0 commit comments