Skip to content

Document the yaml_file usage #11121

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

Closed
wants to merge 7 commits into from
Closed
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
43 changes: 43 additions & 0 deletions service_container.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1072,6 +1072,49 @@ If you want to pass the second, you'll need to :ref:`manually wire the service <
and the automatically loaded service will be passed - by default - when you type-hint
``SiteUpdateManager``. That's why creating the alias is a good idea.

Injecting the content of YAML file as argument
----------------------------------------------

.. versionadded:: 4.3

Support for the YAML file notation in YAML and XML was introduced
in Symfony 4.3.

You can automatically parse a YAML file and injecting it as an argument by referencing the **absolute path** to the file,
or the relative path from **your configuration file**:

.. configuration-block::

.. code-block:: yaml

# config/services.yaml
services:
# ...

App\ServiceWithArrayConfigFromYamlFile:
arguments:
- !yaml_file '%kernel.root_dir%/some/file.yaml'

.. code-block:: xml

<!-- config/services.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services
https://symfony.com/schema/dic/services/services-1.0.xsd">

<services>
<!-- ... -->

<service id="my_service" class="App\ServiceWithArrayConfigFromYamlFile">
<argument type="yaml-file">%kernel.root_dir%/some/file.yaml</argument>
</service>
</services>
</container>

You need the :doc:`YAML component </components/yaml>` to use this feature.

Learn more
----------

Expand Down