Completed
Push — master ( 6292d2...03a8c3 )
by Peter
7s
created

PaginationExtension::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 * AnimeDb package.
4
 *
5
 * @author    Peter Gribanov <[email protected]>
6
 * @copyright Copyright (c) 2011, Peter Gribanov
7
 * @license   http://opensource.org/licenses/MIT
8
 */
9
namespace AnimeDb\Bundle\PaginationBundle\Twig\Extension;
10
11
use AnimeDb\Bundle\PaginationBundle\Service\Configuration;
12
13
/**
14
 * Class PaginationExtension.
15
 */
16
class PaginationExtension extends \Twig_Extension
17
{
18
    /**
19
     * @var string
20
     */
21
    protected $template = '';
22
23
    /**
24
     * @param string $template
25
     */
26 5
    public function __construct($template)
27
    {
28 5
        $this->template = $template;
29 5
    }
30
31
    /**
32
     * @return array
33
     */
34 1
    public function getFunctions()
35
    {
36
        return [
37
            new \Twig_SimpleFunction(
38 1
                'pagination_render',
39 1
                [$this, 'render'],
40 1
                ['is_safe' => ['html'], 'needs_environment' => true]
41
            ),
42 1
        ];
43
    }
44
45
    /**
46
     * Renders the pagination template.
47
     *
48
     * @param \Twig_Environment $env
49
     * @param Configuration $pagination
50
     * @param string $template
51
     * @param array $view_params
52
     *
53
     * @return string
54
     */
55 3
    public function render(
56
        \Twig_Environment $env,
57
        Configuration $pagination,
58 1
        $template = null,
59 1
        array $view_params = []
60
    ) {
61
        return $env->render(
62 3
            $template ?: $this->template,
63
            array_merge(
64
                $view_params,
65
                ['pagination' => $pagination->getView()]
66
            )
67
        );
68 2
    }
69
70
    /**
71
     * @return string
72
     */
73 1
    public function getName()
74
    {
75 1
        return 'anime_db_pagination_extension';
76
    }
77
}
78