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

ImageFileLister.php
Go to the documentation of this file.
1 <?php
2
7 namespace eZ\Bundle\EzPublishIOBundle\Migration\FileLister;
8
9 use eZ\Bundle\EzPublishCoreBundle\Imagine\VariationPathGenerator;
10 use eZ\Bundle\EzPublishCoreBundle\Imagine\VariationPurger\ImageFileList;
11 use eZ\Bundle\EzPublishIOBundle\ApiLoader\HandlerFactory;
12 use eZ\Bundle\EzPublishIOBundle\Migration\FileListerInterface;
13 use eZ\Bundle\EzPublishIOBundle\Migration\MigrationHandler;
14 use eZ\Publish\Core\IO\Exception\BinaryFileNotFoundException;
15 use Iterator;
16 use Liip\ImagineBundle\Imagine\Filter\FilterConfiguration;
17 use LimitIterator;
18 use Psr\Log\LoggerInterface;
19
20 class ImageFileLister extends MigrationHandler implements FileListerInterface
21 {
23 private $imageFileList;
24
26 private $variationPathGenerator;
27
29 private $filterConfiguration;
30
32 private $imagesDir;
33
43 public function __construct(
44 HandlerFactory $metadataHandlerFactory,
45 HandlerFactory $binarydataHandlerFactory,
46 LoggerInterface $logger = null,
47 Iterator $imageFileList,
48 VariationPathGenerator $variationPathGenerator,
49 FilterConfiguration $filterConfiguration,
50 $imagesDir
51 ) {
52 $this->imageFileList = $imageFileList;
53 $this->variationPathGenerator = $variationPathGenerator;
54 $this->filterConfiguration = $filterConfiguration;
55 $this->imagesDir = $imagesDir;
56
57 $this->imageFileList->rewind();
58
59 parent::__construct($metadataHandlerFactory, $binarydataHandlerFactory, $logger);
60 }
61
62 public function countFiles()
63 {
64 return count($this->imageFileList);
65 }
66
67 public function loadMetadataList($limit = null, $offset = null)
68 {
69 $metadataList = [];
70 $imageLimitList = new LimitIterator($this->imageFileList, $offset, $limit);
71 $aliasNames = array_keys($this->filterConfiguration->all());
72
73 foreach ($imageLimitList as $originalImageId) {
74 try {
75 $metadataList[] = $this->fromMetadataHandler->load($this->imagesDir . '/' . $originalImageId);
76 } catch (BinaryFileNotFoundException $e) {
77 $this->logMissingFile($originalImageId);
78
79 continue;
80 }
81
82 foreach ($aliasNames as $aliasName) {
83 $variationImageId = $this->variationPathGenerator->getVariationPath($originalImageId, $aliasName);
84
85 try {
86 $metadataList[] = $this->fromMetadataHandler->load($this->imagesDir . '/' . $variationImageId);
87 } catch (BinaryFileNotFoundException $e) {
88 $this->logMissingFile($variationImageId);
89 }
90 }
91 }
92
93 return $metadataList;
94 }
95 }
eZ\Bundle\EzPublishIOBundle\ApiLoader\HandlerFactory
Factory of IO handlers, given an alias.
Definition: HandlerFactory.php:17
eZ\Bundle\EzPublishIOBundle\Migration\FileLister\ImageFileLister
Definition: ImageFileLister.php:21
eZ\Bundle\EzPublishIOBundle\Migration\FileLister\ImageFileLister\loadMetadataList
loadMetadataList($limit=null, $offset=null)
Loads and returns metadata for files, optionally limited by $limit and $offset.
Definition: ImageFileLister.php:67
eZ\Bundle\EzPublishIOBundle\Migration\FileLister\ImageFileLister\countFiles
countFiles()
Count the number of existing files.
Definition: ImageFileLister.php:62
eZ\Bundle\EzPublishIOBundle\Migration\FileLister\ImageFileLister\$imagesDir
$imagesDir
Definition: ImageFileLister.php:32
eZ\Bundle\EzPublishIOBundle\Migration\FileLister\ImageFileLister\$imageFileList
$imageFileList
Definition: ImageFileLister.php:23
eZ\Bundle\EzPublishIOBundle\Migration\FileLister\ImageFileLister\$filterConfiguration
$filterConfiguration
Definition: ImageFileLister.php:29
eZ\Bundle\EzPublishIOBundle\Migration\FileLister\ImageFileLister\__construct
__construct(HandlerFactory $metadataHandlerFactory, HandlerFactory $binarydataHandlerFactory, LoggerInterface $logger=null, Iterator $imageFileList, VariationPathGenerator $variationPathGenerator, FilterConfiguration $filterConfiguration, $imagesDir)
Definition: ImageFileLister.php:43
eZ\Bundle\EzPublishIOBundle\Migration\FileLister\ImageFileLister\$variationPathGenerator
$variationPathGenerator
Definition: ImageFileLister.php:26
eZ\Bundle\EzPublishIOBundle\Migration\MigrationHandler
The migration handler sets up from/to IO data handlers, and provides logging, for file migrators and ...
Definition: MigrationHandler.php:16
eZ\Bundle\EzPublishIOBundle\Migration\MigrationHandler\$binarydataHandlerFactory
$binarydataHandlerFactory
Definition: MigrationHandler.php:21
eZ\Bundle\EzPublishIOBundle\Migration\MigrationHandler\$metadataHandlerFactory
$metadataHandlerFactory
Definition: MigrationHandler.php:18
eZ\Bundle\EzPublishIOBundle\Migration\MigrationHandler\logMissingFile
logMissingFile($id)
Definition: MigrationHandler.php:76
eZ\Bundle\EzPublishIOBundle\Migration\MigrationHandler\$logger
$logger
Definition: MigrationHandler.php:24
eZ\Publish\Core\IO\Exception\BinaryFileNotFoundException
Definition: BinaryFileNotFoundException.php:13
eZ\Bundle\EzPublishCoreBundle\Imagine\VariationPathGenerator
Generates the path to variations of original images.
Definition: VariationPathGenerator.php:13
eZ\Bundle\EzPublishCoreBundle\Imagine\VariationPurger\ImageFileList
Iterates over BinaryFile id entries for original images.
Definition: ImageFileList.php:16
eZ\Bundle\EzPublishIOBundle\Migration\FileListerInterface
Definition: FileListerInterface.php:12
eZ\Bundle\EzPublishCoreBundle\Imagine\VariationPathGenerator
Definition: AliasDirectoryVariationPathGenerator.php:7
eZ\Bundle\EzPublishIOBundle\Migration\FileLister
Definition: BinaryFileLister.php:7
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.