Skip to content

Commit 31d0d80

Browse files
committed
fix: adds str_contains polyfill and uses it when possible
1 parent c1adbcb commit 31d0d80

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/Providers/Http/DTO/Request.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public function getUri(): string
114114
{
115115
// If GET request with data, append as query parameters
116116
if ($this->method === HttpMethodEnum::GET() && $this->data !== null && !empty($this->data)) {
117-
$separator = strpos($this->uri, '?') === false ? '?' : '&';
117+
$separator = str_contains($this->uri, '?') ? '&' : '?';
118118
return $this->uri . $separator . http_build_query($this->data);
119119
}
120120

src/polyfills.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,26 @@ function str_starts_with(string $haystack, string $needle): bool
5757
}
5858
}
5959

60+
if (!function_exists('str_contains')) {
61+
/**
62+
* Checks if a string contains a given substring.
63+
*
64+
* @since n.e.x.t
65+
*
66+
* @param string $haystack The string to search in.
67+
* @param string $needle The substring to search for.
68+
* @return bool True if $haystack contains $needle, false otherwise.
69+
*/
70+
function str_contains(string $haystack, string $needle): bool
71+
{
72+
if ('' === $needle) {
73+
return true;
74+
}
75+
76+
return false !== strpos($haystack, $needle);
77+
}
78+
}
79+
6080
if (!function_exists('str_ends_with')) {
6181
/**
6282
* Checks if a string ends with a given substring.

0 commit comments

Comments
 (0)