<commit_before><?php

namespace Phalcon\Mvc\View\Engine;

use Phalcon\Mvc\View\Engine,
    Phalcon\Mvc\View\EngineInterface;

/**
 * Phalcon\Mvc\View\Engine\Twig
 *
 * Adapter to use Twig library as templating engine
 */
class Twig extends Engine implements EngineInterface
{

    protected $_twig;

    /**
     * Phalcon\Mvc\View\Engine\Twig constructor
     *
     * @param \Phalcon\Mvc\ViewInterface $view
     * @param \Phalcon\DiInterface $di
     */
    public function __construct($view,  $di)
    {
        $loader = new Twig_Loader_Filesystem($view->getViewsDir());
        $this->_twig = new Twig_Environment($loader);
        $this->_registryFunctions($view);
        parent::__construct($view, $di);
    }

    /**
     * Registers common function in Twig
     *
     * @param \Phalcon\Mvc\ViewInterface $view
     */
    private function _registryFunctions($view)
    {
        $options = array(
            'is_safe' => array('html')
        );

        $functions = array(
             new \Twig_SimpleFunction('content', function() use ($view) {
                return $view->getContent();
            }),
            new \Twig_SimpleFunction('linkTo', function($parameters, $text = null) {
                return \Phalcon\Tag::linkTo($parameters, $text);
            }),
            new \Twig_SimpleFunction('textField', function($parameters) {
                return \Phalcon\Tag::textField($parameters);
            }),
            new \Twig_SimpleFunction('passwordField', function($parameters) {
                return \Phalcon\Tag::passwordField($parameters);
            }),
            new \Twig_SimpleFunction('hiddenField', function($parameters) {
                return \Phalcon\Tag::hiddenField($parameters);
            }),
            new \Twig_SimpleFunction('fileField', function($parameters) {
                return \Phalcon\Tag::fileField($parameters);
            }),
            new \Twig_SimpleFunction('checkField', function($parameters) {
                return \Phalcon\Tag::checkField($parameters);
            }),
            new \Twig_SimpleFunction('radioField', function($parameters) {
                return \Phalcon\Tag::radioField($parameters);
            }),
            new \Twig_SimpleFunction('submitButton', function($parameters) {
                return \Phalcon\Tag::submitButton($parameters);
            }),
            new \Twig_SimpleFunction('selectStatic', function($parameters, $data=null) {
                return \Phalcon\Tag::selectStatic($parameters, $data);
            }),
            new \Twig_SimpleFunction('select', function($parameters, $data=null) {
                return \Phalcon\Tag::select($parameters, $data);
            }),
            new \Twig_SimpleFunction('textArea', function($parameters) {
                return \Phalcon\Tag::textArea($parameters);
            }),
            new \Twig_SimpleFunction('form', function($parameters=null) {
                return \Phalcon\Tag::form($parameters);
            }),
            new \Twig_SimpleFunction('endForm', function() {
                return \Phalcon\Tag::endForm();
            }),
            new \Twig_SimpleFunction('getTitle', function() {
                return \Phalcon\Tag::getTitle();
            }),
            new \Twig_SimpleFunction('getTitle', function() {
                return \Phalcon\Tag::getTitle();
            }),
            new \Twig_SimpleFunction('stylesheetLink', function($parameters=null, $local=null) {
                return \Phalcon\Tag::stylesheetLink($parameters, $local);
            }),
            new \Twig_SimpleFunction('javascriptInclude', function($parameters=null, $local=null) {
                return \Phalcon\Tag::javascriptInclude($parameters, $local);
            }),
            new \Twig_SimpleFunction('image', function($parameters) {
                return \Phalcon\Tag::image($parameters);
            }),
            new \Twig_SimpleFunction('friendlyTitle', function($text, $separator=null, $lowercase=null) {
                return \Phalcon\Tag::friendlyTitle($text, $separator, $lowercase);
            }),
            new \Twig_SimpleFunction('getDocType', function() {
                return \Phalcon\Tag::getDocType();
            }, $options)
        );

        foreach ($functions as $function) {
            $this->_twig->addFunction($function);
        }
    }

