I want to decorate the Symfony UrlGenerator
class.
Symfony\\Component\\Routing\\Generator\\UrlGenerator: ~
my.url_generator:
class: AppBund
The right answer is : you shouldn't decorate UrlGeneratorInterface. You have to decorate 'router' service. Check here : https://github.com/symfony/symfony/issues/28663
** services.yml :
services:
App\Services\MyRouter:
decorates: 'router'
arguments: ['@App\Services\MyRouter.inner']
** MyRouter.php :
router = $router;
}
/**
* @inheritdoc
*/
public function generate($name, $parameters = [], $referenceType = self::ABSOLUTE_PATH)
{
// Your code here
return $this->router->generate($name, $parameters, $referenceType);
}
/**
* @inheritdoc
*/
public function setContext(RequestContext $context)
{
$this->router->setContext($context);
}
/**
* @inheritdoc
*/
public function getContext()
{
return $this->router->getContext();
}
/**
* @inheritdoc
*/
public function getRouteCollection()
{
return $this->router->getRouteCollection();
}
/**
* @inheritdoc
*/
public function match($pathinfo)
{
return $this->router->match($pathinfo);
}
}