Skip to content

Commit

Permalink
Merge pull request #24 from peter-gribanov/twig_2.7
Browse files Browse the repository at this point in the history
Add hook for support Twig > 2.7
  • Loading branch information
peter-gribanov authored Oct 31, 2019
2 parents 32137b4 + 7d19585 commit f3c3911
Showing 1 changed file with 71 additions and 50 deletions.
121 changes: 71 additions & 50 deletions src/Twig/Extension/PaginationExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,64 +8,85 @@
* @license http://opensource.org/licenses/MIT
*/

namespace GpsLab\Bundle\PaginationBundle\Twig\Extension;
// hook for support Twig > 2.7

use GpsLab\Bundle\PaginationBundle\Service\Configuration;

class PaginationExtension extends \Twig_Extension
namespace
{
/**
* @var string
*/
private $template = '';
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;

/**
* @param string $template
*/
public function __construct($template)
{
$this->template = $template;
if (!class_exists('Twig_Extension') && class_exists('Twig\Extension\AbstractExtension')) {
class Twig_Extension extends AbstractExtension
{
}
}

/**
* @return array
*/
public function getFunctions()
{
return [
new \Twig_SimpleFunction(
'pagination_render',
[$this, 'renderPagination'],
['is_safe' => ['html'], 'needs_environment' => true]
),
];
if (!class_exists('Twig_SimpleFunction') && class_exists('Twig\TwigFunction')) {
class Twig_SimpleFunction extends TwigFunction
{
}
}
}

/**
* @param \Twig_Environment $env
* @param Configuration $pagination
* @param string $template
* @param array $view_params
*
* @return string
*/
public function renderPagination(
\Twig_Environment $env,
Configuration $pagination,
$template = null,
array $view_params = []
) {
return $env->render(
$template ?: $this->template,
array_merge($view_params, ['pagination' => $pagination->getView()])
);
}
namespace GpsLab\Bundle\PaginationBundle\Twig\Extension
{
use GpsLab\Bundle\PaginationBundle\Service\Configuration;

/**
* @return string
*/
public function getName()
class PaginationExtension extends \Twig_Extension
{
return 'gpslab_pagination_extension';
/**
* @var string
*/
private $template;

/**
* @param string $template
*/
public function __construct($template)
{
$this->template = $template;
}

/**
* @return array
*/
public function getFunctions()
{
return [
new \Twig_SimpleFunction(
'pagination_render',
[$this, 'renderPagination'],
['is_safe' => ['html'], 'needs_environment' => true]
),
];
}

/**
* @param \Twig_Environment $env
* @param Configuration $pagination
* @param string $template
* @param array $view_params
*
* @return string
*/
public function renderPagination(
\Twig_Environment $env,
Configuration $pagination,
$template = null,
array $view_params = []
) {
return $env->render(
$template ?: $this->template,
array_merge($view_params, ['pagination' => $pagination->getView()])
);
}

/**
* @return string
*/
public function getName()
{
return 'gpslab_pagination_extension';
}
}
}

0 comments on commit f3c3911

Please sign in to comment.