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
|
|
|
|