From 783610c7b8c7fa641e19bb2433f4deea59df1540 Mon Sep 17 00:00:00 2001 From: Antoine Lamirault Date: Sat, 29 Jul 2023 21:58:18 +0200 Subject: [PATCH] [DependencuInjection] Document abstract arguments --- service_container.rst | 66 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/service_container.rst b/service_container.rst index 5c33d16e069..a4abf4ce2f7 100644 --- a/service_container.rst +++ b/service_container.rst @@ -840,6 +840,72 @@ argument for *any* service defined in this file! You can bind arguments by name The ``bind`` config can also be applied to specific services or when loading many services at once (i.e. :ref:`service-psr4-loader`). +Abstract service arguments +-------------------------- + +Sometimes, when defining services in your Symfony applications, there are arguments +that can't be added in config files. The reason is that their values can only be +calculated at runtime in a :doc:`compiler pass ` +or :doc:`bundle extension `. + +If value is not replaced a ``RuntimeException`` would be thrown. + +.. configuration-block:: + + .. code-block:: yaml + + # config/services.yaml + services: + # ... + + App\Service\MyService: + arguments: + $rootNamespace: !abstract 'should be defined by Pass' + + # ... + + .. code-block:: xml + + + + + + + + should be defined by Pass + + + + + + + .. code-block:: php + + // config/services.php + namespace Symfony\Component\DependencyInjection\Loader\Configurator; + + use App\Service\MyService; + use Psr\Log\LoggerInterface; + use Symfony\Component\DependencyInjection\Definition; + use Symfony\Component\DependencyInjection\Reference; + + return function(ContainerConfigurator $container) { + $services = $container->services(); + + $services->set(MyService::class) + ->arg('$rootNamespace', abstract_arg('should be defined by Pass')) + ; + + // ... + }; + +In this case, if you don't replace the value, ``RuntimeException`` will be thrown +with message ``Argument "$rootNamespace" of service "App\Service\MyService" is +abstract: should be defined by Pass.`` + .. _services-autowire: The autowire Option pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy