Completed
Push — master ( e38da2...c1adf5 )
by Alex
02:39
created

TwigResponderConfiguration::getEnvFileExtensions()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

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