Completed
Push — master ( e15c58...b150a8 )
by Changwan
07:08
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\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
use function Wandu\Foundation\path;
11
12
class TwigServiceProvider implements ServiceProviderInterface
13
{
14
    /**
15
     * {@inheritdoc}
16
     */
17
    public function register(ContainerInterface $app)
18
    {
19
        $app->closure(Twig_Environment::class, function () {
20
            $loader = new Twig_Loader_Filesystem(path(config('view.path')));
21
            $options = [];
22
            $cachePath = config('view.cache');
23
            if ($cachePath) {
24
                $options['cache'] = path($cachePath);
25
            }
26
            return new Twig_Environment($loader, $options);
27
        });
28
        $app->closure(RenderInterface::class, function ($app) {
29
            return new TwigView($app[Twig_Environment::class]);
30
        });
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36
    public function boot(ContainerInterface $app)
37
    {
38
    }
39
}
40