public static function Uri::withQueryValue in Zircon Profile 8
Same name and namespace in other branches
- 8.0 vendor/guzzlehttp/psr7/src/Uri.php \GuzzleHttp\Psr7\Uri::withQueryValue()
Create a new URI with a specific query string value.
Any existing query string values that exactly match the provided key are removed and replaced with the given key value pair.
Note: this function will convert "=" to "%3D" and "&" to "%26".
Parameters
UriInterface $uri URI to use as a base.:
string $key Key to set.:
string $value Value to set.:
Return value
1 call to Uri::withQueryValue()
- UriTest::testAddAndRemoveQueryValues in vendor/
guzzlehttp/ psr7/ tests/ UriTest.php
File
- vendor/
guzzlehttp/ psr7/ src/ Uri.php, line 230
Class
- Uri
- Basic PSR-7 URI implementation.
Namespace
GuzzleHttp\Psr7Code
public static function withQueryValue(UriInterface $uri, $key, $value) {
$current = $uri
->getQuery();
$key = strtr($key, self::$replaceQuery);
if (!$current) {
$result = [];
}
else {
$result = [];
foreach (explode('&', $current) as $part) {
if (explode('=', $part)[0] !== $key) {
$result[] = $part;
}
}
}
if ($value !== null) {
$result[] = $key . '=' . strtr($value, self::$replaceQuery);
}
else {
$result[] = $key;
}
return $uri
->withQuery(implode('&', $result));
}