eZ\Publish\Core\FieldType\Image\IO\Legacy::loadBinaryFile PHP Method

loadBinaryFile() public method

public loadBinaryFile ( $binaryFileId )
    public function loadBinaryFile($binaryFileId)
    {
        // If the id is an internal (absolute) path to a draft image, use the draft service to get external path & load
        if ($this->isDraftImagePath($binaryFileId)) {
            return $this->draftIOService->loadBinaryFile($this->draftIOService->getExternalPath($binaryFileId));
        }
        // If the id is an internal path (absolute) to a published image, replace with the internal path
        if ($this->isPublishedImagePath($binaryFileId)) {
            $binaryFileId = $this->publishedIOService->getExternalPath($binaryFileId);
        }
        return $this->publishedIOService->loadBinaryFile($binaryFileId);
    }

Usage Example

 /**
  * Load from internal published binary file path
  */
 public function testLoadBinaryFilePublishedInternalPath()
 {
     $internalId = 'var/test/storage/images/path/file.jpg';
     $id = 'path/file.jpg';
     $binaryFile = new BinaryFile(array('id' => $id));
     $this->publishedIoServiceMock->expects($this->once())->method('getExternalPath')->with($internalId)->will($this->returnValue($id));
     $this->publishedIoServiceMock->expects($this->once())->method('loadBinaryFile')->with($id)->will($this->returnValue($binaryFile));
     $this->draftIoServiceMock->expects($this->never())->method('loadBinaryFile');
     self::assertSame($binaryFile, $this->service->loadBinaryFile($internalId));
 }