| 1 | <?php |
||
| 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) |
|
| 33 | |||
| 34 | /** |
||
| 35 | * @return array |
||
| 36 | */ |
||
| 37 | 1 | public function getFunctions() |
|
| 38 | { |
||
| 39 | return [ |
||
| 40 | new \Twig_Function( |
||
| 41 | 1 | 'pagination_render', |
|
| 42 | 1 | [$this, 'render'], |
|
| 43 | 1 | ['is_safe' => ['html'], 'needs_environment' => true] |
|
| 44 | ) |
||
| 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 | 1 | $template = null, |
|
| 62 | 1 | array $view_params = [] |
|
| 63 | ) { |
||
| 64 | return $env->render( |
||
| 65 | 3 | $template ?: $this->template, |
|
| 66 | array_merge( |
||
| 67 | $view_params, |
||
| 68 | ['pagination' => $pagination->getView()] |
||
| 69 | ) |
||
| 70 | ); |
||
| 71 | 2 | } |
|
| 72 | |||
| 73 | /** |
||
| 74 | * @return string |
||
| 75 | */ |
||
| 76 | 1 | public function getName() |
|
| 80 | } |
||
| 81 |