<commit_before><?php

namespace Lexik\Bundle\MailerBundle\Message;

use Lexik\Bundle\MailerBundle\Model\EmailInterface;

/**
 * Render each parts of an email.
 *
 * @author <NAME> <<EMAIL>>
 */
class MessageRenderer
{
    /**
     * @var \Twig_Environment
     */
    private $templating;

    /**
     * Construct
     *
     * @param \Twig_Environment $templating
     * @param array $defaultOptions
     */
    public function __construct(\Twig_Environment $templating)
    {
        $this->templating = $templating;

        $this->templating->enableStrictVariables();
    }

    /**
     * Load all templates from the email.
     *
     * @param EmailInterface $email
     */
    public function loadTemplates(EmailInterface $email)
    {
        $this->templating->getLoader()->setTemplate('subject', $email->getSubject());
        $this->templating->getLoader()->setTemplate('from_name', $email->getFromName());

        $layout = $email->getLayoutBody();
        $this->templating->getLoader()->setTemplate('layout', $layout);

        $content = empty($layout) ? $email->getBody() : '{% extends \'layout\' %} {% block content %}' . $email->getBody() . '{% endblock %}';
        $this->templating->getLoader()->setTemplate('content', $content);
    }

    /**
     * Render a template previously loaded.
     *
     * @param string $view
     * @param array $parameters<commit_msg>Changes the twig loader in the MessageRenderer class.<commit_after><?php

namespace Lexik\Bundle\MailerBundle\Message;

use Lexik\Bundle\MailerBundle\Model\EmailInterface;

/**
 * Render each parts of an email.
 *
 * @author <NAME> <<EMAIL>>
 */
class MessageRenderer
{
    /**
     * @var \Twig_Environment
     */
    private $templating;
    
    /**
     * @var array
     */
    private $loaders = array();
    
    /**
     * Construct
     *
     * @param \Twig_Environment $templating
     * @param array $defaultOptions
     */
    public function __construct(\Twig_Environment $templating, $loaders = null)
    {
        $this->templating = $templating;

        $this->templating->enableStrictVariables();
        
        if(is_array($loaders))
        {
            $this->loaders = $loaders;
        }
    }
    
    /**
     * Adds an additional twig loader to the chain loader
     * 
     * @param \Twig_LoaderInterface $loader
     */
    public function addTwigLoader(\Twig_LoaderInterface $loader)
    {
        $chain_loader = new \Twig_Loader_Chain();
    	foreach($this->loaders as $original_loader)
    	{
    		$chain_loader->addLoader($original_loader);
    	}
    	$chain_loader->addLoader($loader);
    	
    	$this->templating->setLoader($chain_loader);
    }

    /**
     * Load all templates from the email.
     *
     * @param EmailInterface $email
     */
    public function loadTemplates(EmailInterface $email)
    {
        $layout = $email->getLayoutBody();
    	$content = empty($layout) ? $email->getBody() : '{% extends \'layout\' %} {% block content %}' . $email->getBody() . '{% endblock %}';
    	
    	$loader = new \Twig_Loader_Array(array(
			'subject'   => $email->getSubject(),
			'from_name' => $email->getFromName(),
			'layout'    => $email->getLayoutBody(),
			'content'   => $content 
    	));
        
    	$this->addTwigLoader($loader);
    }

    /**
     * Render a template previously loaded.
     *
     * @param string $view
     * @param array $parameters
{'fraction_non_alphanumeric': 0.14881127091282653, 'fraction_numerical': 0.0, 'mean_word_length': 2.520661157024793, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 49, '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': '6058835', 'n_tokens_mistral': 1060, 'n_tokens_neox': 1039, 'n_words': 199}