• 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

55.56
/Classes/ViewHelpers/CallViewHelper.php
1
<?php
2
namespace FluidTYPO3\Vhs\ViewHelpers;
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 TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
13

14
/**
15
 * ### Call ViewHelper
16
 *
17
 * Calls a method on an existing object. Usable as inline or tag.
18
 *
19
 * ### Examples
20
 *
21
 * ```
22
 * <!-- inline, useful as argument, for example in f:for -->
23
 * {object -> v:call(method: 'toArray')}
24
 * <!-- tag, useful to quickly output simple values -->
25
 * <v:call object="{object}" method="unconventionalGetter" />
26
 * <v:call method="unconventionalGetter">{object}</v:call>
27
 * <!-- arguments for the method -->
28
 * <v:call object="{object}" method="doSomethingWithArguments" arguments="{0: 'foo', 1: 'bar'}" />
29
 * ```
30
 */
31
class CallViewHelper extends AbstractViewHelper
32
{
33
    /**
34
     * @var boolean
35
     */
36
    protected $escapeOutput = false;
37

38
    /**
39
     * @var boolean
40
     */
41
    protected $escapeChildren = false;
42

43
    public function initializeArguments(): void
44
    {
45
        $this->registerArgument('object', 'object', 'Instance to call method on');
3✔
46
        $this->registerArgument('method', 'string', 'Name of method to call on instance', true);
3✔
47
        $this->registerArgument('arguments', 'array', 'Array of arguments if method requires arguments', false, []);
3✔
48
    }
49

50
    /**
51
     * @return mixed
52
     */
53
    public static function renderStatic(
54
        array $arguments,
55
        \Closure $renderChildrenClosure,
56
        RenderingContextInterface $renderingContext
57
    ) {
58
        /** @var object $object */
59
        $object = $arguments['object'] ?? $renderChildrenClosure();
3✔
60
        /** @var string $method */
61
        $method = $arguments['method'];
3✔
62
        /** @var array $methodArguments */
63
        $methodArguments = $arguments['arguments'];
3✔
64
        if (!is_object($object)) {
3✔
65
            throw new \RuntimeException(
×
66
                'Using v:call requires an object either as "object" attribute, tag content or inline argument',
×
67
                1356849652
×
68
            );
×
69
        }
70
        if (!method_exists($object, $method)) {
3✔
71
            throw new \RuntimeException(
×
72
                'Method "' . $method . '" does not exist on object of type ' . get_class($object),
×
73
                1356834755
×
74
            );
×
75
        }
76
        /** @var callable $callable */
77
        $callable = [$object, $method];
3✔
78
        return call_user_func_array($callable, $methodArguments);
3✔
79
    }
80
}
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