    /**
     * Renders a view
     *
     * @param string $path
     * @param array $params
     * @param boolean $mustClean
     */
    public function render($path, $params, $mustClean=false)
    {
        $view = $this->_view;
        if (!isset($params['content'])) {
            $params['content'] = $view->getContent();
        }

        if (!isset($params['view'])) {<commit_msg>Updating Twig/Mustache adapters (4)<commit_after><?php

namespace Phalcon\Mvc\View\Engine;

use Phalcon\Mvc\View\Engine,
    Phalcon\Mvc\View\EngineInterface;

/**
 * Phalcon\Mvc\View\Engine\Twig
 *
 * Adapter to use Twig library as templating engine
 */
class Twig extends Engine implements EngineInterface
{

    protected $_twig;

    /**
     * Phalcon\Mvc\View\Engine\Twig constructor
     *
     * @param \Phalcon\Mvc\ViewInterface $view
     * @param \Phalcon\DiInterface $di
     */
    public function __construct($view,  $di)
    {
        $loader = new Twig_Loader_Filesystem($view->getViewsDir());
        $this->_twig = new Twig_Environment($loader);
        $this->_registryFunctions($view);
        parent::__construct($view, $di);
    }

    /**
     * Registers common function in Twig
     *
     * @param \Phalcon\Mvc\ViewInterface $view
     */
    private function registryFunction($view)
    {

        $options = array(
            'is_safe' => array('html')
        );

        $functions = array(
            new \Twig_SimpleFunction('content', function() use ($view) {
                return $view->getContent();
            }, $options),
            new \Twig_SimpleFunction('partial', function($partialPath) use ($view) {
                return $view->partial($partialPath);
            }, $options),
            new \Twig_SimpleFunction('linkTo', function($parameters, $text = null) {
                return \Phalcon\Tag::linkTo($parameters, $text);
            }, $options),
            new \Twig_SimpleFunction('textField', function($parameters) {
                return \Phalcon\Tag::textField($parameters);
            }, $options),
            new \Twig_SimpleFunction('passwordField', function($parameters) {
                return \Phalcon\Tag::passwordField($parameters);
            }, $options),
            new \Twig_SimpleFunction('hiddenField', function($parameters) {
                return \Phalcon\Tag::hiddenField($parameters);
            }, $options),
            new \Twig_SimpleFunction('fileField', function($parameters) {
                return \Phalcon\Tag::fileField($parameters);
            }, $options),
            new \Twig_SimpleFunction('checkField', function($parameters) {
                return \Phalcon\Tag::checkField($parameters);
            }, $options),
            new \Twig_SimpleFunction('radioField', function($parameters) {
                return \Phalcon\Tag::radioField($parameters);
            }, $options),
            new \Twig_SimpleFunction('submitButton', function($parameters) {
                return \Phalcon\Tag::submitButton($parameters);
            }, $options),
            new \Twig_SimpleFunction('selectStatic', function($parameters, $data = array()) {
                return \Phalcon\Tag::selectStatic($parameters, $data);
            }, $options),
            new \Twig_SimpleFunction('select', function($parameters, $data = array()) {
                return \Phalcon\Tag::select($parameters, $data);
            }, $options),
            new \Twig_SimpleFunction('textArea', function($parameters) {
                return \Phalcon\Tag::textArea($parameters);
            }, $options),
            new \Twig_SimpleFunction('form', function($parameters = array()) {
                return \Phalcon\Tag::form($parameters);
            }, $options),
            new \Twig_SimpleFunction('endForm', function() {
                return \Phalcon\Tag::endForm();
            }, $options),
            new \Twig_SimpleFunction('getTitle', function() {
                return \Phalcon\Tag::getTitle();
            }, $options),
            new \Twig_SimpleFunction('getTitle', function() {
                return \Phalcon\Tag::getTitle();
            }, $options),
            new \Twig_SimpleFunction('stylesheetLink', function($parameters = null, $local = true) {
                return \Phalcon\Tag::stylesheetLink($parameters, $local);
            }, $options),
            new \Twig_SimpleFunction('javascriptInclude', function($parameters = null, $local = true) {
                return \Phalcon\Tag::javascriptInclude($parameters, $local);
            }, $options),
            new \Twig_SimpleFunction('image', function($parameters) {
                return \Phalcon\Tag::image($parameters);
            }, $options),
            new \Twig_SimpleFunction('friendlyTitle', function($text, $separator = null, $lowercase = true) {
                return \Phalcon\Tag::friendlyTitle($text, $separator, $lowercase);
            }, $options),
            new \Twig_SimpleFunction('getDocType', function() {
                return \Phalcon\Tag::getDocType();
            }, $options)
        );

        foreach ($functions as $function) {
            $this->_twig->addFunction($function);
        }
    }

    /**
     * Renders a view
     *
     * @param string $path
     * @param array $params
     * @param boolean $mustClean
     */
    public function render($path, $params, $mustClean=false)
    {
        $view = $this->_view;
        if (!isset($params['content'])) {
            $params['content'] = $view->getContent();
        }

        if (!isset($params['view'])) {
{'fraction_non_alphanumeric': 0.1406706273285671, 'fraction_numerical': 0.0001006947940791461, 'mean_word_length': 2.1440329218106995, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 22, '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': '2636097', 'n_tokens_mistral': 2671, 'n_tokens_neox': 2624, 'n_words': 468}