Completed
Push — feature-extra-extensions ( 2f2a70 )
by Cees-Jan
13:52 queued 11:55
created

ExtensionsListener   C

Complexity

Total Complexity 2

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 19

Test Coverage

Coverage 100%

Importance

Changes 5
Bugs 0 Features 1
Metric Value
wmc 2
c 5
b 0
f 1
lcom 0
cbo 19
dl 0
loc 55
ccs 22
cts 22
cp 1
rs 6.875

2 Methods

Rating   Name   Duplication   Size   Complexity  
B construct() 0 32 1
A implementedEvents() 0 6 1
1
<?php
2
3
/**
4
 * This file is part of TwigView.
5
 *
6
 ** (c) 2014 Cees-Jan Kiewiet
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
namespace WyriHaximus\TwigView\Event;
12
13
use Asm89\Twig\CacheExtension\CacheStrategy\LifetimeCacheStrategy;
14
use Asm89\Twig\CacheExtension\Extension as CacheExtension;
15
use Cake\Event\EventListenerInterface;
16
use Jasny\Twig\ArrayExtension;
17
use Jasny\Twig\DateExtension;
18
use Jasny\Twig\PcreExtension;
19
use Jasny\Twig\TextExtension;
20
use WyriHaximus\TwigView\Lib\Cache;
21
use WyriHaximus\TwigView\Lib\Twig\Extension;
22
use WyriHaximus\TwigView\Lib\Twig\TokenParser;
23
24
/**
25
 * Class ExtensionsListener
26
 * @package WyriHaximus\TwigView\Event
27
 */
28
class ExtensionsListener implements EventListenerInterface
29
{
30
    /**
31
     * Return implemented events.
32
     *
33
     * @return array
34
     */
35 1
    public function implementedEvents()
36
    {
37
        return [
38 1
            ConstructEvent::EVENT => 'construct',
39
        ];
40
    }
41
42
    /**
43
     * Event handler.
44
     *
45
     * @param ConstructEvent $event Event.
46
     *
47
     * @return void
48
     */
49
    // @codingStandardsIgnoreStart
50 1
    public function construct(ConstructEvent $event)
51
    {
52
        // @codingStandardsIgnoreEnd
53
        // @codingStandardsIgnoreStart
54
        // Twig core extensions
55 1
        $event->getTwig()->addExtension(new \Twig_Extension_StringLoader);
56 1
        $event->getTwig()->addExtension(new \Twig_Extension_Debug);
57
58
        // CakePHP bridging extensions
59 1
        $event->getTwig()->addExtension(new Extension\I18n);
60 1
        $event->getTwig()->addExtension(new Extension\Time);
61 1
        $event->getTwig()->addExtension(new Extension\Basic);
62 1
        $event->getTwig()->addExtension(new Extension\Number);
63 1
        $event->getTwig()->addExtension(new Extension\Utils);
64 1
        $event->getTwig()->addExtension(new Extension\Arrays);
65 1
        $event->getTwig()->addExtension(new Extension\Strings);
66 1
        $event->getTwig()->addExtension(new Extension\Inflector);
67
68
        // Third party cache extension
69 1
        $cacheProvider = new Cache();
70 1
        $cacheStrategy = new LifetimeCacheStrategy($cacheProvider);
71 1
        $cacheExtension = new CacheExtension($cacheStrategy);
72 1
        $event->getTwig()->addExtension($cacheExtension);
73
74
        // jasny/twig-extensions
75 1
        $event->getTwig()->addExtension(new DateExtension());
76 1
        $event->getTwig()->addExtension(new PcreExtension());
77 1
        $event->getTwig()->addExtension(new TextExtension());
78 1
        $event->getTwig()->addExtension(new ArrayExtension());
79
80
        // @codingStandardsIgnoreEnd
81 1
    }
82
}
83