src/Features/MyUrlGenerator.php line 57

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.      * @param UriSigner $uriSigner
  19.      */
  20.     public function __construct(RouterInterface $router, private UriSigner $uriSigner)
  21.     {
  22.         $this->router $router;
  23.     }
  24.     /**
  25.      * @inheritdoc
  26.      */
  27.     public function setContext(RequestContext $context)
  28.     {
  29.         $this->router->setContext($context);
  30.     }
  31.     /**
  32.      * @inheritdoc
  33.      */
  34.     public function getRouteCollection(): RouteCollection
  35.     {
  36.         return $this->router->getRouteCollection();
  37.     }
  38.     public function generate(string $name, array $parameters = [], int $referenceType self::ABSOLUTE_PATH): string
  39.     {
  40.         $signRoute= ["file-read""file-download"];
  41.         if (in_array($name$signRoutetrue)) {
  42.             return $this->uriSigner->sign($this->router->generate($name$parametersUrlGeneratorInterface::ABSOLUTE_URL));
  43.         }
  44.         return $this->router->generate($name$parameters$referenceType);
  45.     }
  46.     public function match(string $pathinfo): array
  47.     {
  48.         return $this->router->match($pathinfo);
  49.     }
  50.     public function getContext(): RequestContext
  51.     {
  52.         return $this->router->getContext();
  53.     }
  54.     public function warmUp(string $cacheDir)
  55.     {
  56.         if ($this->router instanceof WarmableInterface) {
  57.             $this->router->warmUp($cacheDir);
  58.         }
  59.     }
  60. }