vendor/webbamboo/spinners-common/src/Services/RouteNormalization.php line 28

  1. <?php
  2. namespace Webbamboo\SpinnersCommon\Services;
  3. use Symfony\Bundle\FrameworkBundle\Routing\Router;
  4. use Symfony\Component\HttpKernel\Event\RequestEvent;
  5. use Symfony\Component\HttpFoundation\RedirectResponse;
  6. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  7. use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
  8. class RouteNormalization
  9. {
  10.     /**
  11.      * Holds Symfony2 router
  12.      *
  13.      *@var Router
  14.      */
  15.     protected $router;
  16.     /**
  17.      * @param Router
  18.      */
  19.     public function __construct(Router $router)
  20.     {
  21.         $this->router $router;
  22.     }
  23.     public function onKernelException(RequestEvent $event)
  24.     {
  25.         return;
  26.         dump($event->getRequest()->getRequestUri());
  27.         $originalRequest $event->getRequest()->getRequestUri();
  28.         $exception $event->getThrowable();
  29.         if ($exception instanceof NotFoundHttpException) {
  30.             /**
  31.              * Company
  32.             */
  33.             if(preg_match("/\/flyttst%C3%A4dning-(.*?)\/(.*?)/iU"$originalRequest$matches))
  34.             {
  35.                 dump(count($matches));
  36.                 if(count($matches) === 3)
  37.                 {
  38.                     $url $this->router->generate('spinner_front_company', [
  39.                         'citypermalink' => $matches[1],
  40.                         'companypermalink' => $matches[2]
  41.                     ]);
  42.                     $response = new RedirectResponse($url);
  43.                     $event->setResponse($response);    
  44.                 }
  45.                 else
  46.                 {
  47.                     return;
  48.                 }
  49.                 
  50.             }
  51.             else
  52.             {
  53.                 dump(preg_match("/\/flyttst%C3%A4dning-(.*?)\/(.*?)/iU"$originalRequest$matches), $matches);
  54.                 /** Choose your router here */
  55.                 $route 'route_name';
  56.     
  57.                 if ($route === $event->getRequest()->get('_route')) {
  58.                     return;
  59.                 }
  60.     
  61.                 $url $this->router->generate($route);
  62.                 $response = new RedirectResponse($url);
  63.                 $event->setResponse($response);
  64.             }
  65.             
  66.         }
  67.     }