@@ -267,6 +267,30 @@ representation of the object.
267267 parsers will likely not recognize the ``php/object `` tag and non-PHP
268268 implementations certainly won't - use with discretion!
269269
270+ Parsing and Dumping Objects as Maps
271+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
272+
273+ .. versionadded :: 3.2
274+ Support for parsing and dumping objects as maps was introduced in Symfony 3.2.
275+
276+ You can dump objects as Yaml maps by using the ``DUMP_OBJECT_AS_MAP `` flag::
277+
278+ $object = new \stdClass();
279+ $object->foo = 'bar';
280+
281+ $dumped = Yaml::dump(array('data' => $object), 2, 4, Yaml::DUMP_OBJECT_AS_MAP);
282+ // $dumped = "data:\n foo: bar"
283+
284+ And parse them by using the ``PARSE_OBJECT_FOR_MAP `` flag::
285+
286+ $parsed = Yaml::parse($dumped, Yaml::PARSE_OBJECT_FOR_MAP);
287+ var_dump(is_object($parsed)); // true
288+ var_dump(is_object($parsed->data)); // true
289+ echo $parsed->data->foo; // bar
290+
291+ The YAML component uses PHP's ``(array) `` casting to generate a string
292+ representation of the object as a map.
293+
270294.. _invalid-types-and-object-serialization :
271295
272296Handling Invalid Types
@@ -333,6 +357,26 @@ syntax to parse them as proper PHP constants::
333357 $parameters = Yaml::parse($yaml, Yaml::PARSE_CONSTANT);
334358 // $parameters = array('foo' => 'PHP_INT_SIZE', 'bar' => 8);
335359
360+ Parsing and Dumping of Binary Data
361+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
362+
363+ .. versionadded :: 3.2
364+ Support for parsing and dumping binary data was introduced in Symfony 3.2.
365+
366+ You can dump binary data by using the ``DUMP_BASE64_BINARY_DATA `` flag::
367+
368+ $imageContents = file_get_contents(__DIR__.'/images/logo.png');
369+
370+ $dumped = Yaml::dump(array('logo' => $imageContents), 2, 4, Yaml::DUMP_BASE64_BINARY_DATA);
371+ // logo: !!binary iVBORw0KGgoAAAANSUhEUgAAA6oAAADqCAY...
372+
373+ Binary data is automatically parsed if they include the ``!!binary `` YAML tag
374+ (there's no need to pass any flag to the Yaml parser)::
375+
376+ $dumped = 'logo: !!binary iVBORw0KGgoAAAANSUhEUgAAA6oAAADqCAY...';
377+ $parsed = Yaml::parse($dumped);
378+ $imageContents = $parsed['logo'];
379+
336380Syntax Validation
337381~~~~~~~~~~~~~~~~~
338382
0 commit comments