Completed
Push — master ( c32122...183c21 )
by Alex
02:02
created

TwigConfiguration::prepareFilesystem()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Asmaster\EquipTwig\Configuration;
4
5
use Auryn\Injector;
6
use Equip\Configuration\EnvTrait;
7
use Equip\Configuration\ConfigurationInterface;
8
use Equip\Responder\FormattedResponder;
9
use Asmaster\EquipTwig\TwigFormatter;
10
11
class TwigConfiguration implements ConfigurationInterface
12
{
13
    use EnvTrait;
14
15
    /**
16
     * @param Injector $injector
17
     */
18
    public function apply(Injector $injector)
19
    {
20 2
        $injector->prepare(FormattedResponder::class, function (FormattedResponder $responder) {
21 1
            return $responder->withValue(TwigFormatter::class, 1.0);
22 2
        });
23
24 2
        $injector->alias(
25 2
            'Equip\Adr\PayloadInterface',
26
            'Asmaster\EquipTwig\TemplatePayload'
27 2
        );
28
29 2
        $injector->prepare(\Twig_Loader_Filesystem::class, [$this, 'prepareFilesystem']);
30
31 2
        $injector->define(\Twig_Environment::class, [
32 2
            'loader'   => \Twig_Loader_Filesystem::class,
33 2
            ':options' => $this->prepareOptions()
34 2
        ]);
35 2
    }
36
37
    /**
38
     * @param Twig_Loader_Filesystem $loader
39
     */
40 1
    public function prepareFilesystem(\Twig_Loader_Filesystem $loader)
41
    {
42 1
        $templates = $this->env->getValue('TWIG_TEMPLATES');
43
44 1
        $loader->addPath($templates);
45 1
    }
46
47
    /**
48
     * @return array $options
49
     */
50 2
    public function prepareOptions()
51
    {
52 2
        $env = $this->env;
53
54
        $options = [
55 2
            'debug'            => $env->getValue('TWIG_DEBUG') ?: false,
56 2
            'auto_reload'      => $env->getValue('TWIG_AUTO_RELOAD') ?: true,
57 2
            'strict_variables' => $env->getValue('TWIG_STRICT_VARIABLES') ?: false,
58 2
            'cache'            => $env->getValue('TWIG_CACHE') ?: false
59 2
        ];
60
61 2
        return $options;
62
    }
63
}
64