<?php
namespace FlexApp\Extensions;
use Symfony\Bundle\FrameworkBundle\Routing\Router;
use Symfony\Component\HttpKernel\CacheWarmer\WarmableInterface;
use Symfony\Component\Routing\RequestContext;
use Symfony\Component\Routing\RouterInterface;
use function Symfony\Component\String\u;
class RouterDecorator implements WarmableInterface, RouterInterface
{
/** @var RouterInterface|Router */
protected $innerRouter;
public function __construct(Router $router)
{
$this->innerRouter = $router;
}
/**
* @inheritDoc
*/
public function setContext(RequestContext $context)
{
$this->innerRouter->setContext($context);
}
/**
* @inheritDoc
*/
public function getContext()
{
return $this->innerRouter->getContext();
}
/**
* @inheritDoc
*/
public function getRouteCollection()
{
return $this->innerRouter->getRouteCollection();
}
/**
* @inheritDoc
*/
public function generate($name, $parameters = [], $referenceType = self::ABSOLUTE_PATH)
{
$url = $this->innerRouter->generate($name, $parameters, $referenceType);
/*
* Для страниц интервью не меняем регистр заглавных букв, т.к. портальные unid чувствительны к регистру,
* и приведение к нижнему регистру влечет за собой баги на страницах интервью
*/
if (u($url)->containsAny(['interview_link', 's_interview'])) {
return $url;
}
if (preg_match('/(.*)\?(.*)/', $url, $out)) {
$url = trim(mb_convert_case($out[1], MB_CASE_LOWER, 'UTF-8'));
$url = "{$url}?{$out[2]}";
} else {
$url = trim(mb_convert_case($url, MB_CASE_LOWER, 'UTF-8'));
}
return $url;
}
/**
* @inheritDoc
*/
public function match($pathinfo)
{
return $this->innerRouter->match($pathinfo);
}
public function warmUp($cacheDir)
{
$this->innerRouter->warmUp($cacheDir);
}
}