Skip to content

[DependencyInjection][Improve] Constant YAML with expression language] #7520

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

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions service_container/parameters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,12 @@ key and define the type as ``constant``.

.. configuration-block::

.. code-block:: yaml

parameters:
global.constant.value: "@=constant('GLOBAL_CONSTANT')"
my_class.constant.value: "@=constant('My_Class::CONSTANT_NAME')"

.. code-block:: xml

<?xml version="1.0" encoding="UTF-8" ?>
Expand All @@ -243,6 +249,13 @@ key and define the type as ``constant``.
$container->setParameter('global.constant.value', GLOBAL_CONSTANT);
$container->setParameter('my_class.constant.value', My_Class::CONSTANT_NAME);

.. caution::

YAML files can refer to PHP constants via the ``@=constant('CONSTANT_NAME')``
syntax, which is provided by the
:doc:`Expression Language component </components/expression_language>`. See
:doc:`/components/expression_language/syntax` to learn more about its syntax.

.. tip::

If you're using YAML, you can :doc:`import an XML file </service_container/import>`
Expand All @@ -253,6 +266,10 @@ key and define the type as ``constant``.
imports:
- { resource: parameters.xml }

.. note::

  In Symfony 3.2, YAML supports PHP constants via the ``!php/const:CONSTANT_NAME`` syntax.

PHP Keywords in XML
-------------------

Expand Down