1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Asmaster\EquipTwig\Configuration; |
4
|
|
|
|
5
|
|
|
use Asmaster\EquipTwig\TwigFormatter; |
6
|
|
|
use Auryn\Injector; |
7
|
|
|
use Equip\Configuration\ConfigurationInterface; |
8
|
|
|
use Equip\Configuration\EnvTrait; |
9
|
|
|
use Equip\Responder\FormattedResponder; |
10
|
|
|
use Twig_Environment as TwigEnvironment; |
11
|
|
|
use Twig_Loader_Filesystem as TwigLoaderFilesystem; |
12
|
|
|
|
13
|
|
|
class TwigResponderConfiguration implements ConfigurationInterface |
14
|
|
|
{ |
15
|
|
|
use EnvTrait; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @param Injector $injector |
19
|
|
|
*/ |
20
|
|
|
public function apply(Injector $injector) |
21
|
|
|
{ |
22
|
1 |
|
$injector->prepare(FormattedResponder::class, function(FormattedResponder $responder) { |
23
|
1 |
|
return $responder->withValue(TwigFormatter::class, 1.0); |
24
|
1 |
|
}); |
25
|
|
|
|
26
|
1 |
|
$injector->define(TwigLoaderFilesystem::class, [ |
27
|
1 |
|
':paths' => $this->env->getValue('TWIG_TEMPLATES') |
28
|
1 |
|
]); |
29
|
|
|
|
30
|
1 |
|
$injector->define(TwigEnvironment::class, [ |
31
|
1 |
|
'loader' => TwigLoaderFilesystem::class, |
32
|
1 |
|
':options' => $this->getEnvOptions() |
33
|
1 |
|
]); |
34
|
1 |
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @return array $options |
38
|
|
|
*/ |
39
|
1 |
|
public function getEnvOptions() |
40
|
|
|
{ |
41
|
1 |
|
$env = $this->env; |
42
|
|
|
|
43
|
|
|
$options = [ |
44
|
1 |
|
'debug' => $env->getValue('TWIG_DEBUG', false), |
45
|
1 |
|
'auto_reload' => $env->getValue('TWIG_AUTO_RELOAD', true), |
46
|
1 |
|
'strict_variables' => $env->getValue('TWIG_STRICT_VARIABLES', false), |
47
|
1 |
|
'cache' => $env->getValue('TWIG_CACHE', false) |
48
|
1 |
|
]; |
49
|
|
|
|
50
|
1 |
|
return $options; |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|