src/Features/MyUrlGenerator.php line 56

Open in your IDE?
  1. <?php
  2. namespace App\Features;
  3. use Symfony\Component\HttpKernel\CacheWarmer\WarmableInterface;
  4. use Symfony\Component\HttpKernel\UriSigner;
  5. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  6. use Symfony\Component\Routing\RequestContext;
  7. use Symfony\Component\Routing\RouteCollection;
  8. use Symfony\Component\Routing\RouterInterface;
  9. class MyUrlGenerator implements RouterInterfaceWarmableInterface
  10. {
  11.     /**
  12.      * @var RouterInterface
  13.      */
  14.     private RouterInterface $router;
  15.     /**
  16.      * MyRouter constructor.
  17.      * @param RouterInterface $router
  18.      */
  19.     public function __construct(RouterInterface $router, private UriSigner $uriSigner)
  20.     {
  21.         $this->router $router;
  22.     }
  23.     /**
  24.      * @inheritdoc
  25.      */
  26.     public function setContext(RequestContext $context)
  27.     {
  28.         $this->router->setContext($context);
  29.     }
  30.     /**
  31.      * @inheritdoc
  32.      */
  33.     public function getRouteCollection(): RouteCollection
  34.     {
  35.         return $this->router->getRouteCollection();
  36.     }
  37.     public function generate(string $name, array $parameters = [], int $referenceType self::ABSOLUTE_PATH): string
  38.     {
  39.         $signRoute= ["file-read""file-download"];
  40.         if (in_array($name$signRoutetrue)) {
  41.             return $this->uriSigner->sign($this->router->generate($name$parametersUrlGeneratorInterface::ABSOLUTE_URL));
  42.         }
  43.         return $this->router->generate($name$parameters$referenceType);
  44.     }
  45.     public function match(string $pathinfo): array
  46.     {
  47.         return $this->router->match($pathinfo);
  48.     }
  49.     public function getContext(): RequestContext
  50.     {
  51.         return $this->router->getContext();
  52.     }
  53.     public function warmUp(string $cacheDir)
  54.     {
  55.         if ($this->router instanceof WarmableInterface) {
  56.             $this->router->warmUp($cacheDir);
  57.         }
  58.     }
  59. }