Skip to content

Commit

Permalink
feat: add PHP 8.4
Browse files Browse the repository at this point in the history
  • Loading branch information
rancoud committed Dec 6, 2024
1 parent ec3a592 commit 787a6b3
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ jobs:
- '8.1'
- '8.2'
- '8.3'
- '8.4'

steps:
- name: Checkout
Expand Down Expand Up @@ -69,4 +70,4 @@ jobs:
if: success()
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: ./coverage/clover.xml
files: ./coverage/clover.xml
2 changes: 1 addition & 1 deletion .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
21 changes: 19 additions & 2 deletions src/Message/MessageTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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
*
Expand Down
19 changes: 18 additions & 1 deletion src/Message/Uri.php
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ protected static function createUriString(
}
} elseif (isset($charAtPosOne) && $charAtPosOne === '/') {
if ($authority === '') {
$path = '/' . \ltrim($path, '/');
$path = '/' . static::ltrim($path, '/');
}
}

Expand All @@ -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
Expand Down

0 comments on commit 787a6b3

Please sign in to comment.