Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Fatal error: Maximum function nesting level of '256' reached, aborting! in /var/www/vendor/symfony/http-foundation/HeaderBag.php on line 162
- <?php
- namespace Drupalmy_moduleEventSubscriber;
- use SymfonyComponentEventDispatcherEventSubscriberInterface;
- use SymfonyComponentHttpFoundationRequest;
- use SymfonyComponentHttpKernelEventGetResponseEvent;
- use SymfonyComponentHttpKernelExceptionNotFoundHttpException;
- use SymfonyComponentHttpKernelKernelEvents;
- class MyClass implements EventSubscriberInterface {
- /**
- * {@inheritdoc}
- */
- static function getSubscribedEvents() {
- $events[KernelEvents::REQUEST][] = ['my404Check'];
- return $events;
- }
- public function my404Check(GetResponseEvent $event) {
- // Do some logic here to check if it should be a 404.
- throw new NotFoundHttpException();
- }
- }
- public function my404Check(GetResponseEvent $event) {
- // only return a response for a master request
- if (!$event->isMasterRequest()) {
- return;
- }
- // Do some logic here to check if it should be a 404.
- $response = new Response('', Response::HTTP_NOT_FOUND);
- $event->setResponse($response);
- }
- /**
- * {@inheritdoc}
- *
- * Use priority > 50 to run before core's ExceptionLoggingSubscriber.
- */
- public static function getSubscribedEvents() {
- $events[KernelEvents::EXCEPTION][] = ['onException', 60];
- return $events;
- }
- /**
- * Return a 404.
- *
- * @param GetResponseForExceptionEvent $event
- */
- public function onException(GetResponseForExceptionEvent $event) {
- $e = $event->getException();
- if ({{CUSTOM LOGIC HERE}}) {
- $new_exception = new NotFoundHttpException($e->getMessage());
- $event->setException($new_exception);
- }
- }
Add Comment
Please, Sign In to add comment