eZ\Bundle\EzPublishIOBundle\EventListener\StreamFileListener::onKernelRequest PHP Метод

onKernelRequest() публичный Метод

public onKernelRequest ( GetResponseEvent $event )
$event Symfony\Component\HttpKernel\Event\GetResponseEvent
    public function onKernelRequest(GetResponseEvent $event)
    {
        if ($event->getRequestType() !== HttpKernelInterface::MASTER_REQUEST) {
            return;
        }
        $uri = $event->getRequest()->attributes->get('semanticPathinfo');
        if (!$this->isIoUri($uri)) {
            return;
        }
        $binaryFile = $this->ioService->loadBinaryFileByUri($uri);
        if ($binaryFile instanceof MissingBinaryFile) {
            throw new NotFoundHttpException("Could not find 'BinaryFile' with identifier '{$uri}'");
        }
        $event->setResponse(new BinaryStreamResponse($binaryFile, $this->ioService));
    }

Usage Example

 public function testRespondsToIoUri()
 {
     $uri = '/var/test/storage/images/image.png';
     $request = $this->createRequest($uri);
     $event = $this->createEvent($request);
     $binaryFile = new BinaryFile(array('mtime' => new DateTime()));
     $this->ioServiceMock->expects($this->once())->method('loadBinaryFileByUri')->with($uri)->will($this->returnValue($binaryFile));
     $this->eventListener->onKernelRequest($event);
     self::assertTrue($event->hasResponse());
     self::assertEquals(new BinaryStreamResponse($binaryFile, $this->ioServiceMock), $event->getResponse());
 }