Completed
Push — master ( 4e56c1...a65fb9 )
by Tim
47s queued 10s
created

EscapeIcalTextViewHelper::render()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
cc 2
nc 2
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
 * EscapeIcalTextViewHelper.
11
 */
12
class EscapeIcalTextViewHelper 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 for ICalendar TEXT defined in RFC 5545 - 3.3.11.
34
     *
35
     * @return string the altered string
36
     *
37
     * @see https://tools.ietf.org/html/rfc5545#section-3.3.11
38
     *
39
     * @api
40
     */
41
    public function render()
42
    {
43
        $value = $this->arguments['value'];
44
        if (null === $value) {
45
            $value = $this->renderChildren();
46
        }
47
        // Note: The string syntax use double and single quotes!
48
        return str_replace(["\\", "\n", "\r", ",", ";"], ['\\\\', '\n', '\r', '\,', '\;'], $value);
49
    }
50
}
51