src/Zicht/Bundle/UrlBundle/Aliasing/Listener.php
public function onKernelRequest(Event\GetResponseEvent $event)
    {
        if ($event->getRequestType() === HttpKernelInterface::MASTER_REQUEST) {
            $request = $event->getRequest();
            $publicUrl = rawurldecode($request->getRequestUri());

            if ($this->isExcluded($publicUrl)) {
                // don't process urls which are marked as excluded.
                return;
            }

            if ($this->isParamsEnabled) {
                if (false !== ($queryMark = strpos($publicUrl, '?'))) {
                    $originalUrl = $publicUrl;
                    $publicUrl = substr($originalUrl, 0, $queryMark);
                    $queryString = substr($originalUrl, $queryMark);
                } else {
                    $queryString = null;
                }

                $parts = explode('/', $publicUrl);
                $params = [];
                while (false !== strpos(end($parts), '=')) {
                    array_push($params, array_pop($parts));
                }
                if ($params) {
                    $publicUrl = join('/', $parts);

                    $parser = new UriParser();
                    $request->query->add($parser->parseUri(join('/', array_reverse($params))));

                    if (!$this->aliasing->hasInternalAlias($publicUrl, false)) {
                        $this->rewriteRequest($event, $publicUrl . $queryString);

                        return;
                    }
                }
            }

            /** @var UrlAlias $url */
            if ($url = $this->aliasing->hasInternalAlias($publicUrl, true)) {
                switch ($url->getMode()) {
                    case UrlAlias::REWRITE:
                        $this->rewriteRequest($event, $url->getInternalUrl());
                        break;
                    case UrlAlias::MOVE:
                    case UrlAlias::ALIAS:
                        $event->setResponse(new RedirectResponse($url->getInternalUrl(), $url->getMode()));
                        break;
                    default:
                        throw new \UnexpectedValueException(
                            sprintf(
                                'Invalid mode %s for UrlAlias %s.',
                                $url->getMode(),
                                json_encode($url)
                            )
                        );
                }
            } elseif (strpos($publicUrl, '?') !== false) {
                // allow aliases to receive the query string.

                $publicUrl = substr($publicUrl, 0, strpos($publicUrl, '?'));
                if ($url = $this->aliasing->hasInternalAlias($publicUrl, true, UrlAlias::REWRITE)) {
                    $this->rewriteRequest($event, $url->getInternalUrl());

                    return;
                }
            }
        }
    }
public function onKernelRequest(Event\GetResponseEvent $event)
    {
        if ($event->getRequestType() === HttpKernelInterface::MASTER_REQUEST) {
            $request = $event->getRequest();
            $publicUrl = rawurldecode($request->getRequestUri());

            if ($this->isExcluded($publicUrl)) {
                // don't process urls which are marked as excluded.
                return;
            }

            if ($this->isParamsEnabled) {
                if (false !== ($queryMark = strpos($publicUrl, '?'))) {
                    $originalUrl = $publicUrl;
                    $publicUrl = substr($originalUrl, 0, $queryMark);
                    $queryString = substr($originalUrl, $queryMark);
                } else {
                    $queryString = null;
                }

                $parts = explode('/', $publicUrl);
                $params = [];
                while (false !== strpos(end($parts), '=')) {
                    array_push($params, array_pop($parts));
                }
                if ($params) {
                    $publicUrl = join('/', $parts);

                    $parser = new UriParser();
                    $request->query->add($parser->parseUri(join('/', array_reverse($params))));

                    if (!$this->aliasing->hasInternalAlias($publicUrl, false)) {
                        $this->rewriteRequest($event, $publicUrl . $queryString);

                        return;
                    }
                }
            }

            /** @var UrlAlias $url */
            if ($url = $this->aliasing->hasInternalAlias($publicUrl, true)) {
                switch ($url->getMode()) {
                    case UrlAlias::REWRITE:
                        $this->rewriteRequest($event, $url->getInternalUrl());
                        break;
                    case UrlAlias::MOVE:
                    case UrlAlias::ALIAS:
                        $event->setResponse(new RedirectResponse($url->getInternalUrl(), $url->getMode()));
                        break;
                    default:
                        throw new \UnexpectedValueException(
                            sprintf(
                                'Invalid mode %s for UrlAlias %s.',
                                $url->getMode(),
                                json_encode($url)
                            )
                        );
                }
            } elseif (strpos($publicUrl, '?') !== false) {
                // allow aliases to receive the query string.

                $publicUrl = substr($publicUrl, 0, strpos($publicUrl, '?'));
                if ($url = $this->aliasing->hasInternalAlias($publicUrl, true, UrlAlias::REWRITE)) {
                    $this->rewriteRequest($event, $url->getInternalUrl());

                    return;
                }
            }
        }
    }
public function onKernelRequest ( Event \ GetResponseEvent $ event ) { if ( $ event -> getRequestType ( ) === HttpKernelInterface :: MASTER_REQUEST ) { $ request = $ event -> getRequest ( ) ; $ publicUrl = rawurldecode ( $ request -> getRequestUri ( ) ) ; if ( $ this -> isExcluded ( $ publicUrl ) ) { // don't process urls which are marked as excluded. return ; } if ( $ this -> isParamsEnabled ) { if ( false !== ( $ queryMark = strpos ( $ publicUrl , '?' ) ) ) { $ originalUrl = $ publicUrl ; $ publicUrl = substr ( $ originalUrl , 0 , $ queryMark ) ; $ queryString = substr ( $ originalUrl , $ queryMark ) ; } else { $ queryString = null ; } $ parts = explode ( '/' , $ publicUrl ) ; $ params = [ ] ; while ( false !== strpos ( end ( $ parts ) , '=' ) ) { array_push ( $ params , array_pop ( $ parts ) ) ; } if ( $ params ) { $ publicUrl = join ( '/' , $ parts ) ; $ parser = new UriParser ( ) ; $ request -> query -> add ( $ parser -> parseUri ( join ( '/' , array_reverse ( $ params ) ) ) ) ; if ( ! $ this -> aliasing -> hasInternalAlias ( $ publicUrl , false ) ) { $ this -> rewriteRequest ( $ event , $ publicUrl . $ queryString ) ; return ; } } } /** @var UrlAlias $url */ if ( $ url = $ this -> aliasing -> hasInternalAlias ( $ publicUrl , true ) ) { switch ( $ url -> getMode ( ) ) { case UrlAlias :: REWRITE : $ this -> rewriteRequest ( $ event , $ url -> getInternalUrl ( ) ) ; break ; case UrlAlias :: MOVE : case UrlAlias :: ALIAS : $ event -> setResponse ( new RedirectResponse ( $ url -> getInternalUrl ( ) , $ url -> getMode ( ) ) ) ; break ; default : throw new \ UnexpectedValueException ( sprintf ( 'Invalid mode %s for UrlAlias %s.' , $ url -> getMode ( ) , json_encode ( $ url ) ) ) ; } } elseif ( strpos ( $ publicUrl , '?' ) !== false ) { // allow aliases to receive the query string. $ publicUrl = substr ( $ publicUrl , 0 , strpos ( $ publicUrl , '?' ) ) ; if ( $ url = $ this -> aliasing -> hasInternalAlias ( $ publicUrl , true , UrlAlias :: REWRITE ) ) { $ this -> rewriteRequest ( $ event , $ url -> getInternalUrl ( ) ) ; return ; } } } }
Listens to master requests and translates the URL to an internal url, if there is an alias available

@param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event
@return void
@throws \UnexpectedValueException
Listens to master requests and translates the URL to an internal url if there is an alias available