src/Support/Services/NgRouter.php line 76

Open in your IDE?
  1. <?php
  2. namespace Support\Services;
  3. use Symfony\Component\HttpKernel\CacheWarmer\WarmableInterface;
  4. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  5. use Symfony\Component\Routing\RequestContext;
  6. use Symfony\Component\Routing\RouterInterface;
  7. // class FcsRouter extends Router
  8. class NgRouter implements RouterInterfaceWarmableInterface
  9. {
  10.     protected $impersonation;
  11.     /**
  12.      * @var RouterInterface
  13.      */
  14.     private $router;
  15.     /**
  16.      * MyRouter constructor.
  17.      * @param RouterInterface $router
  18.      */
  19.     public function __construct(RouterInterface $router)
  20.     {
  21.         $this->router $router;
  22.     }
  23.     /**
  24.      * {@inheritdoc}
  25.      */
  26.     public function generate($name$parameters = array(), $referenceType UrlGeneratorInterface::ABSOLUTE_PATH)
  27.     {
  28.         $url $this->router->generate(...func_get_args());
  29.         if (!$this->impersonation) {
  30.             return $url;
  31.         }
  32.         /*
  33.          *  This forces the impersonation if set on ALL urls. allows multiple impersonation
  34.          *  with the same browser.
  35.          */
  36.         $parsed parse_url($url);
  37.         $join = empty($parsed['query']) ? '?' '&';
  38.         return $url.$join.'impersonating='.$this->impersonation;
  39.     }
  40.     /**
  41.      * @inheritdoc
  42.      */
  43.     public function setContext(RequestContext $context)
  44.     {
  45.         $this->router->setContext($context);
  46.     }
  47.     /**
  48.      * @inheritdoc
  49.      */
  50.     public function getContext()
  51.     {
  52.         return $this->router->getContext();
  53.     }
  54.     /**
  55.      * @inheritdoc
  56.      */
  57.     public function getRouteCollection()
  58.     {
  59.         return $this->router->getRouteCollection();
  60.     }
  61.     /**
  62.      * @inheritdoc
  63.      */
  64.     public function match($pathinfo)
  65.     {
  66.         return $this->router->match($pathinfo);
  67.     }
  68.     public function setCurrentImpersonate($id)
  69.     {
  70.         $this->impersonation $id;
  71.     }
  72.     /** 
  73.      * @inheritDoc
  74.      */
  75.     public function warmUp(string $cacheDir)
  76.     {
  77.     }
  78. }