public function getCompiledTemplate(Core $core, ICompiler $compiler = null)
    {
        $compiledFile = $this->getCompiledFilename($core);

        if ($this->compilationEnforced !== true && isset(self::$cache['compiled'][$this->compileId]) === true) {
            // already checked, return compiled file
        } elseif ($this->compilationEnforced !== true && $this->isValidCompiledFile($compiledFile)) {
            // template is compiled
            self::$cache['compiled'][$this->compileId] = true;
        } else {
            // compiles the template
            $this->compilationEnforced = false;

            if ($compiler === null) {
                $compiler = $core->getDefaultCompilerFactory($this->getResourceName());

                if ($compiler === null || $compiler === array('Dwoo\Compiler', 'compilerFactory')) {
                    $compiler = Compiler::compilerFactory();
                } else {
                    $compiler = call_user_func($compiler);
                }
            }

            $this->compiler = $compiler;

            $compiler->setCustomPlugins($core->getCustomPlugins());
            $compiler->setSecurityPolicy($core->getSecurityPolicy());
            $this->makeDirectory(dirname($compiledFile), $core->getCompileDir());
            file_put_contents($compiledFile, $compiler->compile($core, $this));
            if ($this->chmod !== null) {
                chmod($compiledFile, $this->chmod);
            }

            if (extension_loaded('Zend OPcache')) {
                opcache_invalidate($compiledFile);
            } elseif (extension_loaded('apc') && ini_get('apc.enabled')) {
                apc_delete_file($compiledFile);
            }

            self::$cache['compiled'][$this->compileId] = true;
        }

        return $compiledFile;
    }