Exponential 5.x Kernel 7.5.40 Exponential New Stack (Symfony-based) Kernel — PHP Class Reference

BinaryLoader.php
Go to the documentation of this file.
1 <?php
2
7 namespace eZ\Bundle\EzPublishCoreBundle\Imagine;
8
9 use Exception;
10 use eZ\Publish\Core\IO\Exception\InvalidBinaryFileIdException;
11 use eZ\Publish\Core\IO\IOServiceInterface;
12 use eZ\Publish\Core\IO\Values\MissingBinaryFile;
13 use Liip\ImagineBundle\Binary\Loader\LoaderInterface;
14 use Liip\ImagineBundle\Exception\Binary\Loader\NotLoadableException;
15 use Liip\ImagineBundle\Model\Binary;
16 use Symfony\Component\HttpFoundation\File\MimeType\ExtensionGuesserInterface;
17
22 class BinaryLoader implements LoaderInterface
23 {
25 private $ioService;
26
28 private $extensionGuesser;
29
30 public function __construct(IOServiceInterface $ioService, ExtensionGuesserInterface $extensionGuesser)
31 {
32 $this->ioService = $ioService;
33 $this->extensionGuesser = $extensionGuesser;
34 }
35
36 public function find($path)
37 {
38 try {
39 $binaryFile = $this->ioService->loadBinaryFile($path);
40 // Treat a MissingBinaryFile as a not loadable file.
41 if ($binaryFile instanceof MissingBinaryFile) {
42 throw new NotLoadableException("Source image not found in $path");
43 }
44
45 $mimeType = $this->ioService->getMimeType($path);
46
47 return new Binary(
48 $this->ioService->getFileContents($binaryFile),
49 $mimeType,
50 $this->extensionGuesser->guess($mimeType)
51 );
52 } catch (InvalidBinaryFileIdException $e) {
53 $message =
54 "Source image not found in $path. Repository images path are expected to be " .
55 'relative to the var/<site>/storage/images directory';
56
57 $suggestedPath = preg_replace('#var/[^/]+/storage/images/#', '', $path);
58 if ($suggestedPath !== $path) {
59 $message .= "\nSuggested value: '$suggestedPath'";
60 }
61
62 throw new NotLoadableException($message);
63 } catch (Exception $e) {
64 throw new NotLoadableException("Source image not found in $path", 0, $e);
65 }
66 }
67 }
eZ\Bundle\EzPublishCoreBundle\Imagine\BinaryLoader
Binary loader using eZ IOService.
Definition: BinaryLoader.php:23
eZ\Bundle\EzPublishCoreBundle\Imagine\BinaryLoader\$ioService
$ioService
Definition: BinaryLoader.php:25
eZ\Bundle\EzPublishCoreBundle\Imagine\BinaryLoader\find
find($path)
Definition: BinaryLoader.php:36
eZ\Bundle\EzPublishCoreBundle\Imagine\BinaryLoader\$extensionGuesser
$extensionGuesser
Definition: BinaryLoader.php:28
eZ\Bundle\EzPublishCoreBundle\Imagine\BinaryLoader\__construct
__construct(IOServiceInterface $ioService, ExtensionGuesserInterface $extensionGuesser)
Definition: BinaryLoader.php:30
eZ\Publish\Core\IO\Exception\InvalidBinaryFileIdException
Definition: InvalidBinaryFileIdException.php:12
eZ\Publish\Core\IO\Values\MissingBinaryFile
Override of BinaryFile that indicates a non existing file.
Definition: MissingBinaryFile.php:15
eZ\Publish\Core\IO\IOServiceInterface
Interface for Input/Output handling of binary files.
Definition: IOServiceInterface.php:16
eZ\Bundle\EzPublishCoreBundle\Imagine
Definition: AliasCleaner.php:7
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.