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

FluidTYPO3 / vhs / 13011218278

28 Jan 2025 01:12PM UTC coverage: 71.914%. Remained the same
13011218278

push

github

NamelessCoder
[TASK] Introduce a proxy for ResourceFactory

1 of 3 new or added lines in 3 files covered. (33.33%)

1 existing line in 1 file now uncovered.

5628 of 7826 relevant lines covered (71.91%)

17.2 hits per line

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

72.41
/Classes/ViewHelpers/Media/Image/AbstractImageInfoViewHelper.php
1
<?php
2
namespace FluidTYPO3\Vhs\ViewHelpers\Media\Image;
3

4
/*
5
 * This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
6
 *
7
 * For the full copyright and license information, please read the
8
 * LICENSE.md file that was distributed with this source code.
9
 */
10

11
use FluidTYPO3\Vhs\Proxy\ResourceFactoryProxy;
12
use FluidTYPO3\Vhs\Utility\ResourceUtility;
13
use TYPO3\CMS\Core\Resource\FileReference as CoreFileReference;
14
use TYPO3\CMS\Core\Utility\GeneralUtility;
15
use TYPO3\CMS\Extbase\Domain\Model\FileReference as ExtbaseFileReference;
16
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
17
use TYPO3Fluid\Fluid\Core\ViewHelper\Exception;
18

19
/**
20
 * Base class: Media\Image view helpers.
21
 */
22
abstract class AbstractImageInfoViewHelper extends AbstractViewHelper
23
{
24
    /**
25
     * @var ResourceFactoryProxy
26
     */
27
    protected $resourceFactory;
28

29
    /**
30
     * @var boolean
31
     */
32
    protected $escapeOutput = false;
33

34
    /**
35
     * Construct resource factory
36
     */
37
    public function __construct()
38
    {
39
        /** @var ResourceFactoryProxy $resourceFactory */
NEW
40
        $resourceFactory = GeneralUtility::makeInstance(ResourceFactoryProxy::class);
×
UNCOV
41
        $this->resourceFactory = $resourceFactory;
×
42
    }
43

44
    public function initializeArguments(): void
45
    {
46
        $this->registerArgument(
18✔
47
            'src',
18✔
48
            'mixed',
18✔
49
            'Path to or id of the image file to determine info for. In case a FileReference is supplied, ' .
18✔
50
            'treatIdAsUid and treatIdAsReference will automatically be activated.',
18✔
51
            true
18✔
52
        );
18✔
53
        $this->registerArgument(
18✔
54
            'treatIdAsUid',
18✔
55
            'boolean',
18✔
56
            'If TRUE, the path argument is treated as a resource uid.'
18✔
57
        );
18✔
58
        $this->registerArgument(
18✔
59
            'treatIdAsReference',
18✔
60
            'boolean',
18✔
61
            'If TRUE, the path argument is treated as a reference uid and will be resolved to a resource via ' .
18✔
62
            'sys_file_reference.',
18✔
63
            false,
18✔
64
            false
18✔
65
        );
18✔
66
    }
67

68
    public function getInfo(): array
69
    {
70
        /** @var string|int|CoreFileReference|ExtbaseFileReference|null $src */
71
        $src = $this->arguments['src'];
72✔
72
        $treatIdAsUid = (boolean) $this->arguments['treatIdAsUid'];
72✔
73
        $treatIdAsReference = (boolean) $this->arguments['treatIdAsReference'];
72✔
74

75
        if (null === $src) {
72✔
76
            /** @var string|int|CoreFileReference|ExtbaseFileReference|null $src */
77
            $src = $this->renderChildren();
72✔
78
            if (null === $src) {
72✔
79
                return [];
18✔
80
            }
81
        }
82

83
        if ($src instanceof CoreFileReference || $src instanceof ExtbaseFileReference) {
54✔
84
            $src = $src->getUid();
×
85
            $treatIdAsUid = false;
×
86
            $treatIdAsReference = true;
×
87
        }
88

89
        if ($treatIdAsUid || $treatIdAsReference) {
54✔
90
            $id = (integer) $src;
×
91
            $info = [];
×
92
            if ($treatIdAsUid) {
×
93
                $info = $this->getInfoByUid($id);
×
94
            } elseif ($treatIdAsReference) {
×
95
                $info = $this->getInfoByReference($id);
×
96
            }
97
        } else {
98
            $file = GeneralUtility::getFileAbsFileName((string) $src);
54✔
99
            if (!file_exists($file) || is_dir($file)) {
54✔
100
                throw new Exception(
36✔
101
                    'Cannot determine info for "' . $file . '". File does not exist or is a directory.',
36✔
102
                    1357066532
36✔
103
                );
36✔
104
            }
105
            $imageSize = getimagesize($file);
18✔
106
            $info = [
18✔
107
                'width'  => $imageSize[0] ?? '',
18✔
108
                'height' => $imageSize[1] ?? '',
18✔
109
                'type'   => $imageSize['mime'] ?? '',
18✔
110
            ];
18✔
111
        }
112

113
        return $info;
18✔
114
    }
115

116
    public function getInfoByReference(int $id): array
117
    {
118
        $fileReference = $this->resourceFactory->getFileReferenceObject($id);
×
119
        $file = $fileReference->getOriginalFile();
×
120
        return ResourceUtility::getFileArray($file);
×
121
    }
122

123
    public function getInfoByUid(int $uid): array
124
    {
125
        $file = $this->resourceFactory->getFileObject($uid);
×
126
        return ResourceUtility::getFileArray($file);
×
127
    }
128
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc