Skip to content

Commit 1836dce

Browse files
authored
Merge pull request #90 from Slamdunk/php_82
Add PHP 8.2 support, drop PHP 7.4
2 parents efddaab + 2622cad commit 1836dce

18 files changed

+174
-520
lines changed

.github/workflows/phpunit.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ jobs:
1717
- "highest"
1818
- "locked"
1919
php-version:
20-
- "7.4"
2120
- "8.0"
2221
- "8.1"
22+
- "8.2"
2323
operating-system:
2424
- "ubuntu-latest"
2525

classes/PHPTAL/Context.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
* Holds template variables and carries state/scope across macro executions.
1919
*
2020
*/
21+
#[AllowDynamicProperties]
2122
class PHPTAL_Context
2223
{
2324
public $repeat;

classes/PHPTAL/Dom/Element.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,23 @@ class PHPTAL_Dom_Element extends PHPTAL_Dom_Node
3636
public $childNodes = array();
3737
public $parentNode;
3838

39+
private array $talHandlers;
40+
3941
/**
4042
* @param string $qname qualified name of the element, e.g. "tal:block"
4143
* @param string $namespace_uri namespace of this element
4244
* @param array $attribute_nodes array of PHPTAL_Dom_Attr elements
43-
* @param object $xmlns object that represents namespaces/prefixes known in element's context
45+
* @param PHPTAL_Dom_XmlnsState $xmlns object that represents namespaces/prefixes known in element's context
4446
*/
45-
public function __construct($qname, $namespace_uri, array $attribute_nodes, PHPTAL_Dom_XmlnsState $xmlns)
47+
public function __construct(
48+
$qname,
49+
$namespace_uri,
50+
array $attribute_nodes,
51+
private PHPTAL_Dom_XmlnsState $xmlns)
4652
{
4753
$this->qualifiedName = $qname;
4854
$this->attribute_nodes = $attribute_nodes;
4955
$this->namespace_uri = $namespace_uri;
50-
$this->xmlns = $xmlns;
5156

5257
// implements inheritance of element's namespace to tal attributes (<metal: use-macro>)
5358
foreach ($attribute_nodes as $index => $attr) {

classes/PHPTAL/Dom/PHPTALDocumentBuilder.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class PHPTAL_Dom_PHPTALDocumentBuilder extends PHPTAL_Dom_DocumentBuilder
2424
{
2525
private $_xmlns; /* PHPTAL_Dom_XmlnsState */
2626
private $encoding;
27+
private ?PHPTAL_Dom_Element $documentElement = null;
2728

2829
public function __construct()
2930
{

classes/PHPTAL/Dom/SaxXmlParser.php

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,9 @@ private function checkEncoding($str)
406406
$forbid = '/((?>[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x84\x86-\x9F]+))/s';
407407

408408
if (preg_match($forbid, $str)) {
409-
$str = preg_replace_callback($forbid, array('self', 'convertBytesToEntities'), $str);
409+
$str = preg_replace_callback($forbid, static function (array $m): string {
410+
return self::convertBytesToEntities($m);
411+
}, $str);
410412
$this->raiseError("Invalid ISO-8859-1 characters: ".$str);
411413
}
412414
}
@@ -419,10 +421,8 @@ private function checkEncoding($str)
419421
* Changes all bytes to hexadecimal XML entities
420422
*
421423
* @param array $m first array element is used for input
422-
*
423-
* @return string
424424
*/
425-
private static function convertBytesToEntities(array $m)
425+
private static function convertBytesToEntities(array $m): string
426426
{
427427
$m = $m[1];
428428
$out = "";
@@ -444,21 +444,18 @@ private function sanitizeEscapedText($str)
444444
so they have to be converted into special TALES expression
445445
*/
446446
$types = version_compare(PHP_VERSION, '5.4.0') < 0 ? (ini_get('short_open_tag') ? 'php|=|' : 'php') : 'php|=';
447-
$str = preg_replace_callback("/<\?($types)(.*?)\?>/", array('self', 'convertPHPBlockToTALES'), $str);
447+
$str = preg_replace_callback("/<\?($types)(.*?)\?>/", static function ($m) {
448+
list(, $type, $code) = $m;
449+
if ($type === '=') $code = 'echo '.$code;
450+
return '${structure phptal-internal-php-block:'.rawurlencode($code).'}';
451+
}, $str);
448452

449453
// corrects all non-entities and neutralizes potentially problematic CDATA end marker
450454
$str = strtr(preg_replace('/&(?!(?:#x?[a-f0-9]+|[a-z][a-z0-9]*);)/i', '&amp;', $str), array('<'=>'&lt;', ']]>'=>']]&gt;'));
451455

452456
return $str;
453457
}
454458

455-
private static function convertPHPBlockToTALES($m)
456-
{
457-
list(, $type, $code) = $m;
458-
if ($type === '=') $code = 'echo '.$code;
459-
return '${structure phptal-internal-php-block:'.rawurlencode($code).'}';
460-
}
461-
462459
public function getSourceFile()
463460
{
464461
return $this->_file;

classes/PHPTAL/Php/Attribute.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,10 @@ protected function doEchoAttribute(PHPTAL_Php_CodeWriter $codewriter, $code)
8282
$codewriter->doEchoRaw($code);
8383
}
8484

85-
protected function parseSetExpression($exp)
85+
/**
86+
* @return non-empty-array<array-key, null|string>
87+
*/
88+
protected function parseSetExpression(string $exp)
8689
{
8790
$exp = trim($exp);
8891
// (dest) (value)

classes/PHPTAL/Php/Attribute/TAL/Attributes.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ class PHPTAL_Php_Attribute_TAL_Attributes
4646
* value for default keyword
4747
*/
4848
private $_default_escaped;
49+
private string $_attribute = '';
50+
private string $_attkey = '';
4951

5052
public function before(PHPTAL_Php_CodeWriter $codewriter)
5153
{
@@ -59,7 +61,7 @@ public function before(PHPTAL_Php_CodeWriter $codewriter)
5961
}
6062
}
6163

62-
private function prepareAttribute(PHPTAL_Php_CodeWriter $codewriter, $qname, $expression)
64+
private function prepareAttribute(PHPTAL_Php_CodeWriter $codewriter, string $qname, $expression)
6365
{
6466
$tales_code = $this->extractEchoType($expression);
6567
$code = $codewriter->evaluateExpression($tales_code);
@@ -127,7 +129,7 @@ private function prepareAttributeConditional(PHPTAL_Php_CodeWriter $codewriter,
127129
$this->phpelement->getOrCreateAttributeNode($qname)->overwriteFullWithVariable($attkey);
128130
}
129131

130-
private function prepareChainedAttribute(PHPTAL_Php_CodeWriter $codewriter, $qname, $chain)
132+
private function prepareChainedAttribute(PHPTAL_Php_CodeWriter $codewriter, string $qname, $chain)
131133
{
132134
$this->_default_escaped = false;
133135
$this->_attribute = $qname;
@@ -139,7 +141,7 @@ private function prepareChainedAttribute(PHPTAL_Php_CodeWriter $codewriter, $qna
139141
$this->phpelement->getOrCreateAttributeNode($qname)->overwriteFullWithVariable($this->_attkey);
140142
}
141143

142-
private function prepareBooleanAttribute(PHPTAL_Php_CodeWriter $codewriter, $qname, $code)
144+
private function prepareBooleanAttribute(PHPTAL_Php_CodeWriter $codewriter, string $qname, $code)
143145
{
144146
$attkey = $this->getVarName($qname, $codewriter);
145147

@@ -156,7 +158,7 @@ private function prepareBooleanAttribute(PHPTAL_Php_CodeWriter $codewriter, $qna
156158
$this->phpelement->getOrCreateAttributeNode($qname)->overwriteFullWithVariable($attkey);
157159
}
158160

159-
private function getVarName($qname, PHPTAL_Php_CodeWriter $codewriter)
161+
private function getVarName($qname, PHPTAL_Php_CodeWriter $codewriter): string
160162
{
161163
$var = $codewriter->createTempVariable();
162164
$this->vars_to_recycle[] = $var;

classes/PHPTAL/Php/TalesChainExecutor.php

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,15 @@ class PHPTAL_Php_TalesChainExecutor
2323
const CHAIN_BREAK = 1;
2424
const CHAIN_CONT = 2;
2525

26-
public function __construct(PHPTAL_Php_CodeWriter $codewriter, array $chain, PHPTAL_Php_TalesChainReader $reader)
26+
private int $state = 0;
27+
private bool $chainStarted = false;
28+
29+
public function __construct(
30+
private PHPTAL_Php_CodeWriter $codewriter,
31+
private array $chain,
32+
private PHPTAL_Php_TalesChainReader $reader
33+
)
2734
{
28-
$this->_chain = $chain;
29-
$this->_chainStarted = false;
30-
$this->codewriter = $codewriter;
31-
$this->_reader = $reader;
3235
$this->_executeChain();
3336
}
3437

@@ -37,10 +40,10 @@ public function getCodeWriter()
3740
return $this->codewriter;
3841
}
3942

40-
public function doIf($condition)
43+
public function doIf(string $condition)
4144
{
42-
if ($this->_chainStarted == false) {
43-
$this->_chainStarted = true;
45+
if ($this->chainStarted == false) {
46+
$this->chainStarted = true;
4447
$this->codewriter->doIf($condition);
4548
} else {
4649
$this->codewriter->doElseIf($condition);
@@ -54,43 +57,38 @@ public function doElse()
5457

5558
public function breakChain()
5659
{
57-
$this->_state = self::CHAIN_BREAK;
60+
$this->state = self::CHAIN_BREAK;
5861
}
5962

6063
public function continueChain()
6164
{
62-
$this->_state = self::CHAIN_CONT;
65+
$this->state = self::CHAIN_CONT;
6366
}
6467

6568
private function _executeChain()
6669
{
6770
$this->codewriter->noThrow(true);
6871

69-
end($this->_chain); $lastkey = key($this->_chain);
72+
end($this->chain); $lastkey = key($this->chain);
7073

71-
foreach ($this->_chain as $key => $exp) {
72-
$this->_state = 0;
74+
foreach ($this->chain as $key => $exp) {
75+
$this->state = 0;
7376

7477
if ($exp == PHPTAL_Php_TalesInternal::NOTHING_KEYWORD) {
75-
$this->_reader->talesChainNothingKeyword($this);
78+
$this->reader->talesChainNothingKeyword($this);
7679
} elseif ($exp == PHPTAL_Php_TalesInternal::DEFAULT_KEYWORD) {
77-
$this->_reader->talesChainDefaultKeyword($this);
80+
$this->reader->talesChainDefaultKeyword($this);
7881
} else {
79-
$this->_reader->talesChainPart($this, $exp, $lastkey === $key);
82+
$this->reader->talesChainPart($this, $exp, $lastkey === $key);
8083
}
8184

82-
if ($this->_state == self::CHAIN_BREAK)
85+
if ($this->state == self::CHAIN_BREAK)
8386
break;
84-
if ($this->_state == self::CHAIN_CONT)
87+
if ($this->state == self::CHAIN_CONT)
8588
continue;
8689
}
8790

8891
$this->codewriter->doEnd('if');
8992
$this->codewriter->noThrow(false);
9093
}
91-
92-
private $_state = 0;
93-
private $_chain;
94-
private $_chainStarted = false;
95-
private $codewriter = null;
9694
}

classes/PHPTAL/RepeatController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class PHPTAL_RepeatController implements Iterator
4949
* computed lazily
5050
*/
5151
private $length = null;
52+
private PHPTAL_RepeatControllerGroups $groups;
5253

5354
/**
5455
* Construct a new RepeatController.

classes/PHPTAL/StringSource.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@
2020
class PHPTAL_StringSource implements PHPTAL_Source
2121
{
2222
const NO_PATH_PREFIX = '<string ';
23+
private string $_data;
24+
private string $_realpath;
2325

24-
public function __construct($data, $realpath = null)
26+
public function __construct(string $data, ?string $realpath = null)
2527
{
2628
$this->_data = $data;
2729
$this->_realpath = $realpath ? $realpath : self::NO_PATH_PREFIX.md5($data).'>';

0 commit comments

Comments
 (0)