You are here

public function SecurepagesSubscriber::checkRequestRedirection in Secure Pages 8

Event handler for request processing. Redirects as needed.

Parameters

\Symfony\Component\HttpKernel\Event\GetResponseEvent $event:

File

src/EventSubscriber/SecurepagesSubscriber.php, line 40
Contains \Drupal\securepages\EventSubscriber\SecurepagesSubscriber.

Class

SecurepagesSubscriber

Namespace

Drupal\securepages\EventSubscriber

Code

public function checkRequestRedirection(GetResponseEvent $event) {
  $config = $this->configFactory
    ->get('securepages.settings');
  if ($config
    ->get('enable') && php_sapi_name() != 'cli') {
    $redirect = Securepages::checkRedirect();
    if ($redirect !== NULL) {
      $request = $event
        ->getRequest();
      $route_match = RouteMatch::createFromRequest($request);
      $route_name = $route_match
        ->getRouteName();
      $route_parameters = $route_match
        ->getRawParameters()
        ->all();
      $qs = $request
        ->getQueryString();
      $url = Securepages::getUrl($route_name, $route_parameters, [], $redirect)
        ->toString() . ($qs ? '?' . $qs : '');
      $event
        ->setResponse(new TrustedRedirectResponse($url));
    }
  }
}