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

FluidTYPO3 / vhs / 30001290505

23 Jul 2026 10:57AM UTC coverage: 70.309% (-1.7%) from 72.022%
30001290505

push

github

NamelessCoder
[TER] 8.0.0

4819 of 6854 relevant lines covered (70.31%)

6.54 hits per line

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

88.89
/Classes/ViewHelpers/Variable/PregMatchViewHelper.php
1
<?php
2
namespace FluidTYPO3\Vhs\ViewHelpers\Variable;
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\Core\ViewHelper\AbstractViewHelper;
12
use FluidTYPO3\Vhs\Traits\TemplateVariableViewHelperTrait;
13
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
14

15
/**
16
 * ### PregMatch regular expression ViewHelper
17
 *
18
 * Implementation of `preg_match' for Fluid.
19
 */
20
class PregMatchViewHelper extends AbstractViewHelper
21
{
22
    use TemplateVariableViewHelperTrait;
23

24
    /**
25
     * @var boolean
26
     */
27
    protected $escapeChildren = false;
28

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

34
    public function initializeArguments(): void
35
    {
36
        $this->registerAsArgument();
3✔
37
        $this->registerArgument('pattern', 'mixed', 'Regex pattern to match against', true);
3✔
38
        $this->registerArgument('subject', 'mixed', 'String to match with the regex pattern');
3✔
39
        $this->registerArgument('global', 'boolean', 'Match global', false, false);
3✔
40
    }
41

42
    /**
43
     * @return mixed
44
     */
45
    public static function renderStatic(
46
        array $arguments,
47
        \Closure $renderChildrenClosure,
48
        RenderingContextInterface $renderingContext
49
    ) {
50
        if (!isset($arguments['subject']) && !isset($arguments['as'])) {
3✔
51
            $subject = (string) $renderChildrenClosure();
×
52
        } else {
53
            $subject = is_scalar($arguments['subject']) ? (string) $arguments['subject'] : '';
3✔
54
        }
55
        /** @var string $pattern */
56
        $pattern = $arguments['pattern'];
3✔
57
        if ($arguments['global']) {
3✔
58
            preg_match_all($pattern, $subject, $matches, PREG_SET_ORDER);
×
59
        } else {
60
            preg_match($pattern, $subject, $matches);
3✔
61
        }
62
        /** @var string|null $as */
63
        $as = $arguments['as'];
3✔
64
        return static::renderChildrenWithVariableOrReturnInputStatic(
3✔
65
            $matches,
3✔
66
            $as,
3✔
67
            $renderingContext,
3✔
68
            $renderChildrenClosure
3✔
69
        );
3✔
70
    }
71
}
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