Symfony: Symfony service override (skipping compiler)

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

I looked at http://symfony.com/doc/current/cookbook/bundles/override.html and http://symfony.com/doc/current/cookbook/service_container/compiler_passes.html but cannot make it work.

I made a file in my package 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');
    $definition->setClass('MyApp\CoreBundle\Overrides\UrlPackage');
}

Strange if I call $this->has('assets.url_package')in any controller, it returns false. I grabbed it from a services file in 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" />
    </service>

If I run php app/console debug:container, UrlPackage from symfony does not exist, but if I change something inside the vendor / * / UrlPackge file, it works

- ?

+4
1

- , :

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

, .

http://symfony.com/doc/2.7/service_container/service_decoration.html

+4

Source: https://habr.com/ru/post/1598652/


All Articles