<commit_before><?php
namespace Smartbox\Integration\FrameworkBundle\Util;

use Smartbox\Integration\FrameworkBundle\Messages\Exchange;
use Smartbox\Integration\FrameworkBundle\Traits\UsesMapper;
use Smartbox\Integration\FrameworkBundle\Traits\UsesSerializer;
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;

class ExpressionEvaluator
{
    use UsesSerializer;
    use UsesMapper;

    /** @var ExpressionLanguage */
    protected $language;

    public function __construct()
    {
        $cache = new ApcParserCache();
        $this->language = new ExpressionLanguage($cache);
        // Register any providers here
    }

    public function getExchangeExposedVars(){
        return array(
            'exchange',
            'msg',
            'headers',
            'body',
            'serializer',
            'mapper'
        );
    }

    public function evaluateWithVars($expression, $vars)
    {
        $vars = array_merge($vars,[
            'serializer' => $this->getSerializer(),
            'mapper' => $this->getMapper()
        ]);

        return $this->language->evaluate($expression, $vars);
    }

    public function evaluateWithExchange($expression, Exchange $exchange)
    {
        $body = $exchange->getIn()->getBody();

        return $this->language->evaluate($expression, array(
            'exchange' => $exchange,
            'msg' => $exchange->getIn(),
            'headers' => $exchange->getIn()->getHeaders(),
            'body' => $body,
            'serializer' => $this->getSerializer(),
            'mapper' => $this->getMapper()
        ));
    }

    /**
     * @param $expression
     * @param array $names
     * @return string
     */
    public function compile($expression, $names = array())
    {
        return $this->language->compile($expression, $names);
    }

}<commit_msg>Added variable now (current datetime) in ExpressionEvaluator<commit_after><?php
namespace Smartbox\Integration\FrameworkBundle\Util;

use Smartbox\Integration\FrameworkBundle\Messages\Exchange;
use Smartbox\Integration\FrameworkBundle\Traits\UsesMapper;
use Smartbox\Integration\FrameworkBundle\Traits\UsesSerializer;
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;

class ExpressionEvaluator
{
    use UsesSerializer;
    use UsesMapper;

    /** @var ExpressionLanguage */
    protected $language;

    public function __construct()
    {
        $cache = new ApcParserCache();
        $this->language = new ExpressionLanguage($cache);
        // Register any providers here
    }

    public function getExchangeExposedVars(){
        return array(
            'exchange',
            'msg',
            'headers',
            'body',
            'serializer',
            'mapper',
            'now'
        );
    }

    public function evaluateWithVars($expression, $vars)
    {
        $vars = array_merge($vars,[
            'serializer' => $this->getSerializer(),
            'mapper' => $this->getMapper()
        ]);

        return $this->language->evaluate($expression, $vars);
    }

    public function evaluateWithExchange($expression, Exchange $exchange)
    {
        $body = $exchange->getIn()->getBody();

        return $this->language->evaluate($expression, array(
            'exchange' => $exchange,
            'msg' => $exchange->getIn(),
            'headers' => $exchange->getIn()->getHeaders(),
            'body' => $body,
            'serializer' => $this->getSerializer(),
            'mapper' => $this->getMapper(),
            'now' => new \DateTime(),
        ));
    }

    /**
     * @param $expression
     * @param array $names
     * @return string
     */
    public function compile($expression, $names = array())
    {
        return $this->language->compile($expression, $names);
    }

}
{'fraction_non_alphanumeric': 0.13527080581241743, 'fraction_numerical': 0.0, 'mean_word_length': 2.3894359892569383, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 52, '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': '6172899', 'n_tokens_mistral': 1031, 'n_tokens_neox': 987, 'n_words': 200}