Mazzy Mazzy - 1 year ago 280
PHP Question

Symfony: Overriding Symfony service ( compiler pass )

I'm on symfony 2.7 and need to override Symfony\Component\Asset\UrlPackage

I've looked at
but can't get it working.

I have made a file in my bundle MyApp\CoreBundle\Overrides\UrlPackage;
I registered UrlPackage as a service and added a function:

public function process(ContainerBuilder $container)
$definition = $container->getDefinition('assets.url_package');

The weird thing is, if I call
in any controller, it returns false.
I did grab it from the services file under Symfony:

<service id="assets.url_package" class="Symfony\Component\Asset\UrlPackage" abstract="true">
<argument /> <!-- base URLs -->
<argument type="service" /> <!-- version strategy -->
<argument type="service" id="assets.context" />

If I run
php app/console debug:container
, the UrlPackage from symfony isn't in there, but, if I change something inside the vendor/*/UrlPackge file, it does work

Can someone point me in the right direction?

Answer Source

Decorating the service is the thing you're looking for:

    public: false
    class: stdClass
    decorates: foo
    arguments: ["@bar.inner"]

You can inject the original service in your own service, and implement the original interface to make them compatible.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download