eZ\Bundle\EzPublishCoreBundle\Imagine\BinaryLoader::find PHP Метод

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

public find ( $path )
    public function find($path)
    {
        try {
            $binaryFile = $this->ioService->loadBinaryFile($path);
            // Treat a MissingBinaryFile as a not loadable file.
            if ($binaryFile instanceof MissingBinaryFile) {
                throw new NotLoadableException("Source image not found in {$path}");
            }
            $mimeType = $this->ioService->getMimeType($path);
            return new Binary($this->ioService->getFileContents($binaryFile), $mimeType, $this->extensionGuesser->guess($mimeType));
        } catch (NotFoundException $e) {
            throw new NotLoadableException("Source image not found in {$path}", 0, $e);
        }
    }

Usage Example

Пример #1
0
 public function testFind()
 {
     $path = 'something.jpg';
     $mimeType = 'foo/mime-type';
     $content = 'some content';
     $binaryFile = new BinaryFile(array('id' => $path, 'mimeType' => $mimeType));
     $this->ioService->expects($this->once())->method('loadBinaryFile')->with($path)->will($this->returnValue($binaryFile));
     $format = 'jpg';
     $this->extensionGuesser->expects($this->once())->method('guess')->with($mimeType)->will($this->returnValue($format));
     $this->ioService->expects($this->once())->method('getFileContents')->with($binaryFile)->will($this->returnValue($content));
     $expected = new Binary($content, $mimeType, $format);
     $this->assertEquals($expected, $this->binaryLoader->find($path));
 }