Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add PHP 8.4 #236

Merged
merged 1 commit into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading