<?php
namespace App\Features;
use Symfony\Component\HttpKernel\CacheWarmer\WarmableInterface;
use Symfony\Component\HttpKernel\UriSigner;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Routing\RequestContext;
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Routing\RouterInterface;
class MyUrlGenerator implements RouterInterface, WarmableInterface
{
/**
* @var RouterInterface
*/
private RouterInterface $router;
/**
* MyRouter constructor.
* @param RouterInterface $router
*/
public function __construct(RouterInterface $router, private UriSigner $uriSigner)
{
$this->router = $router;
}
/**
* @inheritdoc
*/
public function setContext(RequestContext $context)
{
$this->router->setContext($context);
}
/**
* @inheritdoc
*/
public function getRouteCollection(): RouteCollection
{
return $this->router->getRouteCollection();
}
public function generate(string $name, array $parameters = [], int $referenceType = self::ABSOLUTE_PATH): string
{
$signRoute= ["file-read", "file-download"];
if (in_array($name, $signRoute, true)) {
return $this->uriSigner->sign($this->router->generate($name, $parameters, UrlGeneratorInterface::ABSOLUTE_URL));
}
return $this->router->generate($name, $parameters, $referenceType);
}
public function match(string $pathinfo): array
{
return $this->router->match($pathinfo);
}
public function getContext(): RequestContext
{
return $this->router->getContext();
}
public function warmUp(string $cacheDir)
{
if ($this->router instanceof WarmableInterface) {
$this->router->warmUp($cacheDir);
}
}
}