|
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 Jasny\Twig\ArrayExtension; |
|
22
|
|
|
use Jasny\Twig\DateExtension; |
|
23
|
|
|
use Jasny\Twig\PcreExtension; |
|
24
|
|
|
use Jasny\Twig\TextExtension; |
|
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
|
|
|
public function implementedEvents() |
|
41
|
|
|
{ |
|
42
|
|
|
return [ |
|
43
|
|
|
ConstructEvent::EVENT => 'construct', |
|
44
|
|
|
]; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Event handler. |
|
49
|
|
|
* |
|
50
|
|
|
* @param ConstructEvent $event Event. |
|
51
|
|
|
* |
|
52
|
|
|
* @return void |
|
53
|
|
|
*/ |
|
54
|
|
|
// @codingStandardsIgnoreStart |
|
55
|
|
|
public function construct(ConstructEvent $event) |
|
56
|
|
|
{ |
|
57
|
|
|
// @codingStandardsIgnoreEnd |
|
58
|
|
|
// @codingStandardsIgnoreStart |
|
59
|
|
|
// Twig core extensions |
|
60
|
|
|
$event->getTwig()->addExtension(new \Twig_Extension_StringLoader); |
|
61
|
|
|
$event->getTwig()->addExtension(new \Twig_Extension_Debug); |
|
62
|
|
|
|
|
63
|
|
|
// CakePHP bridging extensions |
|
64
|
|
|
$event->getTwig()->addExtension(new Extension\I18n); |
|
65
|
|
|
$event->getTwig()->addExtension(new Extension\Time); |
|
66
|
|
|
$event->getTwig()->addExtension(new Extension\Basic); |
|
67
|
|
|
$event->getTwig()->addExtension(new Extension\Number); |
|
68
|
|
|
$event->getTwig()->addExtension(new Extension\Utils); |
|
69
|
|
|
$event->getTwig()->addExtension(new Extension\Arrays); |
|
70
|
|
|
$event->getTwig()->addExtension(new Extension\Strings); |
|
71
|
|
|
$event->getTwig()->addExtension(new Extension\Inflector); |
|
72
|
|
|
|
|
73
|
|
|
// Markdown extension |
|
74
|
|
|
if ( |
|
75
|
|
|
Configure::check('WyriHaximus.TwigView.markdown.engine') && |
|
76
|
|
|
Configure::read('WyriHaximus.TwigView.markdown.engine') instanceof MarkdownEngineInterface |
|
|
|
|
|
|
77
|
|
|
) { |
|
78
|
|
|
$engine = Configure::read('WyriHaximus.TwigView.markdown.engine'); |
|
79
|
|
|
$event->getTwig()->addExtension(new MarkdownExtension($engine)); |
|
80
|
|
|
$event->getTwig()->addTokenParser(new MarkdownTokenParser($engine)); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
// Third party cache extension |
|
84
|
|
|
$cacheProvider = new Cache(); |
|
85
|
|
|
$cacheStrategy = new LifetimeCacheStrategy($cacheProvider); |
|
86
|
|
|
$cacheExtension = new CacheExtension($cacheStrategy); |
|
87
|
|
|
$event->getTwig()->addExtension($cacheExtension); |
|
88
|
|
|
|
|
89
|
|
|
// jasny/twig-extensions |
|
90
|
|
|
$event->getTwig()->addExtension(new DateExtension()); |
|
91
|
|
|
$event->getTwig()->addExtension(new PcreExtension()); |
|
92
|
|
|
$event->getTwig()->addExtension(new TextExtension()); |
|
93
|
|
|
$event->getTwig()->addExtension(new ArrayExtension()); |
|
94
|
|
|
|
|
95
|
|
|
|
|
96
|
|
|
// Breakpoint extension |
|
97
|
|
|
if (Configure::read('debug') === true) { |
|
98
|
|
|
$event->getTwig()->addExtension(new BreakpointExtension()); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
// @codingStandardsIgnoreEnd |
|
102
|
|
|
} |
|
103
|
|
|
} |
|
104
|
|
|
|
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.jsonfile (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.jsonto be in the root folder of your repository.Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the
requireorrequire-devsection?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceofchecks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.