Skip to content

Commit

Permalink
Merge pull request #158 from koriym/php8.2_support
Browse files Browse the repository at this point in the history
Enable PHP 8.2 compat
  • Loading branch information
koriym authored Dec 13, 2022
2 parents fe17f03 + ef08d24 commit e19f465
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 8 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jobs:
- '7.4'
- '8.0'
- '8.1'
- '8.2'
steps:
- name: Checkout
uses: actions/checkout@v1
Expand All @@ -34,7 +35,7 @@ jobs:

- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- name: Cache dependencies
uses: actions/cache@v2
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"autoload": {
"psr-4": {
"Aura\\Filter\\": "src/"
}
},
"files": ["utf8_to_iso8859_1.php"]
},
"suggest": {
"ext-iconv": "To support UTF-8 in string-length filters.",
Expand Down
8 changes: 4 additions & 4 deletions src/Rule/AbstractCharCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/
namespace Aura\Filter\Rule;

use Aura\Filter\Exception;
use function Aura\Filter\utf8_to_iso8859_1;

/**
*
Expand Down Expand Up @@ -38,7 +38,7 @@ protected function strtolower(string $str): string
return mb_convert_case($str, MB_CASE_LOWER, 'UTF-8');
}

return strtolower(utf8_decode($str));
return strtolower(utf8_to_iso8859_1($str));
}

/**
Expand All @@ -57,7 +57,7 @@ protected function strtoupper(string $str): string
return mb_convert_case($str, MB_CASE_UPPER, 'UTF-8');
}

return strtoupper(utf8_decode($str));
return strtoupper(utf8_to_iso8859_1($str));
}

/**
Expand All @@ -75,7 +75,7 @@ protected function ucwords(string $str): string
return mb_convert_case($str, MB_CASE_TITLE, 'UTF-8');
}

return ucwords(utf8_decode($str));
return ucwords(utf8_to_iso8859_1($str));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Rule/AbstractDateTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ protected function newDateTime($value)

// invalid dates (like 1979-02-29) show up as warnings.
$errors = DateTime::getLastErrors();
if ($errors['warnings']) {
if (is_array($errors) && $errors['warnings']) {
return false;
}

Expand Down
4 changes: 3 additions & 1 deletion src/Rule/AbstractStrlen.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
use Aura\Filter\Exception\MalformedUtf8;
use Aura\Filter\Exception;

use function Aura\Filter\utf8_to_iso8859_1;

/**
*
* Abstract rule for string-length filters; supports the `iconv` and `mbstring`
Expand Down Expand Up @@ -67,7 +69,7 @@ protected function strlen(string $str): int
return mb_strlen($str, 'UTF-8');
}

return strlen(utf8_decode($str));
return strlen(utf8_to_iso8859_1($str));
}

/**
Expand Down
10 changes: 10 additions & 0 deletions src/ValueFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ class ValueFilter
*/
protected $subject;

/**
* @var ValidateLocator
*/
protected $validate_locator;

/**
* @var SanitizeLocator
*/
protected $sanitize_locator;

/**
*
* Constructor.
Expand Down
33 changes: 33 additions & 0 deletions utf8_to_iso8859_1.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
namespace Aura\Filter;

function utf8_to_iso8859_1(string $string): string
{
$s = $string;
$len = \strlen($s);

for ($i = 0, $j = 0; $i < $len; ++$i, ++$j) {
switch ($s[$i] & "\xF0") {
case "\xC0":
case "\xD0":
$c = (\ord($s[$i] & "\x1F") << 6) | \ord($s[++$i] & "\x3F");
$s[$j] = $c < 256 ? \chr($c) : '?';
break;

case "\xF0":
++$i;
// no break

case "\xE0":
$s[$j] = '?';
$i += 2;
break;

default:
$s[$j] = $s[$i];
}
}

return substr($s, 0, $j);
}

0 comments on commit e19f465

Please sign in to comment.