I'm trying to override some service from "vendor" section. Following this guide https://symfony.com/doc/3.4/bundles/override.html I made this code
namespace AppBundle\DependencyInjection\Compiler;
use AppBundle\Service\Subscriber;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
class OverrideServiceCompilerPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
{
$definition = $container->getDefinition('MyOldService');
$definition->setClass(Subscriber::class); //my new service class
}
}
After I made a Subscriber class at "AppBundle\Service\Subscriber" and tried to override an action:
<?php
namespace AppBundle\Service;
class Subscriber
{
public function the_same_name_of_function_from_vendor()
{
dump('I am a new function!');die;
return new Response('ok');
}
}
But nothing happaned and symfony continues to call a function from "vendor" section.
How can I override the function correctly?