Skip to content

Commit

Permalink
Add PHP 8.1 support, drop PHP 7.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Slamdunk committed Dec 17, 2021
1 parent 1f71424 commit cc1020a
Show file tree
Hide file tree
Showing 18 changed files with 110 additions and 75 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ jobs:
- "highest"
- "locked"
php-version:
- "7.3"
- "7.4"
- "8.0"
- "8.1"
operating-system:
- "ubuntu-latest"

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ build
/vendor/
/doc/temp/
/docs/
.phpunit.result.cache
2 changes: 1 addition & 1 deletion classes/PHPTAL.php
Original file line number Diff line number Diff line change
Expand Up @@ -981,7 +981,7 @@ public function getFunctionName()
if (!$this->_functionName) {

// just to make tempalte name recognizable
$basename = preg_replace('/\.[a-z]{3,5}$/', '', basename($this->_source->getRealPath()));
$basename = preg_replace('/\.[a-z]{3,5}$/', '', basename($this->_source->getRealPath() ?? ''));
$basename = substr(trim(preg_replace('/[^a-zA-Z0-9]+/', '_', $basename), "_"), 0, 20);

$hash = md5(PHPTAL_VERSION . PHP_VERSION
Expand Down
2 changes: 2 additions & 0 deletions classes/PHPTAL/DefaultKeyword.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ public function __toString()
return "''";
}

#[\ReturnTypeWillChange]
public function count()
{
return 1;
}

#[\ReturnTypeWillChange]
public function jsonSerialize()
{
return new stdClass;
Expand Down
4 changes: 2 additions & 2 deletions classes/PHPTAL/Dom/SaxXmlParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ private function checkEncoding($str)
// $match expression below somehow triggers quite deep recurrency and stack overflow in preg
// to avoid this, check string bit by bit, omitting ASCII fragments.
if (strlen($str) > 200) {
$chunks = preg_split('/(?>[\x09\x0A\x0D\x20-\x7F]+)/',$str,null,PREG_SPLIT_NO_EMPTY);
$chunks = preg_split('/(?>[\x09\x0A\x0D\x20-\x7F]+)/',$str,0,PREG_SPLIT_NO_EMPTY);
foreach ($chunks as $chunk) {
if (strlen($chunk) < 200) {
$this->checkEncoding($chunk);
Expand All @@ -392,7 +392,7 @@ private function checkEncoding($str)
. '|\xF4[\x80-\x8F][\x80-\xBF]{2}'; // plane 16

if (!preg_match('/^(?:(?>'.$match.'))+$/s',$str)) {
$res = preg_split('/((?>'.$match.')+)/s',$str,null,PREG_SPLIT_DELIM_CAPTURE);
$res = preg_split('/((?>'.$match.')+)/s',$str,0,PREG_SPLIT_DELIM_CAPTURE);
for($i=0; $i < count($res); $i+=2)
{
$res[$i] = self::convertBytesToEntities(array(1=>$res[$i]));
Expand Down
2 changes: 2 additions & 0 deletions classes/PHPTAL/NothingKeyword.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ public function __toString()
return 'null';
}

#[\ReturnTypeWillChange]
public function count()
{
return 0;
}

#[\ReturnTypeWillChange]
public function jsonSerialize()
{
return null;
Expand Down
2 changes: 1 addition & 1 deletion classes/PHPTAL/Php/Attribute/I18N/Attributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function before(PHPTAL_Php_CodeWriter $codewriter)
list($qname, $key) = $this->parseSetExpression($exp);

// if the translation key is specified and not empty (but may be '0')
if (strlen($key)) {
if ($key !== null && strlen($key) > 0) {
// we use it and replace the tag attribute with the result of the translation
$code = $this->_getTranslationCode($codewriter, $key);
} else {
Expand Down
2 changes: 1 addition & 1 deletion classes/PHPTAL/Php/TalesInternal.php
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ private static function convertExpressionsToExpression(array $array, $nothrow)
*/
public static function compileToPHPExpressions($expression, $nothrow=false)
{
$expression = trim($expression);
$expression = trim($expression ?? '');

// Look for tales modifier (string:, exists:, Namespaced\Tale:, etc...)
if (preg_match('/^([a-z](?:[a-z0-9._\\\\-]*[a-z0-9])?):(.*)$/si', $expression, $m)) {
Expand Down
5 changes: 5 additions & 0 deletions classes/PHPTAL/RepeatController.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public function __construct($source)
*
* @return Mixed The current element value
*/
#[\ReturnTypeWillChange]
public function current()
{
return $this->current;
Expand All @@ -97,6 +98,7 @@ public function current()
*
* @return String/Int The current element key
*/
#[\ReturnTypeWillChange]
public function key()
{
return $this->key;
Expand All @@ -107,6 +109,7 @@ public function key()
*
* @return bool True if the iteration is not finished yet
*/
#[\ReturnTypeWillChange]
public function valid()
{
$valid = $this->valid || $this->validOnNext;
Expand Down Expand Up @@ -142,6 +145,7 @@ public function length()
* Restarts the iteration process going back to the first element
*
*/
#[\ReturnTypeWillChange]
public function rewind()
{
$this->index = 0;
Expand All @@ -168,6 +172,7 @@ public function rewind()
* Fetches the next element in the iteration and advances the pointer
*
*/
#[\ReturnTypeWillChange]
public function next()
{
$this->index++;
Expand Down
4 changes: 3 additions & 1 deletion classes/PHPTAL/Tokenizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ function nextToken()
}

//if (!preg_match_all($this->regex, $this->str, $m, PREG_SET_ORDER, $this->offset)) throw new Exception("FAIL {$this->regex} at {$this->offset}");
if (!preg_match($this->regex, $this->str, $m, null, $this->offset)) throw new Exception("FAIL {$this->regex} didn't match '{$this->str}' at {$this->offset}");
if (!preg_match($this->regex, $this->str, $m, 0, $this->offset)) {
throw new Exception("FAIL {$this->regex} didn't match '{$this->str}' at {$this->offset}");
}

$this->offset += strlen($m[0]); // in bytes

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
}
],
"require": {
"php": "^7.3 || ^8.0"
"php": "~7.4.0 || ~8.0.0 || ~8.1.0"
},
"require-dev": {
"phpunit/phpunit": "^9.5.8"
"phpunit/phpunit": "^9.5.10"
},
"autoload": {
"psr-0": {
Expand Down
Loading

0 comments on commit cc1020a

Please sign in to comment.