1

I want to custom the routing UrlGenerator

The following is my modification

File: vendor/symfony/framework-bundle/Resources/config/routing.xml
<argument key="generator_class">Symfony\Component\Routing\Generator\UrlGenerator</argument>
<argument key="generator_base_class">Symfony\Component\Routing\Generator\UrlGenerator</argument>

to

<argument key="generator_class">App\Routing\UrlGenerator</argument>
<argument key="generator_base_class">App\Routing\UrlGenerator</argument>

UrlGenerator class

<?php

namespace App\Routing;

class UrlGenerator extends \Symfony\Component\Routing\Generator\UrlGenerator
{

    protected function doGenerate($variables, $defaults, $requirements, $tokens, $parameters, $name, $referenceType, $hostTokens, array $requiredSchemes = [])
    {
        $url = parent::doGenerate($variables, $defaults, $requirements, $tokens, $parameters, $name, $referenceType, $hostTokens, $requiredSchemes);
        var_dump($url);
        die;
    }
}

Controller file

<?php

namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;

class DefaultController extends AbstractController
{

    /**
     * @Route("/test")
     */
    public function test()
    {
        $ret = $this->generateUrl('_profiler_exception_css', ['token' => 'test']);
        var_dump($ret);
        die;
    }
}

He seems to be works,But I think this is not the best way,Can you help me,How to configure,Not modifying the code inside composer

wuxueling
  • 81
  • 3
  • Sorry, i did not know it was deprecated. – Elanochecer Apr 02 '19 at 10:42
  • 1
    Possible duplicate of [Symfony 4.2 - How to decorate the UrlGenerator](https://stackoverflow.com/questions/55468435/symfony-4-2-how-to-decorate-the-urlgenerator) – Jakumi Apr 02 '19 at 12:59

0 Answers0