mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-05-03 17:22:20 +09:00
Support disabling template cache and alternative version directive
This commit is contained in:
parent
a5c0f61b67
commit
7263fc9a5b
1 changed files with 19 additions and 2 deletions
|
|
@ -23,7 +23,8 @@ class Template
|
||||||
public $absolute_path;
|
public $absolute_path;
|
||||||
public $relative_path;
|
public $relative_path;
|
||||||
public $cache_path;
|
public $cache_path;
|
||||||
public $ob_level;
|
public $cache_enabled = true;
|
||||||
|
public $ob_level = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Static properties
|
* Static properties
|
||||||
|
|
@ -120,6 +121,16 @@ class Template
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Disable caching.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function disableCache(): void
|
||||||
|
{
|
||||||
|
$this->cache_enabled = false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compile and execute a template file.
|
* Compile and execute a template file.
|
||||||
*
|
*
|
||||||
|
|
@ -174,7 +185,7 @@ class Template
|
||||||
}
|
}
|
||||||
|
|
||||||
// If a cached result does not exist, or if it is stale, compile again.
|
// If a cached result does not exist, or if it is stale, compile again.
|
||||||
if (!Storage::exists($this->cache_path) || filemtime($this->cache_path) < $latest_mtime)
|
if (!Storage::exists($this->cache_path) || filemtime($this->cache_path) < $latest_mtime || !$this->cache_enabled)
|
||||||
{
|
{
|
||||||
$content = $this->_convert();
|
$content = $this->_convert();
|
||||||
if (!Storage::write($this->cache_path, $content))
|
if (!Storage::write($this->cache_path, $content))
|
||||||
|
|
@ -248,6 +259,12 @@ class Template
|
||||||
return sprintf('<?php $this->config->%s = %s; ?>', $match[1], var_export($this->config->{$match[1]}, true));
|
return sprintf('<?php $this->config->%s = %s; ?>', $match[1], var_export($this->config->{$match[1]}, true));
|
||||||
}, $content);
|
}, $content);
|
||||||
|
|
||||||
|
// Check the alternative version directive: @version(2)
|
||||||
|
if (preg_match('/(?:^|\s)@version\(([0-9]+)\)/', $content, $matches))
|
||||||
|
{
|
||||||
|
$this->config->version = intval($matches[1]);
|
||||||
|
}
|
||||||
|
|
||||||
// Turn autoescape on if the version is 2 or greater.
|
// Turn autoescape on if the version is 2 or greater.
|
||||||
if ($this->config->version >= 2)
|
if ($this->config->version >= 2)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue