Completed
Push — master ( 413e31...6028d7 )
by Changwan
06:35
created

TwigServiceProvider::boot()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 3
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
namespace Wandu\View\Bridges\Twig;
3
4
use Twig_Environment;
5
use Twig_Loader_Filesystem;
6
use Wandu\DI\ContainerInterface;
7
use Wandu\DI\ServiceProviderInterface;
8
use Wandu\View\Contracts\RenderInterface;
9
use function Wandu\Foundation\config;
10
11
class TwigServiceProvider implements ServiceProviderInterface
12
{
13
    /**
14
     * {@inheritdoc}
15
     */
16
    public function register(ContainerInterface $app)
17
    {
18
        $app->closure(Twig_Environment::class, function () {
19
            $loader = new Twig_Loader_Filesystem(config('twig.path', config('view.path')));
20
            $options = [
21
                'auto_reload' => true,
22
            ];
23
            $cachePath = config('view.cache');
24
            if ($cachePath) {
25
                $options['cache'] = $cachePath;
26
            }
27
            return new Twig_Environment($loader, $options);
28
        });
29
        $app->bind(RenderInterface::class, TwigView::class);
30
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35
    public function boot(ContainerInterface $app)
36
    {
37
    }
38
}
39