summaryrefslogtreecommitdiff
path: root/lib/smarty3/sysplugins/smarty_template_compiled.php
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2018-10-18 02:40:38 +0200
committeremkael <emkael@tlen.pl>2018-10-18 02:40:38 +0200
commiteab8a101e7a3fcbb41e01a574985e06c5a3775de (patch)
tree60f201da5984b0c3638d10da02bba42b61aa3177 /lib/smarty3/sysplugins/smarty_template_compiled.php
parent7f38be342c1495aeca418286c15c25c18ac9e142 (diff)
Updating Smarty
Diffstat (limited to 'lib/smarty3/sysplugins/smarty_template_compiled.php')
-rw-r--r--lib/smarty3/sysplugins/smarty_template_compiled.php162
1 files changed, 89 insertions, 73 deletions
diff --git a/lib/smarty3/sysplugins/smarty_template_compiled.php b/lib/smarty3/sysplugins/smarty_template_compiled.php
index 832c8e1..37d8f0a 100644
--- a/lib/smarty3/sysplugins/smarty_template_compiled.php
+++ b/lib/smarty3/sysplugins/smarty_template_compiled.php
@@ -7,11 +7,10 @@
* @package Smarty
* @subpackage TemplateResources
* @author Rodney Rehm
- * @property string $content compiled content
+ * @property string $content compiled content
*/
class Smarty_Template_Compiled extends Smarty_Template_Resource_Base
{
-
/**
* nocache hash
*
@@ -22,11 +21,11 @@ class Smarty_Template_Compiled extends Smarty_Template_Resource_Base
/**
* get a Compiled Object of this source
*
- * @param Smarty_Internal_Template $_template template object
+ * @param Smarty_Internal_Template $_template template object
*
* @return Smarty_Template_Compiled compiled object
*/
- static function load($_template)
+ public static function load($_template)
{
$compiled = new Smarty_Template_Compiled();
if ($_template->source->handler->hasCompiledHandler) {
@@ -49,19 +48,22 @@ class Smarty_Template_Compiled extends Smarty_Template_Resource_Base
$this->filepath = $smarty->getCompileDir();
if (isset($_template->compile_id)) {
$this->filepath .= preg_replace('![^\w]+!', '_', $_template->compile_id) .
- ($smarty->use_sub_dirs ? DS : '^');
+ ($smarty->use_sub_dirs ? DIRECTORY_SEPARATOR : '^');
}
// if use_sub_dirs, break file into directories
if ($smarty->use_sub_dirs) {
- $this->filepath .= $source->uid[ 0 ] . $source->uid[ 1 ] . DS . $source->uid[ 2 ] . $source->uid[ 3 ] . DS .
- $source->uid[ 4 ] . $source->uid[ 5 ] . DS;
+ $this->filepath .= $source->uid[ 0 ] . $source->uid[ 1 ] . DIRECTORY_SEPARATOR . $source->uid[ 2 ] .
+ $source->uid[ 3 ] . DIRECTORY_SEPARATOR . $source->uid[ 4 ] . $source->uid[ 5 ] .
+ DIRECTORY_SEPARATOR;
}
$this->filepath .= $source->uid . '_';
if ($source->isConfig) {
- $this->filepath .= (int) $smarty->config_read_hidden + (int) $smarty->config_booleanize * 2 +
- (int) $smarty->config_overwrite * 4;
+ $this->filepath .= (int)$smarty->config_read_hidden + (int)$smarty->config_booleanize * 2 +
+ (int)$smarty->config_overwrite * 4;
} else {
- $this->filepath .= (int) $smarty->merge_compiled_includes + (int) $smarty->escape_html * 2;
+ $this->filepath .= (int)$smarty->merge_compiled_includes + (int)$smarty->escape_html * 2 +
+ (($smarty->merge_compiled_includes && $source->type === 'extends') ?
+ (int)$smarty->extends_recursion * 4 : 0);
}
$this->filepath .= '.' . $source->type;
$basename = $source->handler->getBasename($source);
@@ -79,64 +81,6 @@ class Smarty_Template_Compiled extends Smarty_Template_Resource_Base
}
/**
- * load compiled template or compile from source
- *
- * @param Smarty_Internal_Template $_smarty_tpl do not change variable name, is used by compiled template
- *
- * @throws Exception
- */
- public function process(Smarty_Internal_Template $_smarty_tpl)
- {
- $source = &$_smarty_tpl->source;
- $smarty = &$_smarty_tpl->smarty;
- if ($source->handler->recompiled) {
- $source->handler->process($_smarty_tpl);
- } elseif (!$source->handler->uncompiled) {
- if (!$this->exists || $smarty->force_compile ||
- ($smarty->compile_check && $source->getTimeStamp() > $this->getTimeStamp())
- ) {
- $this->compileTemplateSource($_smarty_tpl);
- $compileCheck = $smarty->compile_check;
- $smarty->compile_check = false;
- $this->loadCompiledTemplate($_smarty_tpl);
- $smarty->compile_check = $compileCheck;
- } else {
- $_smarty_tpl->mustCompile = true;
- @include($this->filepath);
- if ($_smarty_tpl->mustCompile) {
- $this->compileTemplateSource($_smarty_tpl);
- $compileCheck = $smarty->compile_check;
- $smarty->compile_check = false;
- $this->loadCompiledTemplate($_smarty_tpl);
- $smarty->compile_check = $compileCheck;
- }
- }
- $_smarty_tpl->_subTemplateRegister();
- $this->processed = true;
- }
- }
-
- /**
- * Load fresh compiled template by including the PHP file
- * HHVM requires a work around because of a PHP incompatibility
- *
- * @param \Smarty_Internal_Template $_smarty_tpl do not change variable name, is used by compiled template
- */
- private function loadCompiledTemplate(Smarty_Internal_Template $_smarty_tpl)
- {
- if (function_exists('opcache_invalidate') && strlen(ini_get("opcache.restrict_api")) < 1) {
- opcache_invalidate($this->filepath, true);
- } elseif (function_exists('apc_compile_file')) {
- apc_compile_file($this->filepath);
- }
- if (defined('HHVM_VERSION')) {
- eval("?>" . file_get_contents($this->filepath));
- } else {
- include($this->filepath);
- }
- }
-
- /**
* render compiled template code
*
* @param Smarty_Internal_Template $_template
@@ -178,6 +122,44 @@ class Smarty_Template_Compiled extends Smarty_Template_Resource_Base
}
/**
+ * load compiled template or compile from source
+ *
+ * @param Smarty_Internal_Template $_smarty_tpl do not change variable name, is used by compiled template
+ *
+ * @throws Exception
+ */
+ public function process(Smarty_Internal_Template $_smarty_tpl)
+ {
+ $source = &$_smarty_tpl->source;
+ $smarty = &$_smarty_tpl->smarty;
+ if ($source->handler->recompiled) {
+ $source->handler->process($_smarty_tpl);
+ } elseif (!$source->handler->uncompiled) {
+ if (!$this->exists || $smarty->force_compile
+ || ($_smarty_tpl->compile_check && $source->getTimeStamp() > $this->getTimeStamp())
+ ) {
+ $this->compileTemplateSource($_smarty_tpl);
+ $compileCheck = $_smarty_tpl->compile_check;
+ $_smarty_tpl->compile_check = Smarty::COMPILECHECK_OFF;
+ $this->loadCompiledTemplate($_smarty_tpl);
+ $_smarty_tpl->compile_check = $compileCheck;
+ } else {
+ $_smarty_tpl->mustCompile = true;
+ @include $this->filepath;
+ if ($_smarty_tpl->mustCompile) {
+ $this->compileTemplateSource($_smarty_tpl);
+ $compileCheck = $_smarty_tpl->compile_check;
+ $_smarty_tpl->compile_check = Smarty::COMPILECHECK_OFF;
+ $this->loadCompiledTemplate($_smarty_tpl);
+ $_smarty_tpl->compile_check = $compileCheck;
+ }
+ }
+ $_smarty_tpl->_subTemplateRegister();
+ $this->processed = true;
+ }
+ }
+
+ /**
* compile template from source
*
* @param Smarty_Internal_Template $_template
@@ -191,12 +173,23 @@ class Smarty_Template_Compiled extends Smarty_Template_Resource_Base
$this->nocache_hash = null;
$this->unifunc = null;
// compile locking
- if ($saved_timestamp = $this->getTimeStamp()) {
+ if ($saved_timestamp = (!$_template->source->handler->recompiled && is_file($this->filepath))) {
+ $saved_timestamp = $this->getTimeStamp();
touch($this->filepath);
}
- // call compiler
- $_template->loadCompiler();
- $this->write($_template, $_template->compiler->compileTemplate($_template));
+ // compile locking
+ try {
+ // call compiler
+ $_template->loadCompiler();
+ $this->write($_template, $_template->compiler->compileTemplate($_template));
+ } catch (Exception $e) {
+ // restore old timestamp in case of error
+ if ($saved_timestamp && is_file($this->filepath)) {
+ touch($this->filepath, $saved_timestamp);
+ }
+ unset($_template->compiler);
+ throw $e;
+ }
// release compiler object to free memory
unset($_template->compiler);
}
@@ -207,7 +200,8 @@ class Smarty_Template_Compiled extends Smarty_Template_Resource_Base
* @param Smarty_Internal_Template $_template template object
* @param string $code compiled code
*
- * @return boolean success
+ * @return bool success
+ * @throws \SmartyException
*/
public function write(Smarty_Internal_Template $_template, $code)
{
@@ -238,4 +232,26 @@ class Smarty_Template_Compiled extends Smarty_Template_Resource_Base
}
return isset($this->content) ? $this->content : false;
}
+
+ /**
+ * Load fresh compiled template by including the PHP file
+ * HHVM requires a work around because of a PHP incompatibility
+ *
+ * @param \Smarty_Internal_Template $_smarty_tpl do not change variable name, is used by compiled template
+ */
+ private function loadCompiledTemplate(Smarty_Internal_Template $_smarty_tpl)
+ {
+ if (function_exists('opcache_invalidate')
+ && (!function_exists('ini_get') || strlen(ini_get("opcache.restrict_api")) < 1)
+ ) {
+ opcache_invalidate($this->filepath, true);
+ } elseif (function_exists('apc_compile_file')) {
+ apc_compile_file($this->filepath);
+ }
+ if (defined('HHVM_VERSION')) {
+ eval('?>' . file_get_contents($this->filepath));
+ } else {
+ include $this->filepath;
+ }
+ }
}