converted 3 public properties on Template into getters/setters. unified Template creation code. Provided a getter/setter for the has_nocache_code property. Removed the useless DataObject class. Fixed a few tests. Removed the variable-allow-php-templates property from the docs.

This commit is contained in:
Simon Wisselink
2023-01-13 00:04:08 +01:00
parent 541f0821f0
commit e0f2c36d4d
49 changed files with 723 additions and 922 deletions

View File

@@ -30,11 +30,13 @@ abstract class RecompiledPlugin extends BasePlugin {
public $recompiled = true;
/**
* Resource does implement populateCompiledFilepath() method
* Flag if resource does allow compilation
*
* @var bool
* @return bool
*/
public $hasCompiledHandler = true;
public function supportsCompiledTemplates(): bool {
return false;
}
/**
* compile template from source
@@ -44,45 +46,27 @@ abstract class RecompiledPlugin extends BasePlugin {
* @throws Exception
*/
public function process(Template $_smarty_tpl) {
$compiled = &$_smarty_tpl->compiled;
$compiled = $_smarty_tpl->getCompiled();
$compiled->file_dependency = [];
$compiled->includes = [];
$compiled->nocache_hash = null;
$compiled->unifunc = null;
$level = ob_get_level();
ob_start();
$_smarty_tpl->loadCompiler();
// call compiler
try {
eval('?>' . $_smarty_tpl->compiler->compileTemplate($_smarty_tpl));
eval('?>' . $_smarty_tpl->getCompiler()->compileTemplate($_smarty_tpl));
} catch (\Exception $e) {
unset($_smarty_tpl->compiler);
while (ob_get_level() > $level) {
ob_end_clean();
}
throw $e;
}
// release compiler object to free memory
unset($_smarty_tpl->compiler);
ob_get_clean();
$compiled->timestamp = time();
$compiled->exists = true;
}
/**
* populate Compiled Object with compiled filepath
*
* @param Compiled $compiled compiled object
* @param Template $_template template object
*
* @return void
*/
public function populateCompiledFilepath(Compiled $compiled, Template $_template) {
$compiled->filepath = false;
$compiled->timestamp = false;
$compiled->exists = false;
}
/*
* Disable timestamp checks for recompiled resource.
*