Latte\Engine::loadTemplate PHP Method

loadTemplate() private method

private loadTemplate ( $name ) : void
return void
    private function loadTemplate($name)
    {
        if (!$this->tempDirectory) {
            $code = $this->compile($name);
            if (@eval('?>' . $code) === FALSE) {
                // @ is escalated to exception
                throw (new CompileException('Error in template: ' . error_get_last()['message']))->setSource($code, error_get_last()['line'], "{$name} (compiled)");
            }
            return;
        }
        $file = $this->getCacheFile($name);
        if (!$this->isExpired($file, $name) && @(include $file) !== FALSE) {
            // @ - file may not exist
            return;
        }
        if (!is_dir($this->tempDirectory)) {
            @mkdir($this->tempDirectory);
            // @ - directory may already exist
        }
        $handle = fopen("{$file}.lock", 'c+');
        if (!$handle || !flock($handle, LOCK_EX)) {
            throw new \RuntimeException("Unable to acquire exclusive lock '{$file}.lock'.");
        }
        if (!is_file($file) || $this->isExpired($file, $name)) {
            $code = $this->compile($name);
            if (file_put_contents("{$file}.tmp", $code) !== strlen($code) || !rename("{$file}.tmp", $file)) {
                @unlink("{$file}.tmp");
                // @ - file may not exist
                throw new \RuntimeException("Unable to create '{$file}'.");
            } elseif (function_exists('opcache_invalidate')) {
                @opcache_invalidate($file, TRUE);
                // @ can be restricted
            }
        }
        if ((include $file) === FALSE) {
            throw new \RuntimeException("Unable to load '{$file}'.");
        }
        flock($handle, LOCK_UN);
        fclose($handle);
        @unlink("{$file}.lock");
        // @ file may become locked on Windows
    }