Skip to content

Commit e02b79e

Browse files
[Yaml] Mention php/enum
1 parent 9f8ca28 commit e02b79e

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

reference/formats/yaml.rst

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,43 @@ The YAML specification defines some tags to set the type of any data explicitly:
315315
Pz7Y6OjuDg4J+fn5OTk6enp
316316
56enmleECcgggoBADs=
317317
318+
Symfony Specific Tags
319+
~~~~~~~~~~~~~~~~~~~~~
320+
321+
The YAML component provides a few additional tags that brings a few
322+
features when parsed in your PHP code:
323+
324+
* ``!php/const`` allows to use a constant name defined in a PHP file. This
325+
tag takes a constant FQCN as its argument:
326+
327+
.. code-block:: yaml
328+
329+
data:
330+
page_limit: !php/const App\Pagination\Paginator::PAGE_LIMIT
331+
332+
* ``!php/object`` allows to pass the serialized representation of a PHP
333+
object, which will be deserialized when the parsing is done:
334+
335+
.. code-block:: yaml
336+
337+
data:
338+
my_object: !php/object 'O:8:"stdClass":1:{s:3:"bar";i:2;}'
339+
340+
* ``!php/enum`` allows to use an enum case. This tag takes the enum case
341+
FQCN as its argument:
342+
343+
.. code-block:: yaml
344+
345+
data:
346+
# You can use the typed enum case...
347+
operator_type: !php/enum App\Operator\Enum\Type::Or
348+
# ... or you can also use "->value" to directly use the value of a BackedEnum case
349+
operator_type: !php/enum App\Operator\Enum\Type::Or->value
350+
351+
.. versionadded:: 6.2
352+
353+
The ``!php/enum`` tag was introduced in Symfony 6.2.
354+
318355
Unsupported YAML Features
319356
~~~~~~~~~~~~~~~~~~~~~~~~~
320357

0 commit comments

Comments
 (0)