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

FluidTYPO3 / vhs / 28371118611

29 Jun 2026 12:11PM UTC coverage: 69.786%. Remained the same
28371118611

push

github

NamelessCoder
[TASK] Get rid of LF constant usage

9 of 15 new or added lines in 10 files covered. (60.0%)

4795 of 6871 relevant lines covered (69.79%)

4.03 hits per line

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

51.55
/Classes/ViewHelpers/Media/VideoViewHelper.php
1
<?php
2
namespace FluidTYPO3\Vhs\ViewHelpers\Media;
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\Traits\TagViewHelperTrait;
12
use FluidTYPO3\Vhs\Utility\CoreUtility;
13
use TYPO3\CMS\Core\Utility\GeneralUtility;
14
use TYPO3Fluid\Fluid\Core\ViewHelper\Exception;
15

16
/**
17
 * Renders HTML code to embed a HTML5 video player. NOTICE: This is
18
 * all HTML5 and won't work on browsers like IE8 and below. Include
19
 * some helper library like videojs.com if you need to suport those.
20
 * Source can be a single file, a CSV of files or an array of arrays
21
 * with multiple sources for different video formats. In the latter
22
 * case provide array keys 'src' and 'type'. Providing an array of
23
 * sources (even for a single source) is preferred as you can set
24
 * the correct mime type of the video which is otherwise guessed
25
 * from the filename's extension.
26
 */
27
class VideoViewHelper extends AbstractMediaViewHelper
28
{
29
    use TagViewHelperTrait;
30

31
    /**
32
     * @var string
33
     */
34
    protected $tagName = 'video';
35

36
    protected array $validTypes = ['mp4', 'webm', 'ogg', 'ogv'];
37
    protected array $mimeTypesMap = [
38
        'mp4' => 'video/mp4',
39
        'webm' => 'video/webm',
40
        'ogg' => 'video/ogg',
41
        'ogv' => 'video/ogg'
42
    ];
43
    protected array $validPreloadModes = ['auto', 'metadata', 'none'];
44

45
    public function initializeArguments(): void
46
    {
47
        parent::initializeArguments();
2✔
48
        $this->registerUniversalTagAttributes();
2✔
49
        $this->registerArgument('width', 'integer', 'Sets the width of the video player in pixels.', true);
2✔
50
        $this->registerArgument('height', 'integer', 'Sets the height of the video player in pixels.', true);
2✔
51
        $this->registerArgument(
2✔
52
            'autoplay',
2✔
53
            'boolean',
2✔
54
            'Specifies that the video will start playing as soon as it is ready.',
2✔
55
            false,
2✔
56
            false
2✔
57
        );
2✔
58
        $this->registerArgument(
2✔
59
            'controls',
2✔
60
            'boolean',
2✔
61
            'Specifies that video controls should be displayed (such as a play/pause button etc).',
2✔
62
            false,
2✔
63
            false
2✔
64
        );
2✔
65
        $this->registerArgument(
2✔
66
            'loop',
2✔
67
            'boolean',
2✔
68
            'Specifies that the video will start over again, every time it is finished.',
2✔
69
            false,
2✔
70
            false
2✔
71
        );
2✔
72
        $this->registerArgument(
2✔
73
            'muted',
2✔
74
            'boolean',
2✔
75
            'Specifies that the audio output of the video should be muted.',
2✔
76
            false,
2✔
77
            false
2✔
78
        );
2✔
79
        $this->registerArgument(
2✔
80
            'poster',
2✔
81
            'string',
2✔
82
            'Specifies an image to be shown while the video is downloading, or until the user hits the play button.'
2✔
83
        );
2✔
84
        $this->registerArgument(
2✔
85
            'preload',
2✔
86
            'string',
2✔
87
            'Specifies if and how the author thinks the video should be loaded when the page loads. Can be ' .
2✔
88
            '"auto", "metadata" or "none".',
2✔
89
            false,
2✔
90
            'auto'
2✔
91
        );
2✔
92
        $this->registerArgument(
2✔
93
            'unsupported',
2✔
94
            'string',
2✔
95
            'Add a message for old browsers like Internet Explorer 9 without video support.'
2✔
96
        );
2✔
97
    }
98

99
    public function render(): string
100
    {
101
        $sources = static::getSourcesFromArgument($this->arguments);
×
102
        if (0 === count($sources)) {
×
103
            throw new Exception('No video sources provided.', 1359382189);
×
104
        }
105
        foreach ($sources as $source) {
×
106
            if (is_string($source)) {
×
107
                if (false !== strpos($source, '//')) {
×
108
                    $src = $source;
×
109
                    $type = mb_substr($source, mb_strrpos($source, '.') + 1);
×
110
                } else {
111
                    $src = mb_substr(
×
112
                        GeneralUtility::getFileAbsFileName($source),
×
113
                        mb_strlen(CoreUtility::getSitePath())
×
114
                    );
×
115
                    $type = pathinfo($src, PATHINFO_EXTENSION);
×
116
                }
117
            } elseif (is_array($source)) {
×
118
                if (!isset($source['src'])) {
×
119
                    throw new Exception('Missing value for "src" in sources array.', 1359381250);
×
120
                }
121
                $src = $source['src'];
×
122
                if (!isset($source['type'])) {
×
123
                    throw new Exception('Missing value for "type" in sources array.', 1359381255);
×
124
                }
125
                $type = $source['type'];
×
126
            } else {
127
                // skip invalid source
128
                continue;
×
129
            }
130
            if (!in_array(strtolower($type), $this->validTypes)) {
×
131
                    throw new Exception('Invalid video type "' . $type . '".', 1359381260);
×
132
            }
133
            $type = $this->mimeTypesMap[$type];
×
134
            $src = static::preprocessSourceUri($src, $this->arguments);
×
135
            $this->renderChildTag('source', ['src' => $src, 'type' => $type], false, 'append');
×
136
        }
137
        $tagAttributes = [
×
138
            'width'   => $this->arguments['width'],
×
139
            'height'  => $this->arguments['height'],
×
140
            'preload' => 'auto',
×
141
        ];
×
142
        if ($this->arguments['autoplay']) {
×
143
            $tagAttributes['autoplay'] = 'autoplay';
×
144
        }
145
        if ($this->arguments['controls']) {
×
146
            $tagAttributes['controls'] = 'controls';
×
147
        }
148
        if ($this->arguments['loop']) {
×
149
            $tagAttributes['loop'] = 'loop';
×
150
        }
151
        if ($this->arguments['muted']) {
×
152
            $tagAttributes['muted'] = 'muted';
×
153
        }
154
        if (in_array($this->arguments['preload'], $this->validPreloadModes)) {
×
155
            $tagAttributes['preload'] = $this->arguments['preload'];
×
156
        }
157
        if (null !== $this->arguments['poster']) {
×
158
            $tagAttributes['poster'] = $this->arguments['poster'];
×
159
        }
160
        $this->tag->addAttributes($tagAttributes);
×
161
        if (null !== $this->arguments['unsupported']) {
×
NEW
162
            $this->tag->setContent($this->tag->getContent() . PHP_EOL . $this->arguments['unsupported']);
×
163
        }
164
        return $this->tag->render();
×
165
    }
166
}
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