• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

CPS-IT / handlebars / 36408884534

28 Sep 2026 10:17AM UTC coverage: 88.68% (+0.9%) from 87.788%
36408884534

Pull #647

github

web-flow
Merge f09550a78 into b68c1a4c8
Pull Request #647: [FEATURE] Introduce `image` media processor

35 of 38 new or added lines in 3 files covered. (92.11%)

1653 of 1864 relevant lines covered (88.68%)

7.07 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.43
/Classes/DataProcessing/Media/ImageProcessor.php
1
<?php
2

3
declare(strict_types=1);
4

5
/*
6
 * This file is part of the TYPO3 CMS extension "handlebars".
7
 *
8
 * It is free software; you can redistribute it and/or modify it under
9
 * the terms of the GNU General Public License, either version 2
10
 * of the License, or any later version.
11
 *
12
 * For the full copyright and license information, please read the
13
 * LICENSE.txt file that was distributed with this source code.
14
 *
15
 * The TYPO3 project - inspiring people to share!
16
 */
17

18
namespace CPSIT\Typo3Handlebars\DataProcessing\Media;
19

20
use Symfony\Component\DependencyInjection;
21
use TYPO3\CMS\Core;
22
use TYPO3\CMS\Extbase;
23
use TYPO3\CMS\Frontend;
24

25
/**
26
 * ImageProcessor
27
 *
28
 * @author Elias Häußler <e.haeussler@familie-redlich.de>
29
 * @license GPL-2.0-or-later
30
 * @internal
31
 *
32
 * @extends ConfigurableProcessor<Configuration\ImageConfiguration>
33
 *
34
 * @phpstan-type SourceSet array{src: string, width: int, height: int, extension: string, processedFile: Core\Resource\ProcessedFile|null}
35
 */
36
#[DependencyInjection\Attribute\AsTaggedItem('image')]
37
final class ImageProcessor extends ConfigurableProcessor
38
{
39
    use CanResolveOriginalFile;
40

41
    /**
42
     * @return array{
43
     *     sourceSets: array<string, SourceSet>,
44
     *     originalFile: Core\Resource\AbstractFile,
45
     * }
46
     */
47
    public function processFile(
4 ✔
48
        Frontend\ContentObject\ContentObjectRenderer $contentObjectRenderer,
49
        Core\Resource\ResourceInterface|Extbase\Domain\Model\File|Extbase\Domain\Model\FileReference $resource,
50
        Configuration\Configuration $configuration,
51
    ): array {
52
        /** @var Core\Resource\AbstractFile $file */
53
        $file = $this->resolveOriginalFile($resource);
4 ✔
54

55
        return [
4 ✔
56
            'sourceSets' => $this->processSourceSets($contentObjectRenderer, $resource, $configuration->sourceSets),
4 ✔
57
            'originalFile' => $file,
4 ✔
58
        ];
4 ✔
59
    }
60

61
    /**
62
     * @param array<string, array<string, string|int>> $sourceSets
63
     * @return array<string, SourceSet>
64
     */
65
    private function processSourceSets(
4 ✔
66
        Frontend\ContentObject\ContentObjectRenderer $contentObjectRenderer,
67
        Core\Resource\ResourceInterface|Extbase\Domain\Model\File|Extbase\Domain\Model\FileReference $resource,
68
        array $sourceSets,
69
    ): array {
70
        // Pull original resources from extbase models
71
        if ($resource instanceof Extbase\Domain\Model\FileReference || $resource instanceof Extbase\Domain\Model\File) {
4 ✔
72
            $resource = $resource->getOriginalResource();
1 ✔
73
        }
74

75
        // Early return on invalid resource
76
        if (!($resource instanceof Core\Resource\File) && !($resource instanceof Core\Resource\FileReference)) {
4 ✔
NEW
77
            return [];
×
78
        }
79

80
        $processedSourceSets = [];
4 ✔
81

82
        foreach ($sourceSets as $name => $sourceSet) {
4 ✔
83
            $processedSourceSet = $contentObjectRenderer->getImgResource($resource, $sourceSet);
2 ✔
84
            $publicUrl = $processedSourceSet?->getPublicUrl();
2 ✔
85

86
            if ($publicUrl !== null) {
2 ✔
87
                $processedSourceSets[$name] = [
2 ✔
88
                    'src' => $publicUrl,
2 ✔
89
                    'width' => $processedSourceSet->getWidth(),
2 ✔
90
                    'height' => $processedSourceSet->getHeight(),
2 ✔
91
                    'extension' => $processedSourceSet->getExtension(),
2 ✔
92
                    'processedFile' => $processedSourceSet->getProcessedFile(),
2 ✔
93
                ];
2 ✔
94
            }
95
        }
96

97
        return $processedSourceSets;
4 ✔
98
    }
99

100
    /**
101
     * @phpstan-assert-if-true !null $this->resolveOriginalFile()
102
     */
103
    public function supports(mixed $resource): bool
6 ✔
104
    {
105
        return $this->resolveOriginalFile($resource)?->isImage() ?? false;
6 ✔
106
    }
107

108
    protected function getConfigurationClass(): string
4 ✔
109
    {
110
        return Configuration\ImageConfiguration::class;
4 ✔
111
    }
112
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc