Prepend code in postprocessing, not preprocessing

This commit is contained in:
Kijin Sung 2023-10-15 23:26:04 +09:00
parent 1067588754
commit 6893e08553

View file

@ -120,15 +120,6 @@ class TemplateParser_v2
*/
protected function _preprocess(string $content): string
{
// Force the version number.
if (!str_contains($content, '$this->config->version'))
{
$content = '<?php $this->config->version = 2; ?>' . $content;
}
// Prevent direct invocation.
$content = '<?php if (!defined("RX_VERSION")) exit(); ?>' . $content;
// Remove trailing whitespace.
$content = preg_replace('#[\x20\x09]+$#m', '', $content);
@ -951,6 +942,15 @@ class TemplateParser_v2
'#@(\{\{)#',
], '$1', $content);
// Prepend the version number.
if (!str_contains($content, '$this->config->version'))
{
$content = '<?php $this->config->version = 2; ?>' . $content;
}
// Prepend constant check to block direct invocation of the cache file.
$content = '<?php if (!defined("RX_VERSION")) exit(); ?>' . $content;
// Remove unnecessary spaces before and after PHP tags.
$content = preg_replace([
'#^[\x20\x09]+(<\?(?:php\b|=))#m',