Completed
Push — master ( 32137b...f3c391 )
by Peter
21s queued 14s
created

Twig_Extension

Complexity

Total Complexity 0

Size/Duplication

Total Lines 3
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 0
lcom 0
cbo 1
dl 0
loc 3
ccs 0
cts 0
cp 0
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * GpsLab component.
5
 *
6
 * @author    Peter Gribanov <[email protected]>
7
 * @copyright Copyright (c) 2011, Peter Gribanov
8
 * @license   http://opensource.org/licenses/MIT
9
 */
10
11
// hook for support Twig > 2.7
12
13
namespace
14
{
15
    use Twig\Extension\AbstractExtension;
16
    use Twig\TwigFunction;
17
18 1
    if (!class_exists('Twig_Extension') && class_exists('Twig\Extension\AbstractExtension')) {
19
        class Twig_Extension extends AbstractExtension
20
        {
21
        }
22
    }
23
24 1
    if (!class_exists('Twig_SimpleFunction') && class_exists('Twig\TwigFunction')) {
25
        class Twig_SimpleFunction extends TwigFunction
26
        {
27
        }
28
    }
29
}
30
31
namespace GpsLab\Bundle\PaginationBundle\Twig\Extension
32
{
33
    use GpsLab\Bundle\PaginationBundle\Service\Configuration;
34
35
    class PaginationExtension extends \Twig_Extension
36
    {
37
        /**
38
         * @var string
39
         */
40
        private $template;
41
42
        /**
43
         * @param string $template
44
         */
45 5
        public function __construct($template)
46
        {
47 5
            $this->template = $template;
48 5
        }
49
50
        /**
51
         * @return array
52
         */
53 1
        public function getFunctions()
54
        {
55
            return [
56 1
                new \Twig_SimpleFunction(
57 1
                    'pagination_render',
58 1
                    [$this, 'renderPagination'],
59 1
                    ['is_safe' => ['html'], 'needs_environment' => true]
60
                ),
61
            ];
62
        }
63
64
        /**
65
         * @param \Twig_Environment $env
66
         * @param Configuration     $pagination
67
         * @param string            $template
68
         * @param array             $view_params
69
         *
70
         * @return string
71
         */
72 3
        public function renderPagination(
73
            \Twig_Environment $env,
74
            Configuration $pagination,
75
            $template = null,
76
            array $view_params = []
77
        ) {
78 3
            return $env->render(
79 3
                $template ?: $this->template,
80 3
                array_merge($view_params, ['pagination' => $pagination->getView()])
81
            );
82
        }
83
84
        /**
85
         * @return string
86
         */
87 1
        public function getName()
88
        {
89 1
            return 'gpslab_pagination_extension';
90
        }
91
    }
92
}
93