<commit_before><?php
/**
 * Additional functions and filters for Twig
 *
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 */

namespace Skeleton\Template\Twig\Extension;

class Common extends \Twig_Extension {

	private $environment;

	/**
	 * Init runtime
	 *
	 * @access public
	 */
	public function initRuntime(\Twig_Environment $environment) {
        parent::initRuntime($environment);
        $this->environment = $environment;
    }

	/**
	 * Returns a list of globals
	 *
	 * @return array
	 */
	public function getGlobals() {
		$templates = [
			'base' => '_default/macro.base.twig',
			'form' => '_default/form.base.twig',
		];

		$globals = [];
		foreach ($templates as $key => $template) {
			try {
				$loaded_template = $this->environment->loadTemplate('_default/macro.base.twig');
				$globals[$key] = $loaded_template;
			} catch (\Twig_Error_Loader $e) { }
		}

		return $globals;
	}

    /**
     * Returns a list of filters
     *
     * @return array
     */
    public function getFilters() {
        return [
			new \Twig_SimpleFilter('print_r', [$this, 'print_r_filter'], ['is_safe' => ['html']]),
			new \Twig_SimpleFilter('json_decode', [$this, 'json_decode_filter'], ['is_safe' => ['html']]),
			new \Twig_SimpleFilter('serialize', [$this, 'serialize_filter'], ['is_safe' => ['html']]),
			new \Twig_SimpleFilter('round', [$this, 'round_filter'], ['is_safe' => ['html']]),<commit_msg>Fix loading templates in global scope<commit_after><?php
/**
 * Additional functions and filters for Twig
 *
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 */

namespace Skeleton\Template\Twig\Extension;

class Common extends \Twig_Extension {

	private $environment;

	/**
	 * Init runtime
	 *
	 * @access public
	 */
	public function initRuntime(\Twig_Environment $environment) {
        parent::initRuntime($environment);
        $this->environment = $environment;
    }

	/**
	 * Returns a list of globals
	 *
	 * @return array
	 */
	public function getGlobals() {
		$templates = [
			'base' => '_default/macro.base.twig',
			'form' => '_default/form.base.twig',
		];

		$globals = [];
		foreach ($templates as $key => $template) {
			try {
				$loaded_template = $this->environment->loadTemplate($template);
				$globals[$key] = $loaded_template;
			} catch (\Twig_Error_Loader $e) { }
		}

		return $globals;
	}

    /**
     * Returns a list of filters
     *
     * @return array
     */
    public function getFilters() {
        return [
			new \Twig_SimpleFilter('print_r', [$this, 'print_r_filter'], ['is_safe' => ['html']]),
			new \Twig_SimpleFilter('json_decode', [$this, 'json_decode_filter'], ['is_safe' => ['html']]),
			new \Twig_SimpleFilter('serialize', [$this, 'serialize_filter'], ['is_safe' => ['html']]),
			new \Twig_SimpleFilter('round', [$this, 'round_filter'], ['is_safe' => ['html']]),
{'fraction_non_alphanumeric': 0.17868448821667252, 'fraction_numerical': 0.0, 'mean_word_length': 3.5504, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 35, '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': '246187', 'n_tokens_mistral': 1005, 'n_tokens_neox': 911, 'n_words': 200}