Compare commits

..

1 Commits

Author SHA1 Message Date
Simon Wisselink 23b3c21d73 rebase of j-applese3d:smarty5 2024-03-18 16:00:35 +01:00
64 changed files with 1597 additions and 1431 deletions
-5
View File
@@ -6,11 +6,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
## [5.0.0] - 2024-03-25
- Fixed that scoped variables would overwrite parent scope [#952](https://github.com/smarty-php/smarty/issues/952)
- Removed publicly accessible `$tpl->_var_stack` variable
### Fixed
- Too many shorthand attributes error when using a modifier as a function with more than 3 parameters in an expression [#949](https://github.com/smarty-php/smarty/issues/949)
+1
View File
@@ -29,4 +29,5 @@
## Unrelated / other
- review (and avoid) use of 'clone' keyword
- compiler->has_code seems silly. Why not have proper return values?
- what is 'user literal support', why are unit tests skipped?
-1
View File
@@ -1 +0,0 @@
- Internal compiler classes always return a string (the internal has_code flag has been removed for simplicity) [#918](https://github.com/smarty-php/smarty/pull/918)
+2
View File
@@ -0,0 +1,2 @@
- Fixed that scoped variables would overwrite parent scope [#952](https://github.com/smarty-php/smarty/issues/952)
- Removed publicly accessible `$tpl->_var_stack` variable
+2 -2
View File
@@ -226,8 +226,8 @@ abstract class Base implements CompilerInterface {
* @param Template $compiler compiler object
* @param array $parameter array with compilation parameter
*
* @return string compiled code as a string
* @return bool|string compiled code or true if no code has been compiled
* @throws \Smarty\CompilerException
*/
abstract public function compile($args, Template $compiler, $parameter = array(), $tag = null, $function = null): string;
abstract public function compile($args, Template $compiler, $parameter = array(), $tag = null, $function = null);
}
+3 -2
View File
@@ -50,8 +50,7 @@ class BlockCompiler extends Base {
* @throws CompilerException
* @throws Exception
*/
public function compile($args, Template $compiler, $parameter = [], $tag = null, $function = null): string
{
public function compile($args, Template $compiler, $parameter = [], $tag = null, $function = null) {
if (!isset($tag[5]) || substr($tag, -5) !== 'close') {
$output = $this->compileOpeningTag($compiler, $args, $tag, $function);
@@ -78,6 +77,7 @@ class BlockCompiler extends Base {
);
}
$compiler->_cache['blockParams'][$compiler->_cache['blockNesting']]['callsChild'] = true;
$compiler->has_code = true;
$compiler->suppressNocacheProcessing = true;
$output = "<?php \n";
@@ -102,6 +102,7 @@ class BlockCompiler extends Base {
$compiler->getParser()->lex->taglineno
);
}
$compiler->has_code = true;
$compiler->suppressNocacheProcessing = true;
$output = "<?php \n";
+2 -2
View File
@@ -17,10 +17,10 @@ interface CompilerInterface {
* @param \Smarty\Compiler\Template $compiler compiler object
* @param array $parameter array with compilation parameter
*
* @return string compiled code as a string
* @return bool|string compiled code or true if no code has been compiled
* @throws \Smarty\CompilerException
*/
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null): string;
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null);
public function isCacheable(): bool;
}
@@ -27,8 +27,7 @@ class DefaultHandlerFunctionCallCompiler extends Base {
* @throws \Smarty\CompilerException
* @throws \Smarty\Exception
*/
public function compile($args, Template $compiler, $parameter = [], $tag = null, $function = null): string
{
public function compile($args, Template $compiler, $parameter = [], $tag = null, $function = null) {
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
unset($_attr['nocache']);
+1 -2
View File
@@ -49,8 +49,7 @@ class FunctionCallCompiler extends Base {
* @throws \Smarty\CompilerException
* @throws \Smarty\Exception
*/
public function compile($args, Template $compiler, $parameter = [], $tag = null, $function = null): string
{
public function compile($args, Template $compiler, $parameter = [], $tag = null, $function = null) {
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
+3 -2
View File
@@ -33,8 +33,9 @@ class ModifierCompiler extends Base {
* @throws \Smarty\CompilerException
* @throws \Smarty\Exception
*/
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null): string
{
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
$compiler->has_code = true;
$output = $parameter['value'];
+1 -2
View File
@@ -39,8 +39,7 @@ class ObjectMethodCallCompiler extends Base {
* @throws \Smarty\CompilerException
* @throws \Smarty\Exception
*/
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null): string
{
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
unset($_attr['nocache']);
+3 -2
View File
@@ -47,8 +47,9 @@ class PrintExpressionCompiler extends Base {
* @return string
* @throws \Smarty\Exception
*/
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null): string
{
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
$compiler->has_code = true;
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
+3 -4
View File
@@ -37,8 +37,9 @@ class SpecialVariableCompiler extends Base {
* @return string compiled code
* @throws CompilerException
*/
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null): string
{
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
$compiler->has_code = true;
$_index = preg_split("/\]\[/", substr($parameter, 1, strlen($parameter) - 2));
$variable = smarty_strtolower_ascii($compiler->getId($_index[0]));
@@ -128,7 +129,5 @@ class SpecialVariableCompiler extends Base {
}
return $compiled_ref;
}
return '';
}
}
+2 -2
View File
@@ -35,8 +35,8 @@ class Append extends Assign
* @return string compiled code
* @throws \Smarty\CompilerException
*/
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = array(), $tag = null, $function = null): string
{
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = array(), $tag = null, $function = null)
{
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
+2 -2
View File
@@ -55,8 +55,8 @@ class Assign extends Base
* @return string compiled code
* @throws \Smarty\CompilerException
*/
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = array(), $tag = null, $function = null): string
{
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = array(), $tag = null, $function = null)
{
$_nocache = false;
// check and get attributes
+1 -2
View File
@@ -24,8 +24,7 @@ class BCPluginWrapper extends Base {
/**
* @inheritDoc
*/
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null): string
{
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
return call_user_func($this->callback, $this->getAttributes($compiler, $args), $compiler->getSmarty());
}
}
+1 -2
View File
@@ -58,7 +58,7 @@ class Block extends Inheritance {
* @param \Smarty\Compiler\Template $compiler compiler object
* @param array $parameter array with compilation parameter
*/
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = array(), $tag = null, $function = null): string
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = array(), $tag = null, $function = null)
{
if (!isset($compiler->_cache['blockNesting'])) {
$compiler->_cache['blockNesting'] = 0;
@@ -87,6 +87,5 @@ class Block extends Inheritance {
$compiler->getParser()->current_buffer = new Template();
$compiler->getTemplate()->getCompiled()->setNocacheCode(false);
$compiler->suppressNocacheProcessing = true;
return '';
}
}
+2 -1
View File
@@ -18,7 +18,7 @@ class BlockClose extends Inheritance {
*
* @return bool true
*/
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = array(), $tag = null, $function = null): string
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = array(), $tag = null, $function = null)
{
[$_attr, $_nocache, $_buffer, $_has_nocache_code, $_className] = $this->closeTag($compiler, ['block']);
@@ -103,6 +103,7 @@ class BlockClose extends Inheritance {
if ($compiler->_cache['blockNesting'] === 0) {
unset($compiler->_cache['blockNesting']);
}
$compiler->has_code = true;
$compiler->suppressNocacheProcessing = true;
return $output;
}
+1 -1
View File
@@ -52,7 +52,7 @@ class BreakTag extends Base {
* @return string compiled code
* @throws \Smarty\CompilerException
*/
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = array(), $tag = null, $function = null): string
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = array(), $tag = null, $function = null)
{
[$levels, $foreachLevels] = $this->checkLevels($args, $compiler);
$output = "<?php ";
+1 -2
View File
@@ -47,8 +47,7 @@ class Call extends Base {
*
* @return string compiled code
*/
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null): string
{
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
// save possible attributes
+3 -3
View File
@@ -53,8 +53,7 @@ class Capture extends Base {
*
* @return string compiled code
*/
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null): string
{
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
$buffer = $_attr['name'] ?? "'default'";
@@ -67,6 +66,7 @@ class Capture extends Base {
$compiler->openTag('nocache');
}
return "<?php \$_smarty_tpl->getSmarty()->getRuntime('Capture')->open(\$_smarty_tpl, $buffer, $assign, $append);?>";
$_output = "<?php \$_smarty_tpl->getSmarty()->getRuntime('Capture')->open(\$_smarty_tpl, $buffer, $assign, $append);?>";
return $_output;
}
}
+1 -2
View File
@@ -29,8 +29,7 @@ class CaptureClose extends Base {
*
* @return string compiled code
*/
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null): string
{
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
if (array_pop($compiler->_cache['capture_stack'])) {
// pop the virtual {nocache} tag from the stack.
+1 -2
View File
@@ -62,8 +62,7 @@ class ConfigLoad extends Base {
* @return string compiled code
* @throws \Smarty\CompilerException
*/
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null): string
{
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
if ($_attr['nocache'] === true) {
+1 -2
View File
@@ -29,8 +29,7 @@ class Debug extends Base {
*
* @return string compiled code
*/
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null): string
{
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
// check and get attributes, may trigger errors
$this->getAttributes($compiler, $args);
+1 -2
View File
@@ -22,8 +22,7 @@ class ElseIfTag extends Base {
* @return string compiled code
* @throws \Smarty\CompilerException
*/
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null): string
{
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
[$nesting, $nocache_pushed] = $this->closeTag($compiler, ['if', 'elseif']);
+1 -2
View File
@@ -20,8 +20,7 @@ class ElseTag extends Base {
*
* @return string compiled code
*/
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null): string
{
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
[$nesting, $compiler->tag_nocache] = $this->closeTag($compiler, ['if', 'elseif']);
$this->openTag($compiler, 'else', [$nesting, $compiler->tag_nocache]);
return '<?php } else { ?>';
+1 -2
View File
@@ -52,8 +52,7 @@ class EvalTag extends Base {
*
* @return string compiled code
*/
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null): string
{
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
if (isset($_attr['assign'])) {
+2 -2
View File
@@ -52,8 +52,7 @@ class ExtendsTag extends Inheritance {
* @throws \Smarty\CompilerException
* @throws \Smarty\Exception
*/
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null): string
{
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
if ($_attr['nocache'] === true) {
@@ -87,6 +86,7 @@ class ExtendsTag extends Inheritance {
} else {
$this->compileEndChild($compiler, $_attr['file']);
}
$compiler->has_code = false;
return '';
}
+1 -2
View File
@@ -29,8 +29,7 @@ class ForClose extends Base {
*
* @return string compiled code
*/
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null): string
{
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
$compiler->loopNesting--;
[$openTag, $nocache_pushed] = $this->closeTag($compiler, ['for', 'forelse']);
+1 -2
View File
@@ -21,8 +21,7 @@ class ForElse extends Base {
*
* @return string compiled code
*/
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null): string
{
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
[$tagName, $nocache_pushed] = $this->closeTag($compiler, ['for']);
$this->openTag($compiler, 'forelse', ['forelse', $nocache_pushed]);
return "<?php }} else { ?>";
+1 -2
View File
@@ -28,8 +28,7 @@ class ForTag extends Base {
*
* @return string compiled code
*/
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null): string
{
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
$compiler->loopNesting++;
if ($parameter === 0) {
$this->required_attributes = ['start', 'to'];
+1 -2
View File
@@ -29,8 +29,7 @@ class ForeachClose extends Base {
* @return string compiled code
* @throws \Smarty\CompilerException
*/
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null): string
{
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
$compiler->loopNesting--;
[$openTag, $nocache_pushed, $localVariablePrefix, $item, $restore] = $this->closeTag($compiler, ['foreach', 'foreachelse']);
+1 -2
View File
@@ -20,8 +20,7 @@ class ForeachElse extends Base {
*
* @return string compiled code
*/
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null): string
{
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
[$openTag, $nocache_pushed, $localVariablePrefix, $item, $restore] = $this->closeTag($compiler, ['foreach']);
$this->openTag($compiler, 'foreachelse', ['foreachelse', $nocache_pushed, $localVariablePrefix, $item, false]);
+1 -2
View File
@@ -79,8 +79,7 @@ class ForeachTag extends ForeachSection {
* @throws \Smarty\CompilerException
* @throws \Smarty\Exception
*/
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null): string
{
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
$compiler->loopNesting++;
// init
$this->isNamed = false;
+3 -4
View File
@@ -33,10 +33,9 @@ class FunctionClose extends Base {
* @param array $args array with attributes from parser
* @param object|\Smarty\Compiler\Template $compiler compiler object
*
* @return string compiled code
* @return bool true
*/
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null): string
{
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
$this->compiler = $compiler;
$saved_data = $this->closeTag($compiler, ['function']);
$_attr = $saved_data[0];
@@ -141,7 +140,7 @@ class FunctionClose extends Base {
// restore old status
$compiler->getTemplate()->getCompiled()->setNocacheCode($saved_data[2]);
$compiler->getTemplate()->caching = $saved_data[3];
return '';
return true;
}
/**
+3 -4
View File
@@ -42,11 +42,10 @@ class FunctionTag extends Base {
* @param array $args array with attributes from parser
* @param \Smarty\Compiler\Template $compiler compiler object
*
* @return string compiled code
* @return bool true
* @throws \Smarty\CompilerException
*/
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null): string
{
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
if ($_attr['nocache'] === true) {
@@ -68,6 +67,6 @@ class FunctionTag extends Base {
// Init temporary context
$compiler->getParser()->current_buffer = new \Smarty\ParseTree\Template();
$compiler->getTemplate()->getCompiled()->setNocacheCode(false);
return '';
return true;
}
}
+1 -2
View File
@@ -28,8 +28,7 @@ class IfClose extends Base {
*
* @return string compiled code
*/
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null): string
{
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
[$nesting, $nocache_pushed] = $this->closeTag($compiler, ['if', 'else', 'elseif']);
+1 -2
View File
@@ -22,8 +22,7 @@ class IfTag extends Base {
* @return string compiled code
* @throws \Smarty\CompilerException
*/
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null): string
{
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
if ($compiler->tag_nocache) {
// push a {nocache} tag onto the stack to prevent caching of this block
+1 -2
View File
@@ -67,8 +67,7 @@ class IncludeTag extends Base {
* @throws \Smarty\CompilerException
* @throws \Smarty\Exception
*/
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null): string
{
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
$uid = $t_hash = null;
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
+1 -2
View File
@@ -30,8 +30,7 @@ class Ldelim extends Base {
* @return string compiled code
* @throws \Smarty\CompilerException
*/
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null): string
{
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
$_attr = $this->getAttributes($compiler, $args);
if ($_attr['nocache'] === true) {
$compiler->trigger_template_error('nocache option not allowed', null, true);
+5 -4
View File
@@ -26,11 +26,12 @@ class Nocache extends Base {
* @param array $args array with attributes from parser
* @param \Smarty\Compiler\Template $compiler compiler object
*
* @return string
* @return bool
*/
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null): string
{
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
$this->openTag($compiler, 'nocache');
return '';
// this tag does not return compiled code
$compiler->has_code = false;
return true;
}
}
+5 -4
View File
@@ -27,11 +27,12 @@ class NocacheClose extends Base {
* @param array $args array with attributes from parser
* @param \Smarty\Compiler\Template $compiler compiler object
*
* @return string
* @return bool
*/
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null): string
{
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
$this->closeTag($compiler, ['nocache']);
return '';
// this tag does not return compiled code
$compiler->has_code = false;
return true;
}
}
+1 -2
View File
@@ -28,8 +28,7 @@ class Rdelim extends Ldelim {
* @return string compiled code
* @throws \Smarty\CompilerException
*/
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null): string
{
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
parent::compile($args, $compiler);
return $compiler->getTemplate()->getRightDelimiter();
}
+1 -2
View File
@@ -82,8 +82,7 @@ class Section extends ForeachSection {
* @throws \Smarty\CompilerException
* @throws \Smarty\Exception
*/
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null): string
{
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
$compiler->loopNesting++;
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
+1 -2
View File
@@ -25,8 +25,7 @@ class SectionClose extends Base {
*
* @return string compiled code
*/
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null): string
{
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
$compiler->loopNesting--;
[$openTag, $nocache_pushed] = $this->closeTag($compiler, ['section', 'sectionelse']);
+1 -2
View File
@@ -20,8 +20,7 @@ class SectionElse extends Base {
*
* @return string compiled code
*/
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null): string
{
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
[$openTag, $nocache_pushed] = $this->closeTag($compiler, ['section']);
$this->openTag($compiler, 'sectionelse', ['sectionelse', $nocache_pushed]);
return "<?php }} else {\n ?>";
+4 -3
View File
@@ -21,8 +21,7 @@ class Setfilter extends Base {
*
* @return string compiled code
*/
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null): string
{
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
$compiler->variable_filter_stack[] = $compiler->getSmarty()->getDefaultModifiers();
// The modifier_list is passed as an array of array's. The inner arrays have the modifier at index 0,
@@ -35,6 +34,8 @@ class Setfilter extends Base {
$compiler->getSmarty()->setDefaultModifiers($newList);
return '';
// this tag does not return compiled code
$compiler->has_code = false;
return true;
}
}
+4 -3
View File
@@ -29,8 +29,7 @@ class SetfilterClose extends Base {
*
* @return string compiled code
*/
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null): string
{
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
$this->getAttributes($compiler, $args);
// reset variable filter to previous state
@@ -38,6 +37,8 @@ class SetfilterClose extends Base {
count($compiler->variable_filter_stack) ? array_pop($compiler->variable_filter_stack) : []
);
return '';
// this tag does not return compiled code
$compiler->has_code = false;
return true;
}
}
+1 -2
View File
@@ -28,8 +28,7 @@ class WhileClose extends Base {
*
* @return string compiled code
*/
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null): string
{
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
$compiler->loopNesting--;
$nocache_pushed = $this->closeTag($compiler, ['while']);
+1 -2
View File
@@ -22,8 +22,7 @@ class WhileTag extends Base {
* @return string compiled code
* @throws \Smarty\CompilerException
*/
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null): string
{
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
$compiler->loopNesting++;
if ($compiler->tag_nocache) {
+18 -4
View File
@@ -184,6 +184,13 @@ class Template extends BaseCompiler {
*/
public $prefixCodeStack = [];
/**
* Tag has compiled code
*
* @var bool
*/
public $has_code = false;
/**
* A variable string was compiled
*
@@ -1067,10 +1074,12 @@ class Template extends BaseCompiler {
}
public function compileChildBlock() {
$this->has_code = true;
return $this->blockCompiler->compileChild($this);
}
public function compileParentBlock() {
$this->has_code = true;
return $this->blockCompiler->compileParent($this);
}
@@ -1087,6 +1096,8 @@ class Template extends BaseCompiler {
*/
private function compileTag2($tag, $args, $parameter) {
// $args contains the attributes parsed and compiled by the lexer/parser
// assume that tag does compile into code, but creates no HTML output
$this->has_code = true;
$this->handleNocacheFlag($args);
@@ -1095,10 +1106,12 @@ class Template extends BaseCompiler {
if (!isset($this->smarty->security_policy) || $this->smarty->security_policy->isTrustedTag($tag, $this)) {
$this->tag_nocache = $this->tag_nocache | !$tagCompiler->isCacheable();
$_output = $tagCompiler->compile($args, $this, $parameter);
if (!empty($parameter['modifierlist'])) {
throw new CompilerException('No modifiers allowed on ' . $tag);
if ($_output !== false) {
if (!empty($parameter['modifierlist'])) {
throw new CompilerException('No modifiers allowed on ' . $tag);
}
return $this->has_code && $_output !== true ? $_output : null;
}
return $_output;
}
}
@@ -1111,7 +1124,8 @@ class Template extends BaseCompiler {
$args['_attr']['name'] = "'{$tag}'";
$tagCompiler = $this->getTagCompiler('call');
return $tagCompiler === null ? false : $tagCompiler->compile($args, $this, $parameter);
$_output = $tagCompiler === null ? false : $tagCompiler->compile($args, $this, $parameter);
return $this->has_code ? $_output : null;
}
// remaining tastes: (object-)function, (object-function-)block, custom-compiler
+29 -23
View File
@@ -131,6 +131,7 @@ class TemplateLexer
'OPENB' => '[',
'CLOSEB' => ']',
'PTR' => '->',
'NSPTR' => '?->',
'APTR' => '=>',
'EQUAL' => '=',
'NUMBER' => 'number',
@@ -567,7 +568,7 @@ class TemplateLexer
public function yylex3()
{
if (!isset($this->yy_global_pattern3)) {
$this->yy_global_pattern3 = $this->replace("/\G(\\s*SMARTYrdel)|\G((SMARTYldel)SMARTYal)|\G([\"])|\G('[^'\\\\]*(?:\\\\.[^'\\\\]*)*')|\G([$][0-9]*[a-zA-Z_]\\w*)|\G([$])|\G(\\s+is\\s+in\\s+)|\G(\\s+as\\s+)|\G(\\s+to\\s+)|\G(\\s+step\\s+)|\G(\\s+instanceof\\s+)|\G(\\s*([!=][=]{1,2}|[<][=>]?|[>][=]?|[&|]{2})\\s*)|\G(\\s+(eq|ne|neq|gt|ge|gte|lt|le|lte|mod|and|or|xor)\\s+)|\G(\\s+is\\s+(not\\s+)?(odd|even|div)\\s+by\\s+)|\G(\\s+is\\s+(not\\s+)?(odd|even))|\G([!]\\s*|not\\s+)|\G([(](int(eger)?|bool(ean)?|float|double|real|string|binary|array|object)[)]\\s*)|\G(\\s*[(]\\s*)|\G(\\s*[)])|\G(\\[\\s*)|\G(\\s*\\])|\G(\\s*[-][>]\\s*)|\G(\\s*[=][>]\\s*)|\G(\\s*[=]\\s*)|\G(([+]|[-]){2})|\G(\\s*([+]|[-])\\s*)|\G(\\s*([*]{1,2}|[%\/^&]|[<>]{2})\\s*)|\G([@])|\G(array\\s*[(]\\s*)|\G([#])|\G(\\s+[0-9]*[a-zA-Z_][a-zA-Z0-9_\-:]*\\s*[=]\\s*)|\G(([0-9]*[a-zA-Z_]\\w*)?(\\\\[0-9]*[a-zA-Z_]\\w*)+)|\G([0-9]*[a-zA-Z_]\\w*)|\G(\\d+)|\G([`])|\G([|][@]?)|\G([.])|\G(\\s*[,]\\s*)|\G(\\s*[;]\\s*)|\G([:]{2})|\G(\\s*[:]\\s*)|\G(\\s*[?]\\s*)|\G(0[xX][0-9a-fA-F]+)|\G(\\s+)|\G([\S\s])/isS");
$this->yy_global_pattern3 = $this->replace("/\G(\\s*SMARTYrdel)|\G((SMARTYldel)SMARTYal)|\G([\"])|\G('[^'\\\\]*(?:\\\\.[^'\\\\]*)*')|\G([$][0-9]*[a-zA-Z_]\\w*)|\G([$])|\G(\\s+is\\s+in\\s+)|\G(\\s+as\\s+)|\G(\\s+to\\s+)|\G(\\s+step\\s+)|\G(\\s+instanceof\\s+)|\G(\\s*([!=][=]{1,2}|[<][=>]?|[>][=]?|[&|]{2})\\s*)|\G(\\s+(eq|ne|neq|gt|ge|gte|lt|le|lte|mod|and|or|xor)\\s+)|\G(\\s+is\\s+(not\\s+)?(odd|even|div)\\s+by\\s+)|\G(\\s+is\\s+(not\\s+)?(odd|even))|\G([!]\\s*|not\\s+)|\G([(](int(eger)?|bool(ean)?|float|double|real|string|binary|array|object)[)]\\s*)|\G(\\s*[(]\\s*)|\G(\\s*[)])|\G(\\[\\s*)|\G(\\s*\\])|\G(\\s*[-][>]\\s*)|\G(\\s*[?][-][>]\\s*)|\G(\\s*[=][>]\\s*)|\G(\\s*[=]\\s*)|\G(([+]|[-]){2})|\G(\\s*([+]|[-])\\s*)|\G(\\s*([*]{1,2}|[%\/^&]|[<>]{2})\\s*)|\G([@])|\G(array\\s*[(]\\s*)|\G([#])|\G(\\s+[0-9]*[a-zA-Z_][a-zA-Z0-9_\-:]*\\s*[=]\\s*)|\G(([0-9]*[a-zA-Z_]\\w*)?(\\\\[0-9]*[a-zA-Z_]\\w*)+)|\G([0-9]*[a-zA-Z_]\\w*)|\G(\\d+)|\G([`])|\G([|][@]?)|\G([.])|\G(\\s*[,]\\s*)|\G(\\s*[;]\\s*)|\G([:]{2})|\G(\\s*[:]\\s*)|\G(\\s*[?]\\s*)|\G(0[xX][0-9a-fA-F]+)|\G(\\s+)|\G([\S\s])/isS");
}
if (!isset($this->dataLength)) {
$this->dataLength = strlen($this->data);
@@ -737,44 +738,49 @@ class TemplateLexer
public function yy_r3_33()
{
$this->token = \Smarty\Parser\TemplateParser::TP_APTR;
$this->token = \Smarty\Parser\TemplateParser::TP_NSPTR;
}
public function yy_r3_34()
{
$this->token = \Smarty\Parser\TemplateParser::TP_EQUAL;
$this->token = \Smarty\Parser\TemplateParser::TP_APTR;
}
public function yy_r3_35()
{
$this->token = \Smarty\Parser\TemplateParser::TP_EQUAL;
}
public function yy_r3_36()
{
$this->token = \Smarty\Parser\TemplateParser::TP_INCDEC;
}
public function yy_r3_37()
public function yy_r3_38()
{
$this->token = \Smarty\Parser\TemplateParser::TP_UNIMATH;
}
public function yy_r3_39()
public function yy_r3_40()
{
$this->token = \Smarty\Parser\TemplateParser::TP_MATH;
}
public function yy_r3_41()
public function yy_r3_42()
{
$this->token = \Smarty\Parser\TemplateParser::TP_AT;
}
public function yy_r3_42()
public function yy_r3_43()
{
$this->token = \Smarty\Parser\TemplateParser::TP_ARRAYOPEN;
}
public function yy_r3_43()
public function yy_r3_44()
{
$this->token = \Smarty\Parser\TemplateParser::TP_HATCH;
}
public function yy_r3_44()
public function yy_r3_45()
{
// resolve conflicts with shorttag and right_delimiter starting with '='
@@ -786,73 +792,73 @@ class TemplateLexer
$this->token = \Smarty\Parser\TemplateParser::TP_ATTR;
}
}
public function yy_r3_45()
public function yy_r3_46()
{
$this->token = \Smarty\Parser\TemplateParser::TP_NAMESPACE;
}
public function yy_r3_48()
public function yy_r3_49()
{
$this->token = \Smarty\Parser\TemplateParser::TP_ID;
}
public function yy_r3_49()
public function yy_r3_50()
{
$this->token = \Smarty\Parser\TemplateParser::TP_INTEGER;
}
public function yy_r3_50()
public function yy_r3_51()
{
$this->token = \Smarty\Parser\TemplateParser::TP_BACKTICK;
$this->yypopstate();
}
public function yy_r3_51()
public function yy_r3_52()
{
$this->token = \Smarty\Parser\TemplateParser::TP_VERT;
}
public function yy_r3_52()
public function yy_r3_53()
{
$this->token = \Smarty\Parser\TemplateParser::TP_DOT;
}
public function yy_r3_53()
public function yy_r3_54()
{
$this->token = \Smarty\Parser\TemplateParser::TP_COMMA;
}
public function yy_r3_54()
public function yy_r3_55()
{
$this->token = \Smarty\Parser\TemplateParser::TP_SEMICOLON;
}
public function yy_r3_55()
public function yy_r3_56()
{
$this->token = \Smarty\Parser\TemplateParser::TP_DOUBLECOLON;
}
public function yy_r3_56()
public function yy_r3_57()
{
$this->token = \Smarty\Parser\TemplateParser::TP_COLON;
}
public function yy_r3_57()
public function yy_r3_58()
{
$this->token = \Smarty\Parser\TemplateParser::TP_QMARK;
}
public function yy_r3_58()
public function yy_r3_59()
{
$this->token = \Smarty\Parser\TemplateParser::TP_HEX;
}
public function yy_r3_59()
public function yy_r3_60()
{
$this->token = \Smarty\Parser\TemplateParser::TP_SPACE;
}
public function yy_r3_60()
public function yy_r3_61()
{
$this->token = \Smarty\Parser\TemplateParser::TP_TEXT;
+5
View File
@@ -131,6 +131,7 @@ class TemplateLexer
'OPENB' => '[',
'CLOSEB' => ']',
'PTR' => '->',
'NSPTR' => '?->',
'APTR' => '=>',
'EQUAL' => '=',
'NUMBER' => 'number',
@@ -310,6 +311,7 @@ class TemplateLexer
equal = ~\s*[=]\s*~
space = ~\s+~
ptr = ~\s*[-][>]\s*~
nsptr = ~\s*[?][-][>]\s*~
aptr = ~\s*[=][>]\s*~
singlequotestring = ~'[^'\\]*(?:\\.[^'\\]*)*'~
backtick = ~[`]~
@@ -514,6 +516,9 @@ class TemplateLexer
ptr {
$this->token = \Smarty\Parser\TemplateParser::TP_PTR;
}
nsptr {
$this->token = \Smarty\Parser\TemplateParser::TP_NSPTR;
}
aptr {
$this->token = \Smarty\Parser\TemplateParser::TP_APTR;
}
+1369 -1283
View File
File diff suppressed because it is too large Load Diff
+47 -1
View File
@@ -290,7 +290,9 @@ literal_e1(A) ::= . {
}
// Smarty tag
template ::= template smartytag(B). {
$this->current_buffer->append_subtree($this, $this->mergePrefixCode(B));
if ($this->compiler->has_code) {
$this->current_buffer->append_subtree($this, $this->mergePrefixCode(B));
}
$this->compiler->has_variable_string = false;
$this->block_nesting_level = $this->compiler->getTagStackCount();
}
@@ -430,6 +432,16 @@ tag(res) ::= LDEL ID(i) PTR ID(me) modifierlist(l) attributes(a). {
res = $this->compiler->compileTag(i,a,array('modifierlist'=>l, 'object_method'=>me));
}
// registered ns object tag
tag(res) ::= LDEL ID(i) NSPTR ID(m) attributes(a). {
res = $this->compiler->compileTag(i,a,array('object_method'=>m));
}
// registered ns object tag with modifiers
tag(res) ::= LDEL ID(i) NSPTR ID(me) modifierlist(l) attributes(a). {
res = $this->compiler->compileTag(i,a,array('modifierlist'=>l, 'object_method'=>me));
}
// {if}, {elseif} and {while} tag
tag(res) ::= LDELIF(i) expr(ie). {
$tag = trim(substr(i,$this->compiler->getLdelLength()));
@@ -1054,6 +1066,40 @@ objectelement(res)::= PTR method(f). {
res = '->'.f;
}
// variable
objectelement(res)::= NSPTR ID(i) arrayindex(a). {
if ($this->security && substr(i,0,1) === '_') {
$this->compiler->trigger_template_error (self::ERR1);
}
res = '?->'.i.a;
}
objectelement(res)::= NSPTR varvar(v) arrayindex(a). {
if ($this->security) {
$this->compiler->trigger_template_error (self::ERR2);
}
res = '?->{'.$this->compiler->compileVariable(v).a.'}';
}
objectelement(res)::= NSPTR LDEL expr(e) RDEL arrayindex(a). {
if ($this->security) {
$this->compiler->trigger_template_error (self::ERR2);
}
res = '?->{'.e.a.'}';
}
objectelement(res)::= NSPTR ID(ii) LDEL expr(e) RDEL arrayindex(a). {
if ($this->security) {
$this->compiler->trigger_template_error (self::ERR2);
}
res = '?->{\''.ii.'\'.'.e.a.'}';
}
// method
objectelement(res)::= NSPTR method(f). {
res = '?->'.f;
}
//
// function
+1 -1
View File
@@ -53,7 +53,7 @@ class Smarty extends \Smarty\TemplateBase {
/**
* smarty version
*/
const SMARTY_VERSION = '5.0.0';
const SMARTY_VERSION = '5.0.0-rc3';
/**
* define caching modes
@@ -303,7 +303,7 @@ class SecurityTest extends PHPUnit_Smarty
}
/**
*
* @group slow
*
*/
public function testTrustedUri()
{
@@ -304,8 +304,7 @@ class blockparamsCompiler extends \Smarty\Compile\Base {
protected $shorttag_order = ["first", "second"];
protected $optional_attributes = ["first", "second"];
public function compile($args, Template $compiler, $parameter = [], $tag = null, $function = null): string
{
public function compile($args, Template $compiler, $parameter = [], $tag = null, $function = null) {
$_attr = $this->getAttributes($compiler, $args);
$output = '';
@@ -6,8 +6,7 @@ use Smarty\Compile\Base;
class smarty_compiler_test extends Base
{
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null): string
{
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
$this->required_attributes = array('data');
$_attr = $this->getAttributes($compiler, $args);
@@ -6,8 +6,7 @@ use Smarty\Compile\Base;
class smarty_compiler_testclose extends Base
{
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null): string
{
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
$this->closeTag($compiler, 'test');
@@ -30,7 +30,7 @@ class PluginFunctionFetchTest extends PHPUnit_Smarty
* test {fetch} from UIR
*
*
* @group slow
*
*/
public function testFetchUri()
{
@@ -32,6 +32,7 @@ class CompileFunctionTest extends PHPUnit_Smarty
*
* @dataProvider functionProvider
* test simple function call tag
*
*/
public function testSimpleFunction_001($text)
{
@@ -93,6 +93,33 @@ class ObjectVariableTest extends PHPUnit_Smarty
$tpl->assign('object', $object);
$this->assertEquals('hello world', $this->smarty->fetch($tpl));
}
public function testNullSafeOperatorSimple()
{
$object = new VariableObject;
$tpl = $this->smarty->createTemplate('string:{$object?->hello}');
$tpl->assign('object', $object);
$this->assertEquals('hello_world', $this->smarty->fetch($tpl));
$object = null;
$tpl = $this->smarty->createTemplate('string:{$object?->hello}');
$tpl->assign('object', $object);
$this->assertEquals((string)null, $this->smarty->fetch($tpl));
}
public function testNullSafeOperatorChaining()
{
$object = new VariableObject;
$tpl = $this->smarty->createTemplate('string:{$object?->returnSelf()?->myhello()}');
$tpl->assign('object', $object);
$this->assertEquals('hello world', $this->smarty->fetch($tpl));
$tpl = $this->smarty->createTemplate('string:{$object?->returnNull()?->myhello()}');
$tpl->assign('object', $object);
$this->assertEquals((string)null, $this->smarty->fetch($tpl));
}
}
Class VariableObject
@@ -103,4 +130,14 @@ Class VariableObject
{
return 'hello world';
}
public function returnSelf()
{
return $this;
}
public function returnNull()
{
return null;
}
}
@@ -41,8 +41,8 @@ class smarty_compiler_getparamsshort extends Base
*/
public $shorttag_order = array('s1', 's2', 's3');
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null): string
{
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null)
{
$_attr = $this->getAttributes($compiler, $args);
$output = '<?php echo "array(';
foreach ($_attr as $key => $value) {