Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Override service definitions parameters by configuration

Tags:

symfony

I have noticed in several bundles that some services definition files had parameters embedded in it, like in the following example:

<?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 http://symfony.com/schema/dic/services/services-1.0.xsd">

    <parameters>
        <!-- CUSTOMER -->
        <parameter key="sonata.customer.admin.customer.class">Sonata\CustomerBundle\Admin\CustomerAdmin</parameter>
        <parameter key="sonata.customer.admin.customer.controller">SonataAdminBundle:CRUD</parameter>
    </parameters>

    <services>
        <service id="sonata.customer.admin.customer" class="%sonata.customer.admin.customer.class%">
            <tag name="sonata.admin" manager_type="orm" group="sonata_ecommerce" label="B2C" label_translator_strategy="sonata.admin.label.strategy.underscore"/>
            <argument />
            <argument>%sonata.customer.admin.customer.entity%</argument>
            <argument>%sonata.customer.admin.customer.controller%</argument>

            <call method="addChild">
                <argument type="service" id="sonata.customer.admin.address" />
            </call>

            <call method="addChild">
                <argument type="service" id="sonata.order.admin.order" />
            </call>
        </service>

    </services>

</container>

Those parameters are not exposed as bundle configuration.

I recently discovered it is possible to add a CompilerPass class to override some service definitions. Although, this looks a bit tedious to do.

Is it possible to override those <parameter> by configuration ?

like image 475
Didier Ghys Avatar asked Dec 02 '25 00:12

Didier Ghys


1 Answers

In your app/config/config.yml (or whatever imported config file) add :

parameters:
    parameter.name: new_value
like image 185
Yann Eugoné Avatar answered Dec 03 '25 14:12

Yann Eugoné



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!