Skip to content

Commit

Permalink
[TASK] Also pass 404 requests implementation should catch them
Browse files Browse the repository at this point in the history
  • Loading branch information
gertvdb committed Oct 23, 2020
1 parent 2eaa3fc commit 047e855
Showing 1 changed file with 13 additions and 20 deletions.
33 changes: 13 additions & 20 deletions EventListener/RouterListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Tactics\LegacyBridgeBundle\EventListener;

use Exception;
use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\FinishRequestEvent;
Expand Down Expand Up @@ -35,26 +36,24 @@ class RouterListener implements EventSubscriberInterface
*/
protected $logger;


/**
* @param SymfonyRouterListener $routerListener
* @param LegacyKernelInterface $legacyKernel
* @param LoggerInterface $logger
* @param LegacyKernelInterface|null $legacyKernel
* @param LoggerInterface|null $logger
*/
public function __construct(SymfonyRouterListener $routerListener, LegacyKernelInterface $legacyKernel=null, LoggerInterface $logger=null)
public function __construct(SymfonyRouterListener $routerListener, LegacyKernelInterface $legacyKernel=NULL, LoggerInterface $logger=NULL)
{
$this->legacyKernel = $legacyKernel;
$this->routerListener = $routerListener;
$this->logger = $logger;

}//end __construct()


/**
* @param \Symfony\Component\HttpKernel\Event\RequestEvent $event
* @param RequestEvent $event
*
* @return \Symfony\Component\HttpKernel\Event\RequestEvent
* @throws \Exception
* @return RequestEvent
* @throws Exception
*/
public function onKernelRequest(RequestEvent $event)
{
Expand All @@ -63,31 +62,27 @@ public function onKernelRequest(RequestEvent $event)
$this->routerListener->onKernelRequest($event);
} catch (NotFoundHttpException $e) {
// Optionally we log the request that go through the legacy controller.
if ($this->logger !== null) {
if ($this->logger !== NULL) {
$message = 'Request handled by the '.$this->legacyKernel->getName().' kernel.';
$this->logger->info($message);
}

if ($this->legacyKernel !== null) {

if ($this->legacyKernel !== NULL) {
// When the request could not be dispatched through symfony 5
// we fallback to our legacy kernel to dispatch the request.
$response = $this->legacyKernel->handle(
$event->getRequest(),
$event->getRequestType(),
true
TRUE
);

if ($response->getStatusCode() !== 404) {
$event->setResponse($response);
return $event;
}
$event->setResponse($response);
return $event;
}
}
}//end try

}//end onKernelRequest()


/**
* @param FinishRequestEvent $event
*/
Expand All @@ -97,7 +92,6 @@ public function onKernelFinishRequest(FinishRequestEvent $event)

}//end onKernelFinishRequest()


/**
* @{inheritdoc}
*/
Expand Down Expand Up @@ -125,5 +119,4 @@ public static function getSubscribedEvents()

}//end getSubscribedEvents()


}//end class

0 comments on commit 047e855

Please sign in to comment.