Completed
Push — master ( eaa10a...12d04d )
by Albert
03:25
created

TwigServiceProvider::boot()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 6
rs 9.4285
cc 1
eloc 1
nc 1
nop 0
1
<?php
2
3
namespace Albert221\Blog\ServiceProvider;
4
5
use Albert221\Blog\Pagination\PaginatorBuilder;
6
use League\Container\ServiceProvider\AbstractServiceProvider;
7
use Twig_Environment;
8
use Twig_Loader_Filesystem;
9
10
class TwigServiceProvider extends AbstractServiceProvider
11
{
12
    /**
13
     * {@inheritdoc}
14
     */
15
    protected $provides = [
16
        'twig',
17
        'paginatorBuilder'
18
    ];
19
20
    /**
21
     * {@inheritdoc}
22
     */
23
    public function register()
24
    {
25
        $this->getContainer()->share('twig', function () {
26
            $loader = new Twig_Loader_Filesystem(
27
                $this->getContainer()->get('baseDir').'/views'
28
            );
29
            
30
            return new Twig_Environment($loader, [
31
                'autoescape' => false
32
            ]);
33
        });
34
        
35
        $this->getContainer()->share('paginatorBuilder', function () {
36
            return new PaginatorBuilder(
37
                $this->getContainer()->get('twig'),
38
                $this->getContainer()->get('config')['pagination']['perPage']
39
            );
40
        });
41
    }
42
}
43