-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Documented the missing YAML flags #9205
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -267,6 +267,29 @@ representation of the object. | |
parsers will likely not recognize the ``php/object`` tag and non-PHP | ||
implementations certainly won't - use with discretion! | ||
|
||
Parsing and Dumping Objects as Maps | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
.. versionadded:: 3.2 | ||
Support for parsing and dumping objectas as maps was introduced in Symfony 3.2. | ||
|
||
You can dump objects as Yaml maps by using the ``DUMP_OBJECT_AS_MAP`` flag:: | ||
|
||
$object = new \stdClass(); | ||
$object->foo = 'bar'; | ||
|
||
$dumped = Yaml::dump(array('data' => $object), 2, 4, Yaml::DUMP_OBJECT_AS_MAP); | ||
// $dumped = "data:\nfoo:\nSbar" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
And parse them by using the ``PARSE_OBJECT_FOR_MAP`` flag:: | ||
|
||
$parsed = Yaml::parse($dumped, Yaml::PARSE_OBJECT); | ||
var_dump(is_object($parsed)); // true | ||
echo $parsed->foo; // bar | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if |
||
|
||
The YAML component uses PHP's ``(array)`` casting to generate a string | ||
representation of the object as a map. | ||
|
||
.. _invalid-types-and-object-serialization: | ||
|
||
Handling Invalid Types | ||
|
@@ -333,6 +356,26 @@ syntax to parse them as proper PHP constants:: | |
$parameters = Yaml::parse($yaml, Yaml::PARSE_CONSTANT); | ||
// $parameters = array('foo' => 'PHP_INT_SIZE', 'bar' => 8); | ||
|
||
Parsing and Dumping of Binary Data | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
.. versionadded:: 3.2 | ||
Support for parsing and dumping binary data was introduced in Symfony 3.2. | ||
|
||
You can dump binary data by using the ``DUMP_BASE64_BINARY_DATA`` flag:: | ||
|
||
$imageContents = file_get_contents(__DIR__.'/images/logo.png'); | ||
|
||
$dumped = Yaml::dump(array('logo' => $imageContents), 2, 4, Yaml::DUMP_BASE64_BINARY_DATA); | ||
// logo: !!binary iVBORw0KGgoAAAANSUhEUgAAA6oAAADqCAY... | ||
|
||
Binary data is automatically parsed if they include the ``!!binary`` YAML tag | ||
(there's no need to pass any flag to the Yaml parser):: | ||
|
||
$dumped = 'logo: !!binary iVBORw0KGgoAAAANSUhEUgAAA6oAAADqCAY...'; | ||
$parsed = Yaml::parse($dumped); | ||
$imageContents = $parsed['logo']; | ||
|
||
Syntax Validation | ||
~~~~~~~~~~~~~~~~~ | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
objects