Quantcast
Channel: Active questions tagged symfony4 - Stack Overflow
Viewing all articles
Browse latest Browse all 3918

Mixing positional and keyed arguments in service definition, using YAML

$
0
0

When configuring a service using XML, we can do the following:

<service id="foobar" class="App\Foobar" public="false" abstract="true"><argument type="service" id="doctrine" /><argument>null</argument><argument type="service" id="logger" on-invalid="ignore" /><argument key="$bombastic" type="service"            id="bombastic.service" on-invalid="ignore" /></service>

The first three arguments are positional (the first three arguments in the constructor), and the last one is keyed to the parameter name. Since the actual service has 5 arguments, the fourth argument is left undefined so it can be defined by a service that extends the foobar service.

Which is very nice.

In YAML the documentation shows how to use keyed arguments like this:

App\Updates\SiteUpdateManager:        arguments:            $someService: '@manager'

and positional arguments like this:

App\Updates\SiteUpdateManager:        arguments:            - '@manager'

But I'd like to do the same as the above XML configuration, but using YAML (because all the service configuration for this application is already in YAML, and I would not want to add a single XML configuration file just for this service).

How can I combine the two styles with YAML configuration?


Viewing all articles
Browse latest Browse all 3918

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>