src/Modules/OnlineService/Service/OnlineServiceService.php line 42

  1. <?php
  2. namespace App\Modules\OnlineService\Service;
  3. use Symfony\Component\HttpFoundation\RequestStack;
  4. use Symfony\Component\Routing\RouterInterface;
  5. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  6. class OnlineServiceService
  7. {
  8.     private $_requestStack;
  9.     private $_router;
  10.     private $_iframeSessionKey 'online_service.is_iframe';
  11.     public function __construct(
  12.             RequestStack $requestStack,
  13.             RouterInterface $router)
  14.     {
  15.         $this->_requestStack $requestStack;
  16.         $this->_router $router;
  17.     }
  18.     
  19.     public function checkIframe()
  20.     {
  21.         $request $this->_requestStack->getMainRequest();
  22.         
  23.         if (!(bool)(int)$request->query->get('iframe'))
  24.             return;
  25.         
  26.         $data = array(
  27.             'parent_url' => $request->query->get('parentUrl')
  28.         );
  29.         
  30.         if ($data['parent_url'] == '')
  31.             throw new \Exception('Invalid parameters.');
  32.         
  33.         $request->getSession()->set($this->_iframeSessionKey$data);
  34.     }
  35.     
  36.     public function getIframeData()
  37.     {
  38.         return $this->_requestStack->getMainRequest()->getSession()->get($this->_iframeSessionKey);
  39.     }
  40.     
  41.     public function isIframe()
  42.     {
  43.         return $this->getIframeData() != null;
  44.     }
  45.     
  46.     public function getUrl($route, array $params = array(), $referenceType UrlGeneratorInterface::ABSOLUTE_PATH)
  47.     {
  48.         if ($this->isIframe())
  49.             $params['_sid'] = session_id();
  50.         return $this->_router->generate($route$params$referenceType);
  51.     }
  52. }