1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @copyright 2018 Vladimir Jimenez |
5
|
|
|
* @license https://github.com/stakx-io/stakx/blob/master/LICENSE.md MIT |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace allejo\stakx\Templating\Twig; |
9
|
|
|
|
10
|
|
|
use allejo\stakx\Configuration; |
11
|
|
|
use allejo\stakx\Filesystem\FilesystemLoader as fs; |
12
|
|
|
use allejo\stakx\Manager\CollectionManager; |
13
|
|
|
use allejo\stakx\Manager\DataManager; |
14
|
|
|
use allejo\stakx\Manager\MenuManager; |
15
|
|
|
use allejo\stakx\Manager\PageManager; |
16
|
|
|
use allejo\stakx\RuntimeStatus; |
17
|
|
|
use allejo\stakx\Service; |
18
|
|
|
use Psr\Log\LoggerInterface; |
19
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
20
|
|
|
use Twig_Environment; |
21
|
|
|
use Twig_Extension_Debug; |
22
|
|
|
|
23
|
|
|
class TwigStakxBridgeFactory |
24
|
|
|
{ |
25
|
48 |
|
public static function createTwigEnvironment( |
26
|
|
|
Configuration $configuration, |
27
|
|
|
TwigExtension $twigExtension, |
28
|
|
|
LoggerInterface $logger |
29
|
|
|
) { |
30
|
48 |
|
$loader = new TwigFileLoader([ |
31
|
48 |
|
Service::getWorkingDirectory(), |
32
|
|
|
]); |
33
|
|
|
|
34
|
48 |
|
$theme = $configuration->getTheme(); |
35
|
|
|
|
36
|
|
|
// Only load a theme if one is specified and actually exists |
37
|
48 |
|
if ($theme !== null) |
38
|
|
|
{ |
39
|
|
|
try |
40
|
|
|
{ |
41
|
|
|
$loader->addPath(fs::absolutePath('_themes', $theme), 'theme'); |
|
|
|
|
42
|
|
|
} |
43
|
|
|
catch (\Twig_Error_Loader $e) |
44
|
|
|
{ |
45
|
|
|
$logger->error('The following theme could not be loaded: {theme}', [ |
46
|
|
|
'theme' => $theme, |
47
|
|
|
]); |
48
|
|
|
$logger->error($e->getMessage()); |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
|
52
|
48 |
|
$twig = new Twig_Environment($loader, [ |
53
|
48 |
|
'autoescape' => $configuration->getTwigAutoescape(), |
54
|
|
|
'auto_reload' => true, |
55
|
48 |
|
'cache' => fs::absolutePath('.stakx-cache/twig'), |
|
|
|
|
56
|
|
|
]); |
57
|
|
|
|
58
|
48 |
|
$twig->addExtension($twigExtension); |
59
|
|
|
|
60
|
48 |
|
$profiler = null; |
61
|
|
|
|
62
|
48 |
|
if (Service::hasRunTimeFlag(RuntimeStatus::IN_PROFILE_MODE)) |
63
|
|
|
{ |
64
|
|
|
$profiler = new \Twig_Profiler_Profile(); |
65
|
|
|
$twig->addExtension(new \Twig_Extension_Profiler($profiler)); |
66
|
|
|
} |
67
|
|
|
|
68
|
48 |
|
if ($configuration->isDebug()) |
69
|
|
|
{ |
70
|
|
|
$twig->addExtension(new Twig_Extension_Debug()); |
71
|
|
|
$twig->enableDebug(); |
72
|
|
|
} |
73
|
|
|
|
74
|
48 |
|
$bridge = new TwigStakxBridge($twig); |
75
|
48 |
|
$bridge->setProfiler($profiler); |
76
|
|
|
|
77
|
48 |
|
return $bridge; |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: