TokenParsersListener::implementedEvents()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 6
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
1
<?php
2
declare(strict_types=1);
3
4
/**
5
 * This file is part of TwigView.
6
 *
7
 ** (c) 2014 Cees-Jan Kiewiet
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
namespace WyriHaximus\TwigView\Event;
14
15
use Cake\Event\EventListenerInterface;
16
use LogicException;
17
use WyriHaximus\TwigView\Lib\Twig\TokenParser;
18
19
/**
20
 * Class TokenParsersListener.
21
 * @package WyriHaximus\TwigView\Event
22
 */
23
final class TokenParsersListener implements EventListenerInterface
24
{
25
    /**
26
     * Return implemented events.
27
     *
28
     * @return array
29
     */
30 14
    public function implementedEvents(): array
31
    {
32
        return [
33 14
            ConstructEvent::EVENT => 'construct',
34
        ];
35
    }
36
37
    /**
38
     * Event handler.
39
     *
40
     * @param \WyriHaximus\TwigView\Event\ConstructEvent $event Event.
41
     *
42
     */
43 1
    public function construct(ConstructEvent $event)
44
    {
45
        // CakePHP specific tags
46
        try {
47 1
            $event->getTwig()->addTokenParser(new TokenParser\Cell());
48 1
            $event->getTwig()->addTokenParser(new TokenParser\Element());
49
        } catch (LogicException $d) {
50
            // Nothing to do as token parser already added.
51
        }
52 1
    }
53
}
54