<commit_before><?php

namespace Wanjee\Shuwee\AdminBundle\Twig;

use Symfony\Component\Translation\TranslatorInterface;
use Wanjee\Shuwee\AdminBundle\Datagrid\DatagridInterface;
use Wanjee\Shuwee\AdminBundle\Datagrid\Field\DatagridFieldInterface;

/**
 * Class AdminExtension
 * @package Wanjee\Shuwee\AdminBundle\Twig
 */
class DatagridExtension extends \Twig_Extension
{
    /**
     * @var \Twig_Environment
     */
    private $environment;

    /**
     * @var \Symfony\Component\Translation\TranslatorInterface
     */
    protected $translator;

    /**
     * @param \Symfony\Component\Translation\TranslatorInterface $translator
     */
    public function __construct(TranslatorInterface $translator = null)
    {
        $this->translator = $translator;
    }

    /**
     * @param \Twig_Environment $environment
     */
    public function initRuntime(\Twig_Environment $environment)
    {
        $this->environment = $environment;
    }

    /**
     * @return array
     */
    public function getFunctions()
    {
        return array(
          'datagrid' => new \Twig_Function_Method($this, 'renderDatagrid', array('is_safe' => array('html'))),
          'datagrid_field' => new \Twig_Function_Method($this, 'renderDatagridField', array('is_safe' => array('html'))),
        );
    }

    /**
     * @param $datagrid \Wanjee\Shuwee\AdminBundle\Datagrid\Datagrid
     */
    public function renderDatagrid(DatagridInterface $datagrid)
    {
        return $this->render('datagrid', array(
          'datagrid' => $datagrid,
        ));
    }

    /**
     * @param $datagrid \Wanjee\Shuwee\AdminBundle\Datagrid\Field\DatagridFieldInterface
     */
    public function renderDatagridField(DatagridFieldInterface $field, $entity)
    {
        /** @var \Wanjee\Shuwee\AdminBundle\Datagrid\Type\DatagridTypeInterface */
        $type = $field->getType();

        return $this->render($type->getBlockName(), $type->getBlockVariables($field, $entity));
    }

    /**
     * @param string $block Block name
     * @param array $variables
     */
    public function render($block, $variables = array())
    {
        /** @var \Twig_TemplateInterface $template */
        $template = $this->environment->loadTemplate('ShuweeAdminBundle:Datagrid:datagrid.html.twig');

        return $template->renderBlock($block, $variables);
    }

    /**
     * @return string
     */
    public function getName()
    {
        return 'shuwee_datagrid_extension';
    }
}
<commit_msg>Fix deprecated Twig_Function_Method; Fix deprecated initRuntime<commit_after><?php

namespace Wanjee\Shuwee\AdminBundle\Twig;

use Symfony\Component\Translation\TranslatorInterface;
use Twig_Environment;
use Wanjee\Shuwee\AdminBundle\Datagrid\DatagridInterface;
use Wanjee\Shuwee\AdminBundle\Datagrid\Field\DatagridFieldInterface;

/**
 * Class AdminExtension
 * @package Wanjee\Shuwee\AdminBundle\Twig
 */
class DatagridExtension extends \Twig_Extension
{
    /**
     * @var \Twig_Environment
     */
    private $environment;

    /**
     * @var \Symfony\Component\Translation\TranslatorInterface
     */
    protected $translator;

    /**
     * @param \Symfony\Component\Translation\TranslatorInterface $translator
     */
    public function __construct(TranslatorInterface $translator = null)
    {
        $this->translator = $translator;
    }

    /**
     * @return array
     */
    public function getFunctions()
    {
        return array(
          new \Twig_SimpleFunction('datagrid', array($this, 'renderDatagrid'), array('is_safe' => array('html'), 'needs_environment' => true)),
          new \Twig_SimpleFunction('datagrid_field', array($this, 'renderDatagridField'), array('is_safe' => array('html'), 'needs_environment' => true)),
        );
    }

    /**
     * @param $datagrid \Wanjee\Shuwee\AdminBundle\Datagrid\Datagrid
     */
    public function renderDatagrid(Twig_Environment $env, DatagridInterface $datagrid)
    {
        return $this->render(
            $env,
            'datagrid',
            array(
                'datagrid' => $datagrid,
            )
        );
    }

    /**
     * @param $datagrid \Wanjee\Shuwee\AdminBundle\Datagrid\Field\DatagridFieldInterface
     */
    public function renderDatagridField(Twig_Environment $env, DatagridFieldInterface $field, $entity)
    {
        /** @var \Wanjee\Shuwee\AdminBundle\Datagrid\Type\DatagridTypeInterface */
        $type = $field->getType();

        return $this->render(
            $env,
            $type->getBlockName(),
            $type->getBlockVariables($field, $entity)
        );
    }

    /**
     * @param string $block Block name
     * @param array $variables
     */
    public function render(Twig_Environment $env, $block, $variables = array())
    {
        /** @var \Twig_TemplateInterface $template */
        $template = $env->loadTemplate('ShuweeAdminBundle:Datagrid:datagrid.html.twig');

        return $template->renderBlock($block, $variables);
    }

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

{'fraction_non_alphanumeric': 0.12970957613814757, 'fraction_numerical': 0.0, 'mean_word_length': 2.7699704142011834, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1185358', 'n_tokens_mistral': 1598, 'n_tokens_neox': 1569, 'n_words': 250}