@@ -185,7 +185,10 @@ If you only need to dump one array, you can use the
185
185
186
186
use Symfony\Component\Yaml\Yaml;
187
187
188
- $yaml = Yaml::dump($array, $inline);
188
+ $yaml = Yaml::dump($array);
189
+
190
+ Array Expansion and Inlining
191
+ ............................
189
192
190
193
The YAML format supports two kind of representation for arrays, the expanded
191
194
one, and the inline one. By default, the dumper uses the inline
@@ -201,7 +204,7 @@ representation to the inline one:
201
204
202
205
.. code-block :: php
203
206
204
- echo $dumper-> dump($array, 1);
207
+ echo Yaml:: dump($array, 1);
205
208
206
209
.. code-block :: yaml
207
210
@@ -210,7 +213,7 @@ representation to the inline one:
210
213
211
214
.. code-block :: php
212
215
213
- echo $dumper-> dump($array, 2);
216
+ echo Yaml:: dump($array, 2);
214
217
215
218
.. code-block :: yaml
216
219
@@ -219,6 +222,49 @@ representation to the inline one:
219
222
foo : bar
220
223
bar : baz
221
224
225
+ Indentation
226
+ ...........
227
+
228
+ By default the YAML component will use 4 spaces for indentation. This can be
229
+ changed using the second argument as follows::
230
+
231
+ // use 8 spaces for indentation
232
+ echo Yaml::dump($array, 2, 8);
233
+
234
+ .. code-block :: yaml
235
+
236
+ foo : bar
237
+ bar :
238
+ foo : bar
239
+ bar : baz
240
+
241
+ Invalid Types and Object Serialization
242
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
243
+
244
+ By default the YAML component will encode any "unsupported" type (i.e.
245
+ resources and objects) as ``null ``.
246
+
247
+ Instead of encoding as ``null `` you can choose to throw an exception if an invalid
248
+ type is encountered in either the dumper or parser as follows::
249
+
250
+ // throw an exception if a resource or object is encoutered
251
+ Yaml::dump($data, 2, 4, true);
252
+
253
+ // throw an exception if an encoded object is found in the YAML string
254
+ Yaml::parse($yaml, true);
255
+
256
+ However, you can activate object support using the next argument::
257
+
258
+ $object = new \stdClass();
259
+ $object->hello = 'goodbye';
260
+
261
+ $dumped = Yaml::dump($object, 2, 4, false, true);
262
+ // !!php/object:O:8:"stdClass":1:{s:5:"hello";s:7:"goodbye";}
263
+
264
+ $parsed = Yaml::parse($dumped, false, true);
265
+ var_dump(is_object($parsed)); // true
266
+ echo $parsed->hello; // goodbye
267
+
222
268
.. _YAML : http://yaml.org/
223
269
.. _Packagist : https://packagist.org/packages/symfony/yaml
224
270
.. _`YAML 1.2 version specification` : http://yaml.org/spec/1.2/spec.html
0 commit comments