<commit_before><?php

namespace Laiz\Template;

class Template
{
    protected $templateDir = 'template';
    protected $cacheDir = 'cache';
    private $ext = 'html';
    private $vars;

    /**
     * @deprecated
     */
    private $path;
    private $file;

    public function __construct($templateDir = null, $cacheDir = null)
    {
        if ($templateDir)
            $this->templateDir = $templateDir;
        if ($cacheDir)
            $this->cacheDir;

        if (!is_writeable($this->cacheDir))
            throw new \RuntimeException("$cacheDir directory is not writeable.");

        $this->vars = new \StdClass();
    }
    public function setExtension($ext)
    {
        $this->ext = $ext;
    }
    public function setVars($vars)
    {
        $this->vars = $vars;
    }

    /**
     * @deprecated
     */
    public function setPath($path)
    {
        $this->path = $path;
        return $this;
    }

    /**
     * @deprecated
     */
    public function getPath()
    {
        if ($this->path !== null)
            return $this->path;
        return basename($_SERVER['SCRIPT_FILENAME'], '.php');
    }
    public function setFile($file)
    {
        $this->file = $file;
        return $this;
    }
    public function getFile()
    {
        if ($this->file !== null)
            return $this->file;
        return $this->getPath() . '.' . $this->ext;
    }
    public function show($vars = null)
    {
        if ($vars === null)
            $vars = $this->vars;
        $file = $this->getFile();
        $tmplFile = $this->templateDir . '/' . $file;
        $cacheFile = $this->cacheDir . '/' . $file;

        if (!$this->compile($tmplFile, $cacheFile))
            return;

        $this->showCache($cacheFile, $vars);
    }

    public function get($vars = null)
    {
        ob_start();
        $this->show($vars);
        return ob_get_clean();
    }

    protected function show404()
    {
        header($_SERVER['SERVER_PROTOCOL']. " 404 Not Found");

        echo <<<END
            <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
            <html><head>
            <title>404 Not Found</title>
            </head><body><commit_msg>remove setPath and related methods.<commit_after><?php

namespace Laiz\Template;

class Template
{
    protected $templateDir = 'template';
    protected $cacheDir = 'cache';
    private $ext = 'html';
    private $vars;

    private $file;

    public function __construct($templateDir = null, $cacheDir = null)
    {
        if ($templateDir)
            $this->templateDir = $templateDir;
        if ($cacheDir)
            $this->cacheDir;

        if (!is_writeable($this->cacheDir))
            throw new \RuntimeException("$cacheDir directory is not writeable.");

        $this->vars = new \StdClass();
    }
    public function setExtension($ext)
    {
        $this->ext = $ext;
    }
    public function setVars($vars)
    {
        $this->vars = $vars;
    }

    public function setFile($file)
    {
        $this->file = $file;
        return $this;
    }
    public function getFile()
    {
        if ($this->file !== null)
            return $this->file;
        return basename($_SERVER['SCRIPT_FILENAME'], '.php') . '.' . $this->ext;
    }
    public function show($vars = null)
    {
        if ($vars === null)
            $vars = $this->vars;
        $file = $this->getFile();
        $tmplFile = $this->templateDir . '/' . $file;
        $cacheFile = $this->cacheDir . '/' . $file;

        if (!$this->compile($tmplFile, $cacheFile))
            return;

        $this->showCache($cacheFile, $vars);
    }

    public function get($vars = null)
    {
        ob_start();
        $this->show($vars);
        return ob_get_clean();
    }

    protected function show404()
    {
        header($_SERVER['SERVER_PROTOCOL']. " 404 Not Found");

        echo <<<END
            <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
            <html><head>
            <title>404 Not Found</title>
            </head><body>
{'fraction_non_alphanumeric': 0.15455450472872076, 'fraction_numerical': 0.0054753608760577405, 'mean_word_length': 1.8544034090909092, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 55, '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': '5425308', 'n_tokens_mistral': 1240, 'n_tokens_neox': 1197, 'n_words': 271}