1 | <?php |
||
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) |
|
30 | |||
31 | /** |
||
32 | * @return array |
||
33 | */ |
||
34 | 1 | public function getFunctions() |
|
35 | { |
||
36 | return [ |
||
37 | 1 | new \Twig_SimpleFunction( |
|
38 | 1 | 'pagination_render', |
|
39 | 1 | [$this, 'render'], |
|
40 | 1 | ['is_safe' => ['html'], 'needs_environment' => true] |
|
41 | 1 | ), |
|
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 | $template = null, |
||
59 | array $view_params = [] |
||
60 | ) { |
||
61 | 3 | return $env->render( |
|
62 | 3 | $template ?: $this->template, |
|
63 | 3 | array_merge( |
|
64 | 3 | $view_params, |
|
65 | 3 | ['pagination' => $pagination->getView()] |
|
66 | 3 | ) |
|
67 | 3 | ); |
|
68 | } |
||
69 | |||
70 | /** |
||
71 | * @return string |
||
72 | */ |
||
73 | 1 | public function getName() |
|
77 | } |
||
78 |