Completed
Push — master ( 0b98a1...f096da )
by Alex
03:36
created

TwigResponderConfiguration::apply()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 1

Importance

Changes 3
Bugs 0 Features 1
Metric Value
c 3
b 0
f 1
dl 0
loc 15
ccs 11
cts 11
cp 1
rs 9.4285
cc 1
eloc 8
nc 1
nop 1
crap 1
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