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; // FIXME Not ported to Twig 2.x yet |
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 Jasny\Twig\ArrayExtension; // FIXME Not ported to Twig 2.x yet |
22
|
|
|
// use Jasny\Twig\DateExtension; // FIXME Not ported to Twig 2.x yet |
23
|
|
|
// use Jasny\Twig\PcreExtension; // FIXME Not ported to Twig 2.x yet |
24
|
|
|
// use Jasny\Twig\TextExtension; // FIXME Not ported to Twig 2.x yet |
25
|
|
|
use WyriHaximus\TwigView\Lib\Cache; |
26
|
|
|
use WyriHaximus\TwigView\Lib\Twig\Extension; |
27
|
|
|
use WyriHaximus\TwigView\Lib\Twig\TokenParser; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Class ExtensionsListener |
31
|
|
|
* @package WyriHaximus\TwigView\Event |
32
|
|
|
*/ |
33
|
|
|
class ExtensionsListener implements EventListenerInterface |
34
|
|
|
{ |
35
|
|
|
/** |
36
|
|
|
* Return implemented events. |
37
|
|
|
* |
38
|
|
|
* @return array |
39
|
|
|
*/ |
40
|
1 |
|
public function implementedEvents() |
41
|
|
|
{ |
42
|
|
|
return [ |
43
|
1 |
|
ConstructEvent::EVENT => 'construct', |
44
|
1 |
|
]; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Event handler. |
49
|
|
|
* |
50
|
|
|
* @param ConstructEvent $event Event. |
51
|
|
|
* |
52
|
|
|
* @return void |
53
|
|
|
*/ |
54
|
|
|
// @codingStandardsIgnoreStart |
55
|
5 |
|
public function construct(ConstructEvent $event) |
56
|
|
|
{ |
57
|
|
|
// @codingStandardsIgnoreEnd |
58
|
|
|
// @codingStandardsIgnoreStart |
59
|
|
|
// Twig core extensions |
60
|
5 |
|
$event->getTwig()->addExtension(new \Twig_Extension_StringLoader); |
61
|
5 |
|
$event->getTwig()->addExtension(new \Twig_Extension_Debug); |
62
|
|
|
|
63
|
|
|
// CakePHP bridging extensions |
64
|
5 |
|
$event->getTwig()->addExtension(new Extension\I18n); |
65
|
5 |
|
$event->getTwig()->addExtension(new Extension\Time); |
66
|
5 |
|
$event->getTwig()->addExtension(new Extension\Basic); |
67
|
5 |
|
$event->getTwig()->addExtension(new Extension\Number); |
68
|
5 |
|
$event->getTwig()->addExtension(new Extension\Utils); |
69
|
5 |
|
$event->getTwig()->addExtension(new Extension\Arrays); |
70
|
5 |
|
$event->getTwig()->addExtension(new Extension\Strings); |
71
|
5 |
|
$event->getTwig()->addExtension(new Extension\Inflector); |
72
|
|
|
|
73
|
|
|
// Markdown extension |
74
|
|
|
if ( |
75
|
5 |
|
Configure::check('WyriHaximus.TwigView.markdown.engine') && |
76
|
1 |
|
Configure::read('WyriHaximus.TwigView.markdown.engine') instanceof MarkdownEngineInterface |
77
|
5 |
|
) { |
78
|
1 |
|
$engine = Configure::read('WyriHaximus.TwigView.markdown.engine'); |
79
|
1 |
|
$event->getTwig()->addExtension(new MarkdownExtension($engine)); |
80
|
1 |
|
$event->getTwig()->addTokenParser(new MarkdownTokenParser($engine)); |
|
|
|
|
81
|
1 |
|
} |
82
|
|
|
|
83
|
|
|
// Third party cache extension |
84
|
5 |
|
$cacheProvider = new Cache(); |
85
|
5 |
|
$cacheStrategy = new LifetimeCacheStrategy($cacheProvider); |
86
|
5 |
|
$cacheExtension = new CacheExtension($cacheStrategy); |
87
|
5 |
|
$event->getTwig()->addExtension($cacheExtension); |
88
|
|
|
|
89
|
|
|
// jasny/twig-extensions |
90
|
|
|
// $event->getTwig()->addExtension(new DateExtension()); // FIXME Not ported to Twig 2.x yet |
91
|
|
|
// $event->getTwig()->addExtension(new PcreExtension()); // FIXME Not ported to Twig 2.x yet |
92
|
|
|
// $event->getTwig()->addExtension(new TextExtension()); // FIXME Not ported to Twig 2.x yet |
93
|
|
|
// $event->getTwig()->addExtension(new ArrayExtension()); // FIXME Not ported to Twig 2.x yet |
94
|
|
|
|
95
|
|
|
|
96
|
|
|
// Breakpoint extension |
97
|
5 |
|
if (Configure::read('debug') === true) { |
98
|
|
|
// $event->getTwig()->addExtension(new BreakpointExtension()); // FIXME Not ported to Twig 2.x yet |
99
|
4 |
|
} |
100
|
|
|
|
101
|
|
|
// @codingStandardsIgnoreEnd |
102
|
5 |
|
} |
103
|
|
|
} |
104
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.