-
Notifications
You must be signed in to change notification settings - Fork 229
/
ImplodeViewHelper.php
75 lines (67 loc) · 2.06 KB
/
ImplodeViewHelper.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
namespace FluidTYPO3\Vhs\ViewHelpers\Iterator;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use FluidTYPO3\Vhs\Traits\ArrayConsumingViewHelperTrait;
use FluidTYPO3\Vhs\Traits\TemplateVariableViewHelperTrait;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
/**
* Implode ViewHelper
*
* Implodes an array or array-convertible object by $glue.
*/
class ImplodeViewHelper extends AbstractViewHelper
{
use TemplateVariableViewHelperTrait;
use ArrayConsumingViewHelperTrait;
/**
* @var boolean
*/
protected $escapeChildren = false;
/**
* @var boolean
*/
protected $escapeOutput = false;
public function initializeArguments(): void
{
parent::initializeArguments();
$this->registerArgument('content', 'array', 'Array or array-convertible object to be imploded by glue');
$this->registerArgument(
'glue',
'string',
'String used as glue in the string to be exploded. To read a constant (like PHP_EOL) use v:const.',
false,
','
);
$this->registerAsArgument();
}
/**
* @return mixed
*/
public static function renderStatic(
array $arguments,
\Closure $renderChildrenClosure,
RenderingContextInterface $renderingContext
) {
/** @var string|null $as */
$as = $arguments['as'];
/** @var array $content */
$content = !empty($as)
? $arguments['content']
: ($arguments['content'] ?? $renderChildrenClosure());
/** @var string $glue */
$glue = $arguments['glue'];
$output = implode($glue, $content);
return static::renderChildrenWithVariableOrReturnInputStatic(
$output,
$as,
$renderingContext,
$renderChildrenClosure
);
}
}