File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -338,6 +338,30 @@ syntax to parse them as proper PHP constants::
338
338
$parameters = Yaml::parse($yaml, Yaml::PARSE_CONSTANT);
339
339
// $parameters = ['foo' => 'PHP_INT_SIZE', 'bar' => 8];
340
340
341
+ Parsing Unit and Backed Enumerations
342
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
343
+
344
+ Unit and backed enumerations can be parsed by the YAML parser thanks to the
345
+ special ``!php/enum `` syntax and the ``PARSE_CONSTANT `` flag. Depending if
346
+ you need the concrete enumeration case or the actual value of the case when
347
+ dealing with backed enumerations, both syntax are available::
348
+
349
+ enum FooEnum: string
350
+ {
351
+ case Foo = 'foo';
352
+ case Bar = 'bar';
353
+ }
354
+
355
+ // ...
356
+
357
+ $yaml = '{ foo: FooEnum::Foo, bar: !php/enum FooEnum::Foo }';
358
+ $parameters = Yaml::parse($yaml, Yaml::PARSE_CONSTANT);
359
+ // $parameters = ['foo' => 'FooEnum::Foo', 'bar' => FooEnum::Foo];
360
+
361
+ $yaml = '{ foo: FooEnum::Foo, bar: !php/enum FooEnum::Foo->value }';
362
+ $parameters = Yaml::parse($yaml, Yaml::PARSE_CONSTANT);
363
+ // $parameters = ['foo' => 'FooEnum::Foo', 'bar' => 'foo'];
364
+
341
365
Parsing and Dumping of Binary Data
342
366
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
343
367
You can’t perform that action at this time.
0 commit comments