Gc\Mvc\Listener\SslListener::check PHP Method

check() public method

Check if ssl is forced or not
public check ( Zend\EventManager\EventInterface $event ) : null | Zend\Http\PhpEnvironment\Response
$event Zend\EventManager\EventInterface Mvc event
return null | Zend\Http\PhpEnvironment\Response
    public function check(EventInterface $event)
    {
        $coreConfig = $event->getApplication()->getServiceManager()->get('CoreConfig');
        $matchedRouteName = $event->getRouteMatch()->getMatchedRouteName();
        $request = $event->getRequest();
        $uri = $request->getUri();
        if ($matchedRouteName === 'cms') {
            if ($uri->getScheme() === 'https' or $coreConfig->getValue('force_frontend_ssl')) {
                $newUri = new Uri($coreConfig->getValue('secure_frontend_base_path'));
                $newUri->setScheme('https');
            } else {
                $newUri = new Uri($coreConfig->getValue('unsecure_frontend_base_path'));
            }
        } else {
            if ($uri->getScheme() === 'https' or $coreConfig->getValue('force_backend_ssl')) {
                $newUri = new Uri($coreConfig->getValue('secure_backend_base_path'));
                $newUri->setScheme('https');
            } else {
                $newUri = new Uri($coreConfig->getValue('unsecure_backend_base_path'));
            }
        }
        if (!empty($newUri) and $newUri->isValid() and ($newUri->getHost() != '' and $uri->getHost() != $newUri->getHost()) or $newUri->getScheme() != '' and $uri->getScheme() != $newUri->getScheme()) {
            $uri->setPort($newUri->getPort());
            if ($newUri->getHost() != '') {
                $uri->setHost($newUri->getHost());
            }
            if ($newUri->getScheme() != '') {
                $uri->setScheme($newUri->getScheme());
            }
            $response = $event->getResponse();
            $response->setStatusCode(302);
            $response->getHeaders()->addHeaderLine('Location', $request->getUri());
            $event->stopPropagation();
            return $response;
        }
    }
SslListener