Completed
Push — master ( 237ce5...4e56c1 )
by Tim
01:59
created

EscapeNewLinesViewHelper::initializeArguments()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace HDNET\Calendarize\ViewHelpers\Format;
6
7
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
8
9
/**
10
 * EscapeNewLinesViewHelper.
11
 */
12
class EscapeNewLinesViewHelper extends AbstractViewHelper
13
{
14
    /**
15
     * @var bool
16
     */
17
    protected $escapeChildren = false;
18
19
    /**
20
     * Disable the output escaping interceptor so that the value is not htmlspecialchar'd twice.
21
     *
22
     * @var bool
23
     */
24
    protected $escapeOutput = false;
25
26
    public function initializeArguments()
27
    {
28
        parent::initializeArguments();
29
        $this->registerArgument('value', 'string', 'Value to format');
30
    }
31
32
    /**
33
     * Escapes special characters with their escaped counterparts as needed using PHPs htmlspecialchars() function.
34
     *
35
     * @return string the altered string
36
     *
37
     * @see http://www.php.net/manual/function.htmlspecialchars.php
38
     *
39
     * @api
40
     */
41
    public function render()
42
    {
43
        $value = $this->arguments['value'];
44
        if (null === $value) {
45
            $value = $this->renderChildren();
46
        }
47
48
        return str_replace(["\n", "\r"], ['\\n', '\\r'], $value);
49
    }
50
}
51