PHP 5.3 compatibility fixes

This commit is contained in:
AnrDaemon
2020-05-05 01:37:36 +03:00
parent e1c050a32c
commit eae19f23b9
4 changed files with 18 additions and 18 deletions

View File

@@ -40,7 +40,7 @@
} }
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "6.4.1", "phpunit/phpunit": "6.4.1 || ^5.7 || ^4.8",
"smarty/smarty-lexer": "^3.1" "smarty/smarty-lexer": "^3.1"
} }
} }

View File

@@ -127,12 +127,12 @@ class Smarty_Internal_ParseTree_Template extends Smarty_Internal_ParseTree
} }
private function getChunkedSubtrees() { private function getChunkedSubtrees() {
$chunks = []; $chunks = array();
$currentMode = null; $currentMode = null;
$currentChunk = []; $currentChunk = array();
for ($key = 0, $cnt = count($this->subtrees); $key < $cnt; $key++) { for ($key = 0, $cnt = count($this->subtrees); $key < $cnt; $key++) {
if ($this->subtrees[ $key ]->data === '' && in_array($currentMode, ['textstripped', 'text', 'tag'])) { if ($this->subtrees[ $key ]->data === '' && in_array($currentMode, array('textstripped', 'text', 'tag'))) {
continue; continue;
} }
@@ -150,19 +150,19 @@ class Smarty_Internal_ParseTree_Template extends Smarty_Internal_ParseTree
if ($newMode == $currentMode) { if ($newMode == $currentMode) {
$currentChunk[] = $this->subtrees[ $key ]; $currentChunk[] = $this->subtrees[ $key ];
} else { } else {
$chunks[] = [ $chunks[] = array(
'mode' => $currentMode, 'mode' => $currentMode,
'subtrees' => $currentChunk 'subtrees' => $currentChunk
]; );
$currentMode = $newMode; $currentMode = $newMode;
$currentChunk = [$this->subtrees[ $key ]]; $currentChunk = array($this->subtrees[ $key ]);
} }
} }
if ($currentMode && $currentChunk) { if ($currentMode && $currentChunk) {
$chunks[] = [ $chunks[] = array(
'mode' => $currentMode, 'mode' => $currentMode,
'subtrees' => $currentChunk 'subtrees' => $currentChunk
]; );
} }
return $chunks; return $chunks;
} }

View File

@@ -95,7 +95,7 @@ class CompileForeachTest extends PHPUnit_Smarty
array('{foreach $foo x y foo}{$y}.{$x},{foreachelse}else{/foreach}total{$smarty.foreach.foo.total}', array(9,10,11), '0.9,1.10,2.11,total3', '', $i ++), array('{foreach $foo x y foo}{$y}.{$x},{foreachelse}else{/foreach}total{$smarty.foreach.foo.total}', array(9,10,11), '0.9,1.10,2.11,total3', '', $i ++),
array('{$x = "hallo"}{$bar=[1,2,3]}{foreach $foo as $x}outer={$x@index}.{$x}#{foreach $bar as $x}inner={$x@index}.{$x}{/foreach}##{/foreach}###{$x}', array(9,10,11), 'outer=0.9#inner=0.1inner=1.2inner=2.3##outer=1.10#inner=0.1inner=1.2inner=2.3##outer=2.11#inner=0.1inner=1.2inner=2.3#####hallo', '', $i ++), array('{$x = "hallo"}{$bar=[1,2,3]}{foreach $foo as $x}outer={$x@index}.{$x}#{foreach $bar as $x}inner={$x@index}.{$x}{/foreach}##{/foreach}###{$x}', array(9,10,11), 'outer=0.9#inner=0.1inner=1.2inner=2.3##outer=1.10#inner=0.1inner=1.2inner=2.3##outer=2.11#inner=0.1inner=1.2inner=2.3#####hallo', '', $i ++),
array('{foreach $foo as $x}{$x}{foreachelse}else{/foreach}', null, 'else', '', $i ++), array('{foreach $foo as $x}{$x}{foreachelse}else{/foreach}', null, 'else', '', $i ++),
array('{foreach $foo as $x}{$x}{foreachelse}else{/foreach}', [], 'else', '', $i ++), array('{foreach $foo as $x}{$x}{foreachelse}else{/foreach}', array(), 'else', '', $i ++),
array('{foreach $foo as $x}{$x}{foreachelse}else{/foreach}', new \ArrayIterator(), 'else', '', $i ++), array('{foreach $foo as $x}{$x}{foreachelse}else{/foreach}', new \ArrayIterator(), 'else', '', $i ++),
); );
} }

View File

@@ -57,7 +57,7 @@ class PhpFunctionTest extends PHPUnit_Smarty
public function testEmpty2() public function testEmpty2()
{ {
if (version_compare(phpversion(), '5.5', '<')) { if (version_compare(phpversion(), '5.5', '<')) {
$this->markTestSkipped('runs only on PHP > 5.5'); $this->markTestSkipped('runs only on PHP >= 5.5');
} }
$this->smarty->disableSecurity(); $this->smarty->disableSecurity();
@@ -82,7 +82,7 @@ class PhpFunctionTest extends PHPUnit_Smarty
public function testEmpty3() public function testEmpty3()
{ {
if (version_compare(phpversion(), '5.5', '<')) { if (version_compare(phpversion(), '5.5', '<')) {
$this->markTestSkipped('runs only on PHP > 5.5'); $this->markTestSkipped('runs only on PHP >= 5.5');
} }
$this->smarty->disableSecurity(); $this->smarty->disableSecurity();
$this->smarty->assign('var', array(true, $this->smarty->assign('var', array(true,
@@ -104,7 +104,7 @@ class PhpFunctionTest extends PHPUnit_Smarty
public function testEmpty4() public function testEmpty4()
{ {
if (version_compare(phpversion(), '5.5', '<')) { if (version_compare(phpversion(), '5.5', '<')) {
$this->markTestSkipped('runs only on PHP > 5.5'); $this->markTestSkipped('runs only on PHP >= 5.5');
} }
$this->smarty->disableSecurity(); $this->smarty->disableSecurity();
@@ -168,11 +168,11 @@ class PhpFunctionTest extends PHPUnit_Smarty
$this->smarty->disableSecurity(); $this->smarty->disableSecurity();
$this->smarty->assign('varobject', new TestIsset()); $this->smarty->assign('varobject', new TestIsset());
$this->smarty->assign('vararray', $vararray = [ $this->smarty->assign('vararray', $vararray = array(
'keythatexists' => false, 'keythatexists' => false,
'keywitharray' => [1 => 1], 'keywitharray' => array(1 => 1),
'keywithobject' => new TestIsset()] 'keywithobject' => new TestIsset()
); ));
$this->smarty->assign('key', 'A'); $this->smarty->assign('key', 'A');
$this->smarty->assign('_varsimpleA', 1); $this->smarty->assign('_varsimpleA', 1);
@@ -234,4 +234,4 @@ class TestIsset {
public function pass($v) { public function pass($v) {
return $v; return $v;
} }
} }