<commit_before><?php
/**
 * Copyright (C) 2015 <NAME>
 *
 * Defines methods for compiling views
 */
namespace Opulence\Views\Compilers;
use Opulence\Views\Caching\ICache;
use Opulence\Views\IView;

class Compiler implements ICompiler
{
    /** @var ICompilerRegistry The compiler registry */
    protected $registry = null;
    /** @var ICache The view cache */
    protected $cache = null;

    /**
     * @param ICompilerRegistry $registry The compiler registry
     * @param ICache $cache The view cache
     */
    public function __construct(ICompilerRegistry $registry, ICache $cache)
    {
        $this->registry = $registry;
        $this->cache = $cache;
    }

    /**
     * @inheritdoc
     */
    public function compile(IView $view, $contents = null)
    {
        if($contents === null)
        {
            $contents = $view->getContents();
        }

        if($this->cache->has($contents, $view->getVars()))
        {
            return $this->cache->get($contents, $view->getVars());
        }

        $compiledContents = $this->registry->get($view)->compile($view, $contents);
        $this->cache->set($compiledContents, $contents, $view->getVars());

        return $compiledContents;
    }
} <commit_msg>Fixed bug that would never find view in cache because it was written to cache with a few compiler-set variables (eg __opulenceViewCompiler)<commit_after><?php
/**
 * Copyright (C) 2015 <NAME>
 *
 * Defines methods for compiling views
 */
namespace Opulence\Views\Compilers;
use Opulence\Views\Caching\ICache;
use Opulence\Views\IView;

class Compiler implements ICompiler
{
    /** @var ICompilerRegistry The compiler registry */
    protected $registry = null;
    /** @var ICache The view cache */
    protected $cache = null;

    /**
     * @param ICompilerRegistry $registry The compiler registry
     * @param ICache $cache The view cache
     */
    public function __construct(ICompilerRegistry $registry, ICache $cache)
    {
        $this->registry = $registry;
        $this->cache = $cache;
    }

    /**
     * @inheritdoc
     */
    public function compile(IView $view, $contents = null)
    {
        if($contents === null)
        {
            $contents = $view->getContents();
        }

        $varsBeforeCompiling = $view->getVars();

        if($this->cache->has($contents, $varsBeforeCompiling))
        {
            return $this->cache->get($contents, $view->getVars());
        }

        $compiledContents = $this->registry->get($view)->compile($view, $contents);
        $this->cache->set($compiledContents, $contents, $varsBeforeCompiling);

        return $compiledContents;
    }
} 
{'fraction_non_alphanumeric': 0.13567649281934996, 'fraction_numerical': 0.0030234315948601664, 'mean_word_length': 2.676388888888889, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 34, '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': '4785796', 'n_tokens_mistral': 765, 'n_tokens_neox': 738, 'n_words': 187}