<?php
namespace Customize\EventListener;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\KernelEvents;
class RouteBlockListener implements EventSubscriberInterface
{
public function onKernelRequest(RequestEvent $event)
{
$request = $event->getRequest();
$path = $request->getPathInfo();
$isOldPage = env('OLD_PAGE');
if($isOldPage) return;
$blockedRoutes = [
'/cart',
'/shopping',
'/shopping/confirm',
'/shopping/checkout',
'/products/list'
];
if (in_array($path, $blockedRoutes)) {
throw new NotFoundHttpException('Page not found');
}
if (preg_match('#^/products/detail/\d+$#', $path)) {
throw new NotFoundHttpException('Page not found');
}
if (preg_match('#\/mypage\/#', $path)) {
throw new NotFoundHttpException('Page not found');
}
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents()
{
return [
KernelEvents::REQUEST => [
['onKernelRequest', 20],
],
];
}
}