本文整理汇总了PHP中Smarty_Internal_Template::loadCompiler方法的典型用法代码示例。如果您正苦于以下问题:PHP Smarty_Internal_Template::loadCompiler方法的具体用法?PHP Smarty_Internal_Template::loadCompiler怎么用?PHP Smarty_Internal_Template::loadCompiler使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Smarty_Internal_Template
的用法示例。
在下文中一共展示了Smarty_Internal_Template::loadCompiler方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: process
/**
* compile template 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)
{
$compiled =& $_smarty_tpl->compiled;
$compiled->file_dependency = array();
$compiled->includes = array();
$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));
} 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;
}
示例2: compileTemplateSource
/**
* compile template from source
*
* @param Smarty_Internal_Template $_template
*
* @return string
* @throws Exception
*/
public function compileTemplateSource(Smarty_Internal_Template $_template)
{
$this->file_dependency = array();
$this->includes = array();
$this->nocache_hash = null;
$this->unifunc = null;
// compile locking
if (!$_template->source->handler->recompiled) {
if ($saved_timestamp = $this->getTimeStamp()) {
touch($this->filepath);
}
}
// call compiler
try {
$_template->loadCompiler();
$code = $_template->compiler->compileTemplate($_template);
} catch (Exception $e) {
// restore old timestamp in case of error
if (!$_template->source->handler->recompiled && $saved_timestamp) {
touch($this->filepath, $saved_timestamp);
}
throw $e;
}
// compiling succeeded
if ($_template->compiler->write_compiled_code) {
// write compiled template
$this->write($_template, $code);
$code = '';
}
// release compiler object to free memory
unset($_template->compiler);
return $code;
}
示例3: compileInlineTemplate
/**
* Compile inline sub template
*
* @param \Smarty_Internal_SmartyTemplateCompiler $compiler
* @param \Smarty_Internal_Template $tpl
* @param string $t_hash
*
* @return bool
*/
public function compileInlineTemplate(Smarty_Internal_SmartyTemplateCompiler $compiler, Smarty_Internal_Template $tpl, $t_hash)
{
$uid = $tpl->source->type . $tpl->source->uid;
if (!$tpl->source->handler->uncompiled && $tpl->source->exists) {
$compiler->parent_compiler->mergedSubTemplatesData[$uid][$t_hash]['uid'] = $tpl->source->uid;
if (isset($compiler->template->inheritance)) {
$tpl->inheritance = clone $compiler->template->inheritance;
}
$tpl->compiled = new Smarty_Template_Compiled();
$tpl->compiled->nocache_hash = $compiler->parent_compiler->template->compiled->nocache_hash;
$tpl->loadCompiler();
// save unique function name
$compiler->parent_compiler->mergedSubTemplatesData[$uid][$t_hash]['func'] = $tpl->compiled->unifunc = 'content_' . str_replace(array('.', ','), '_', uniqid('', true));
// make sure whole chain gets compiled
$tpl->mustCompile = true;
$compiler->parent_compiler->mergedSubTemplatesData[$uid][$t_hash]['nocache_hash'] = $tpl->compiled->nocache_hash;
if ($compiler->template->source->type == 'file') {
$sourceInfo = $compiler->template->source->filepath;
} else {
$basename = $compiler->template->source->handler->getBasename($compiler->template->source);
$sourceInfo = $compiler->template->source->type . ':' . ($basename ? $basename : $compiler->template->source->name);
}
// get compiled code
$compiled_code = "<?php\n\n";
$compiled_code .= "/* Start inline template \"{$sourceInfo}\" =============================*/\n";
$compiled_code .= "function {$tpl->compiled->unifunc} (\$_smarty_tpl) {\n";
$compiled_code .= "?>\n" . $tpl->compiler->compileTemplateSource($tpl, null, $compiler->parent_compiler);
$compiled_code .= "<?php\n";
$compiled_code .= "}\n?>\n";
$compiled_code .= $tpl->compiler->postFilter($tpl->compiler->blockOrFunctionCode);
$compiled_code .= "<?php\n\n";
$compiled_code .= "/* End inline template \"{$sourceInfo}\" =============================*/\n";
$compiled_code .= "?>";
unset($tpl->compiler);
if ($tpl->compiled->has_nocache_code) {
// replace nocache_hash
$compiled_code = str_replace("{$tpl->compiled->nocache_hash}", $compiler->template->compiled->nocache_hash, $compiled_code);
$compiler->template->compiled->has_nocache_code = true;
}
$compiler->parent_compiler->mergedSubTemplatesCode[$tpl->compiled->unifunc] = $compiled_code;
return true;
} else {
return false;
}
}
示例4: compileTemplateSource
/**
* compile template from source
*
* @param Smarty_Internal_Template $_template
*
* @return string
* @throws Exception
*/
public function compileTemplateSource(Smarty_Internal_Template $_template)
{
// compile locking
if (!$_template->source->recompiled) {
if ($saved_timestamp = $_template->compiled->timestamp) {
touch($_template->compiled->filepath);
}
}
$level = ob_get_level();
try {
$_template->loadCompiler();
$code = $_template->compiler->compileTemplate($_template);
} catch (Exception $e) {
$_template->context = null;
while (ob_get_level() > $level) {
ob_end_clean();
}
// restore old timestamp in case of error
if (!$_template->source->recompiled && $saved_timestamp) {
touch($_template->compiled->filepath, $saved_timestamp);
}
throw $e;
}
// compiling succeeded
if ($_template->compiler->write_compiled_code) {
// write compiled template
$this->write($_template, $code);
$code = '';
}
// release compiler object to free memory
unset($_template->compiler);
return $code;
}
示例5: compileTemplateSource
/**
* compile template from source
*
* @param Smarty_Internal_Template $_template
*
* @throws Exception
*/
public function compileTemplateSource(Smarty_Internal_Template $_template)
{
$this->file_dependency = array();
$this->includes = array();
$this->nocache_hash = null;
$this->unifunc = null;
// compile locking
$saved_timestamp = $_template->source->handler->recompiled ? false : $this->getTimeStamp();
if ($saved_timestamp) {
touch($this->filepath);
}
// 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) {
touch($this->filepath, $saved_timestamp);
}
unset($_template->compiler);
throw $e;
}
// release compiler object to free memory
unset($_template->compiler);
}
示例6: compileTemplateSource
/**
* compile template from source
*
* @param Smarty_Internal_Template $_template
*
* @throws Exception
*/
public function compileTemplateSource(Smarty_Internal_Template $_template)
{
$this->file_dependency = array();
$this->includes = array();
$this->nocache_hash = null;
$this->unifunc = null;
// compile locking
if ($saved_timestamp = $this->getTimeStamp()) {
touch($this->filepath);
}
// call compiler
$_template->loadCompiler();
$this->write($_template, $_template->compiler->compileTemplate($_template));
// release compiler object to free memory
unset($_template->compiler);
}