Contao\CoreBundle\EventListener\AddToSearchIndexListener::onKernelTerminate PHP Method

onKernelTerminate() public method

Forwards the request to the Frontend class if there is a page object.
public onKernelTerminate ( Symfony\Component\HttpKernel\Event\PostResponseEvent $event )
$event Symfony\Component\HttpKernel\Event\PostResponseEvent
    public function onKernelTerminate(PostResponseEvent $event)
    {
        if (!$this->framework->isInitialized()) {
            return;
        }
        // Do not index fragments
        if (preg_match('~(?:^|/)' . preg_quote($this->fragmentPath, '~') . '/~', $event->getRequest()->getPathInfo())) {
            return;
        }
        /** @var Frontend $frontend */
        $frontend = $this->framework->getAdapter(Frontend::class);
        $frontend->indexPageIfApplicable($event->getResponse());
    }

Usage Example

 /**
  * Tests that the listener does nothing if the request is a fragment.
  */
 public function testWithFragment()
 {
     $this->framework->expects($this->any())->method('isInitialized')->willReturn(true);
     $listener = new AddToSearchIndexListener($this->framework);
     $event = $this->mockPostResponseEvent('_fragment/foo/bar');
     $event->expects($this->never())->method('getResponse');
     $listener->onKernelTerminate($event);
 }
AddToSearchIndexListener