diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c49f43f..cef40f1 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -27,6 +27,7 @@ jobs: - '8.1' - '8.2' - '8.3' + - '8.4' steps: - name: Checkout @@ -69,4 +70,4 @@ jobs: if: success() with: token: ${{ secrets.CODECOV_TOKEN }} - file: ./coverage/clover.xml + files: ./coverage/clover.xml diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php index 7ba8371..2658d79 100644 --- a/.php-cs-fixer.php +++ b/.php-cs-fixer.php @@ -22,7 +22,7 @@ 'declare_strict_types' => true, 'global_namespace_import' => false, 'linebreak_after_opening_tag' => true, - 'mb_str_functions' => true, + 'mb_str_functions' => false, // turn off because of PHP 8.4 'native_function_invocation' => [ 'include' => [ '@all' diff --git a/src/Message/MessageTrait.php b/src/Message/MessageTrait.php index d6a8a55..6094af1 100644 --- a/src/Message/MessageTrait.php +++ b/src/Message/MessageTrait.php @@ -258,7 +258,7 @@ protected function validateAndTrimHeader($header, $values): array throw new \InvalidArgumentException('Header value must be RFC 7230 compatible string.'); } - return [\trim((string) $values, " \t")]; + return [$this->trim((string) $values, " \t")]; } if (empty($values)) { @@ -271,12 +271,29 @@ protected function validateAndTrimHeader($header, $values): array throw new \InvalidArgumentException('Header values must be RFC 7230 compatible strings.'); } - $returnValues[] = \trim((string) $v, " \t"); + $returnValues[] = $this->trim((string) $v, " \t"); } return $returnValues; } + /** + * Because of PHP 8.4. + * + * @param $string + * @param string $characters + * + * @return string + */ + protected function trim($string, string $characters = " \n\r\t\v\0"): string + { + if (\PHP_MAJOR_VERSION >= 8 && \PHP_MINOR_VERSION >= 4) { + return \mb_trim((string) $string, $characters); + } + + return \trim((string) $string, $characters); + } + /** * @param string $protocolVersion * diff --git a/src/Message/Uri.php b/src/Message/Uri.php index 18163db..422e06e 100644 --- a/src/Message/Uri.php +++ b/src/Message/Uri.php @@ -383,7 +383,7 @@ protected static function createUriString( } } elseif (isset($charAtPosOne) && $charAtPosOne === '/') { if ($authority === '') { - $path = '/' . \ltrim($path, '/'); + $path = '/' . static::ltrim($path, '/'); } } @@ -401,6 +401,23 @@ protected static function createUriString( return $uri; } + /** + * Because of PHP 8.4. + * + * @param $string + * @param string $characters + * + * @return string + */ + protected static function ltrim($string, string $characters = " \n\r\t\v\0"): string + { + if (\PHP_MAJOR_VERSION >= 8 && \PHP_MINOR_VERSION >= 4) { + return \mb_ltrim((string) $string, $characters); + } + + return \ltrim((string) $string, $characters); + } + /** * @param string $scheme * @param int $port