8000 Merge branch '6.2' into 6.3 · symfony/symfony-docs@a780195 · GitHub
[go: up one dir, main page]

Skip to content

Commit a780195

Browse files
committed
Merge branch '6.2' into 6.3
* 6.2: [Yaml] Mention `php/enum` [Yaml] Mention `php/const` and `php/object`
2 parents 0d0d23a + 5196974 commit a780195

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

reference/formats/yaml.rst

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,44 @@ The YAML specification defines some tags to set the type of any data explicitly:
315315
Pz7Y6OjuDg4J+fn5OTk6enp
316316
56enmleECcgggoBADs=
317317
318+
Symfony Specific Features
319+
~~~~~~~~~~~~~~~~~~~~~~~~~
320+
321+
The Yaml component provides some additional features that are not part of the
322+
official YAML specification but are useful in Symfony applications:
323+
324+
* ``!php/const`` allows to get the value of a PHP constant. This tag takes the
325+
fully-qualified class name of the constant 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 (created with the `serialize()`_ function), which will be deserialized
334+
when parsing the YAML file:
335+
336+
.. code-block:: yaml
337+
338+
data:
339+
my_object: !php/object 'O:8:"stdClass":1:{s:3:"bar";i:2;}'
340+
341+
* ``!php/enum`` allows to use a PHP enum case. This tag takes the fully-qualified
342+
class name of the enum case as its argument:
343+
344+
.. code-block:: yaml
345+
346+
data:
347+
# You can use the typed enum case...
348+
operator_type: !php/enum App\Operator\Enum\Type::Or
349+
# ... or you can also use "->value" to directly use the value of a BackedEnum case
350+
operator_type: !php/enum App\Operator\Enum\Type::Or->value
351+
352+
.. versionadded:: 6.2
353+
354+
The ``!php/enum`` tag was introduced in Symfony 6.2.
355+
318356
Unsupported YAML Features
319357
~~~~~~~~~~~~~~~~~~~~~~~~~
320358

@@ -332,3 +370,4 @@ The following YAML features are not supported by the Symfony Yaml component:
332370

333371
.. _`YAML 1.2 version specification`: https://yaml.org/spec/1.2/spec.html
334372
.. _`ISO-8601`: https://www.iso.org/iso-8601-date-and-time-format.html
373+
.. _`serialize()`: https://www.php.net/manual/en/function.serialize.php

0 commit comments

Comments
 (0)
0