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 Ajgl\Twig\Extension\BreakpointExtension; |
14
|
|
|
use Asm89\Twig\CacheExtension\CacheStrategy\LifetimeCacheStrategy; |
15
|
|
|
use Asm89\Twig\CacheExtension\Extension as CacheExtension; |
16
|
|
|
use Cake\Core\Configure; |
17
|
|
|
use Cake\Event\EventListenerInterface; |
18
|
|
|
use WyriHaximus\TwigView\Lib\Cache; |
19
|
|
|
use WyriHaximus\TwigView\Lib\Twig\Extension; |
20
|
|
|
use WyriHaximus\TwigView\Lib\Twig\TokenParser; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Class ExtensionsListener |
24
|
|
|
* @package WyriHaximus\TwigView\Event |
25
|
|
|
*/ |
26
|
|
|
class ExtensionsListener implements EventListenerInterface |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* Return implemented events. |
30
|
|
|
* |
31
|
|
|
* @return array |
32
|
|
|
*/ |
33
|
1 |
|
public function implementedEvents() |
34
|
|
|
{ |
35
|
|
|
return [ |
36
|
1 |
|
ConstructEvent::EVENT => 'construct', |
37
|
1 |
|
]; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Event handler. |
42
|
|
|
* |
43
|
|
|
* @param ConstructEvent $event Event. |
44
|
|
|
* |
45
|
|
|
* @return void |
46
|
|
|
*/ |
47
|
|
|
// @codingStandardsIgnoreStart |
48
|
1 |
|
public function construct(ConstructEvent $event) |
49
|
|
|
{ |
50
|
|
|
// @codingStandardsIgnoreEnd |
51
|
|
|
// @codingStandardsIgnoreStart |
52
|
|
|
// Twig core extensions |
53
|
1 |
|
$event->getTwig()->addExtension(new \Twig_Extension_StringLoader); |
54
|
1 |
|
$event->getTwig()->addExtension(new \Twig_Extension_Debug); |
55
|
|
|
|
56
|
|
|
// CakePHP bridging extensions |
57
|
1 |
|
$event->getTwig()->addExtension(new Extension\I18n); |
58
|
1 |
|
$event->getTwig()->addExtension(new Extension\Time); |
59
|
1 |
|
$event->getTwig()->addExtension(new Extension\Basic); |
60
|
1 |
|
$event->getTwig()->addExtension(new Extension\Number); |
61
|
1 |
|
$event->getTwig()->addExtension(new Extension\Utils); |
62
|
1 |
|
$event->getTwig()->addExtension(new Extension\Arrays); |
63
|
1 |
|
$event->getTwig()->addExtension(new Extension\Strings); |
64
|
1 |
|
$event->getTwig()->addExtension(new Extension\Inflector); |
65
|
|
|
|
66
|
|
|
// Third party cache extension |
67
|
1 |
|
$cacheProvider = new Cache(); |
68
|
1 |
|
$cacheStrategy = new LifetimeCacheStrategy($cacheProvider); |
69
|
1 |
|
$cacheExtension = new CacheExtension($cacheStrategy); |
70
|
1 |
|
$event->getTwig()->addExtension($cacheExtension); |
71
|
|
|
|
72
|
|
|
// Breakpoint extension |
73
|
1 |
|
if (Configure::read('debug') === true) { |
74
|
1 |
|
$event->getTwig()->addExtension(new BreakpointExtension()); |
75
|
1 |
|
} |
76
|
|
|
|
77
|
|
|
// @codingStandardsIgnoreEnd |
78
|
1 |
|
} |
79
|
|
|
} |
80
|
|
|
|