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