<commit_before><?php
/**
 * Date: 06.12.12
 * Time: 3:59
 * Author: <NAME>
 */

namespace Axis\S1\HybridTemplating\Engine;

class TwigTemplatingEngine extends BaseTemplatingEngine
{
  /** @var \Twig_Environment */
  protected $twig;

  /**
   * @param \Twig_Environment $twig
   * @param string $extension
   */
  function __construct($twig, $extension = 'twig')
  {
    $this->twig = $twig;
    parent::__construct($extension);
  }

  /**
   * @param string $template
   * @param array $vars
   * @return string
   */
  public function render($template, $vars = array())
  {
    /** @var $loader \Twig_Loader_Filesystem */
    $loader = $this->twig->getLoader();
    $loader->setPaths((array) realpath(dirname($template)));
    return $this->twig->render(basename($template), $vars);
  }

  public function isEscapingNeeded()
  {
    return false;
  }
}<commit_msg>Fixed bug with TwigLoader (see Card #210)<commit_after><?php
/**
 * Date: 06.12.12
 * Time: 3:59
 * Author: <NAME>
 */

namespace Axis\S1\HybridTemplating\Engine;

class TwigTemplatingEngine extends BaseTemplatingEngine
{
  /** @var \Twig_Environment */
  protected $twig;

  /**
   * @param \Twig_Environment $twig
   * @param string $extension
   */
  function __construct($twig, $extension = 'twig')
  {
    $this->twig = $twig;
    parent::__construct($extension);
  }

  /**
   * @param string $template
   * @param array $vars
   * @return string
   */
  public function render($template, $vars = array())
  {
    /** @var $loader \Twig_Loader_Filesystem */
   $paths = $this->twig->getLoader()->getPaths($namespace);
    $templateDir = realpath(dirname($template));
    if (!in_array($templateDir, $paths))
    {
      array_unshift($paths, $templateDir);
    }
    $loader->setPaths($paths, $namespace);
    return $this->twig->render(basename($template), $vars);
  }

  public function isEscapingNeeded()
  {
    return false;
  }
}
{'fraction_non_alphanumeric': 0.16360776088096488, 'fraction_numerical': 0.012060828526481384, 'mean_word_length': 3.4475524475524475, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 18, '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': '2274210', 'n_tokens_mistral': 669, 'n_tokens_neox': 646, 'n_words': 129}