<?php
namespace Support\Services;
use Symfony\Component\HttpKernel\CacheWarmer\WarmableInterface;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Routing\RequestContext;
use Symfony\Component\Routing\RouterInterface;
// class FcsRouter extends Router
class NgRouter implements RouterInterface, WarmableInterface
{
protected $impersonation;
/**
* @var RouterInterface
*/
private $router;
/**
* MyRouter constructor.
* @param RouterInterface $router
*/
public function __construct(RouterInterface $router)
{
$this->router = $router;
}
/**
* {@inheritdoc}
*/
public function generate($name, $parameters = array(), $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH)
{
$url = $this->router->generate(...func_get_args());
if (!$this->impersonation) {
return $url;
}
/*
* This forces the impersonation if set on ALL urls. allows multiple impersonation
* with the same browser.
*/
$parsed = parse_url($url);
$join = empty($parsed['query']) ? '?' : '&';
return $url.$join.'impersonating='.$this->impersonation;
}
/**
* @inheritdoc
*/
public function setContext(RequestContext $context)
{
$this->router->setContext($context);
}
/**
* @inheritdoc
*/
public function getContext()
{
return $this->router->getContext();
}
/**
* @inheritdoc
*/
public function getRouteCollection()
{
return $this->router->getRouteCollection();
}
/**
* @inheritdoc
*/
public function match($pathinfo)
{
return $this->router->match($pathinfo);
}
public function setCurrentImpersonate($id)
{
$this->impersonation = $id;
}
/**
* @inheritDoc
*/
public function warmUp(string $cacheDir)
{
}
}