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