Completed
Push — develop ( b5d1ea...bf89f2 )
by Neomerx
03:07
created

configureContainer()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 19
ccs 11
cts 11
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 12
nc 1
nop 1
crap 1
1
<?php namespace Limoncello\Templates\Package;
2
3
/**
4
 * Copyright 2015-2017 [email protected]
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 * http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
use Limoncello\Contracts\Application\ContainerConfiguratorInterface;
20
use Limoncello\Contracts\Container\ContainerInterface as LimoncelloContainerInterface;
21
use Limoncello\Contracts\Settings\SettingsProviderInterface;
22
use Limoncello\Contracts\Templates\TemplatesInterface;
23
use Limoncello\Templates\Contracts\TemplatesCacheInterface;
24
use Limoncello\Templates\Package\TemplatesSettings as C;
25
use Limoncello\Templates\TwigTemplates;
26
use Psr\Container\ContainerInterface as PsrContainerInterface;
27
28
/**
29
 * @package Limoncello\Templates
30
 */
31
class TwigTemplatesContainerConfigurator implements ContainerConfiguratorInterface
32
{
33
    /**
34
     * @inheritdoc
35
     */
36
    public static function configureContainer(LimoncelloContainerInterface $container): void
37
    {
38 1
        $container[TemplatesInterface::class] = function (PsrContainerInterface $container): TemplatesInterface {
39 1
            $settings  = $container->get(SettingsProviderInterface::class)->get(C::class);
40 1
            $templates = new TwigTemplates(
41 1
                $settings[C::KEY_APP_ROOT_FOLDER],
42 1
                $settings[C::KEY_TEMPLATES_FOLDER],
43 1
                $settings[C::KEY_CACHE_FOLDER] ?? null,
44 1
                $settings[C::KEY_IS_DEBUG] ?? false
45
            );
46
47 1
            return $templates;
48
        };
49
50 1
        $container[TemplatesCacheInterface::class] =
51 1
            function (PsrContainerInterface $container): TemplatesCacheInterface {
52 1
                return $container->get(TemplatesInterface::class);
53
        };
54
    }
55
}
56