mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-04 18:34:27 +02:00
- improvement internal compiler changes
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
===== 3.1.30-dev ===== (xx.xx.xx)
|
||||
05.02.2016
|
||||
- improvement internal compiler changes
|
||||
|
||||
01.02.2016
|
||||
- bugfix {foreach} compilation failed when $smarty->merge_compiled_includes = true and pre-filters are used.
|
||||
|
||||
|
@@ -121,7 +121,7 @@ class Smarty extends Smarty_Internal_TemplateBase
|
||||
/**
|
||||
* smarty version
|
||||
*/
|
||||
const SMARTY_VERSION = '3.1.30-dev/28';
|
||||
const SMARTY_VERSION = '3.1.30-dev/29';
|
||||
|
||||
/**
|
||||
* define variable scopes
|
||||
|
@@ -49,11 +49,11 @@ class Smarty_Internal_Runtime_CodeFrame
|
||||
$output = "<?php\n";
|
||||
$output .= "/* Smarty version " . Smarty::SMARTY_VERSION . ", created on " . strftime("%Y-%m-%d %H:%M:%S") .
|
||||
"\n from \"" . $_template->source->filepath . "\" */\n\n";
|
||||
|
||||
$output .= "/* @var Smarty_Internal_Template \$_smarty_tpl */\n";
|
||||
$dec = "\$_smarty_tpl->_decodeProperties(\$_smarty_tpl, " . var_export($properties, true) . ',' .
|
||||
($cache ? 'true' : 'false') . ")";
|
||||
$output .= "if ({$dec}) {\n";
|
||||
$output .= "function {$properties['unifunc']} (\$_smarty_tpl) {\n";
|
||||
$output .= "function {$properties['unifunc']} (Smarty_Internal_Template \$_smarty_tpl) {\n";
|
||||
// include code for plugins
|
||||
if (!$cache) {
|
||||
if (!empty($_template->compiled->required_plugins[ 'compiled' ])) {
|
||||
|
@@ -1064,8 +1064,8 @@ abstract class Smarty_Internal_TemplateCompilerBase
|
||||
*/
|
||||
public function getId($input)
|
||||
{
|
||||
if (preg_match('~^[\'"]*([0-9]*[a-zA-Z_]\w*)[\'"]*$~', $input, $match)) {
|
||||
return $match[ 1 ];
|
||||
if (preg_match('~^([\'"]*)([0-9]*[a-zA-Z_]\w*)\1$~', $input, $match)) {
|
||||
return $match[ 2 ];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -1085,6 +1085,53 @@ abstract class Smarty_Internal_TemplateCompilerBase
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set nocache flag in variable or create new variable
|
||||
*
|
||||
* @param string $varName
|
||||
*/
|
||||
public function setNocacheInVariable($varName){
|
||||
// create nocache var to make it know for further compiling
|
||||
if ($_var = $this->getId($varName)) {
|
||||
if (isset($this->template->tpl_vars[ $_var ])) {
|
||||
$this->template->tpl_vars[ $_var ] = clone $this->template->tpl_vars[ $_var ];
|
||||
$this->template->tpl_vars[ $_var ]->nocache = true;
|
||||
} else {
|
||||
$this->template->tpl_vars[ $_var ] = new Smarty_Variable(null, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $_attr tag attributes
|
||||
* @param array $validScopes
|
||||
*
|
||||
* @return int|string
|
||||
* @throws \SmartyCompilerException
|
||||
*/
|
||||
public function convertScope($_attr, $validScopes){
|
||||
$_scope = Smarty::SCOPE_LOCAL;
|
||||
if (isset($_attr[ 'scope' ])) {
|
||||
$_scopeName = trim($_attr[ 'scope' ], "'\"");
|
||||
if (is_numeric($_scopeName) && in_array($_scopeName, $validScopes)) {
|
||||
$_scope = $_scopeName;
|
||||
} elseif (is_string($_scopeName)) {
|
||||
$_scopeName = trim($_scopeName, "'\"");
|
||||
$_scope = isset($validScopes[ $_scopeName ]) ? $validScopes[ $_scopeName ] : false;
|
||||
} else {
|
||||
$_scope = false;
|
||||
}
|
||||
if ($_scope === false) {
|
||||
$err = var_export($_scopeName, true);
|
||||
$this->trigger_template_error("illegal value '{$err}' for \"scope\" attribute", null, true);
|
||||
}
|
||||
if (isset($_attr[ 'bubble_up' ]) && $_attr[ 'bubble_up' ]) {
|
||||
$_scope += Smarty::SCOPE_BUBBLE_UP;
|
||||
}
|
||||
}
|
||||
return $_scope;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate nocache code string
|
||||
*
|
||||
@@ -1166,4 +1213,41 @@ abstract class Smarty_Internal_TemplateCompilerBase
|
||||
$e->template = $this->template->source->filepath;
|
||||
throw $e;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return var_export() value with all white spaces removed
|
||||
*
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getVarExport($value) {
|
||||
return preg_replace('/\s/', '', var_export($value, true));
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if $value contains variable elements
|
||||
*
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return bool|int
|
||||
*/
|
||||
public function isVariable($value){
|
||||
if (is_string($value)) {
|
||||
return preg_match('/[$(]/', $value);
|
||||
}
|
||||
if (is_bool($value) || is_numeric($value)) {
|
||||
return false;
|
||||
}
|
||||
if (is_array($value)) {
|
||||
foreach ($value as $k => $v) {
|
||||
if ($this->isVariable($k) || $this->isVariable($v)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user