Skip to content

Commit 1c0fd68

Browse files
committed
refactor: rename URI query var helpers
Signed-off-by: memleakd <121398829+memleakd@users.noreply.github.com>
1 parent a8664e0 commit 1c0fd68

5 files changed

Lines changed: 14 additions & 14 deletions

File tree

‎system/HTTP/URI.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -884,7 +884,7 @@ public function addQuery(string $key, $value = null)
884884
*
885885
* @return static
886886
*/
887-
public function withAddedQueryVar(string $key, $value)
887+
public function withQueryVar(string $key, $value)
888888
{
889889
$uri = clone $this;
890890

@@ -902,7 +902,7 @@ public function withAddedQueryVar(string $key, $value)
902902
*
903903
* @return static
904904
*/
905-
public function withAddedQueryVars(array $params)
905+
public function withQueryVars(array $params)
906906
{
907907
$uri = clone $this;
908908

‎tests/system/HTTP/URITest.php‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -835,45 +835,45 @@ public function testAddQueryVarRespectsExistingQueryVars(): void
835835
$this->assertSame('http://example.com/foo?bar=baz&baz=foz', (string) $uri);
836836
}
837837

838-
public function testWithAddedQueryVarAddsQueryVarWithoutMutatingOriginal(): void
838+
public function testWithQueryVarAddsQueryVarWithoutMutatingOriginal(): void
839839
{
840840
$base = 'http://example.com/foo';
841841
$uri = new URI($base);
842842

843-
$new = $uri->withAddedQueryVar('bar', 'baz');
843+
$new = $uri->withQueryVar('bar', 'baz');
844844

845845
$this->assertSame('http://example.com/foo?bar=baz', (string) $new);
846846
$this->assertSame('http://example.com/foo', (string) $uri);
847847
}
848848

849-
public function testWithAddedQueryVarReplacesQueryVarAndPreservesFragment(): void
849+
public function testWithQueryVarReplacesQueryVarAndPreservesFragment(): void
850850
{
851851
$base = 'http://example.com/foo?bar=baz#section';
852852
$uri = new URI($base);
853853

854-
$new = $uri->withAddedQueryVar('bar', 'foz');
854+
$new = $uri->withQueryVar('bar', 'foz');
855855

856856
$this->assertSame('http://example.com/foo?bar=foz#section', (string) $new);
857857
$this->assertSame('http://example.com/foo?bar=baz#section', (string) $uri);
858858
}
859859

860-
public function testWithAddedQueryVarKeepsEmptyStringQueryVar(): void
860+
public function testWithQueryVarKeepsEmptyStringQueryVar(): void
861861
{
862862
$base = 'http://example.com/foo?bar=baz';
863863
$uri = new URI($base);
864864

865-
$new = $uri->withAddedQueryVar('bar', '');
865+
$new = $uri->withQueryVar('bar', '');
866866

867867
$this->assertSame('http://example.com/foo?bar=', (string) $new);
868868
$this->assertSame('http://example.com/foo?bar=baz', (string) $uri);
869869
}
870870

871-
public function testWithAddedQueryVarsAddsAndReplacesWithoutMutatingOriginal(): void
871+
public function testWithQueryVarsAddsAndReplacesWithoutMutatingOriginal(): void
872872
{
873873
$base = 'http://example.com/foo?foo=bar&bar=baz&baz=foz#section';
874874
$uri = new URI($base);
875875

876-
$new = $uri->withAddedQueryVars([
876+
$new = $uri->withQueryVars([
877877
'baz' => 'updated',
878878
'new' => 'value',
879879
]);

‎user_guide_src/source/changelogs/v4.8.0.rst‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ HTTP
276276
- ``CLIRequest`` now supports options with values specified using an equals sign (e.g., ``--option=value``) in addition to the existing space-separated syntax (e.g., ``--option value``).
277277
This provides more flexibility in how you can pass options to CLI requests.
278278
- Added ``$enableStyleNonce`` and ``$enableScriptNonce`` options to ``Config\App`` to automatically add nonces to control whether to add nonces to style-* and script-* directives in the Content Security Policy (CSP) header when CSP is enabled. See :ref:`csp-control-nonce-generation` for details.
279-
- Added ``URI::withAddedQueryVar()`` and ``URI::withAddedQueryVars()`` to return a cloned URI with query variables added or replaced.
279+
- Added ``URI::withQueryVar()`` and ``URI::withQueryVars()`` to return a cloned URI with query variables added or replaced.
280280
- ``URI`` now accepts an optional boolean second parameter in the constructor, defaulting to ``false``, to control how the query string is parsed in instantiation.
281281
This is the behavior of ``->useRawQueryString()`` brought into the constructor for convenience. Previously, you need to call ``$uri->useRawQueryString(true)->setURI($uri)`` to get this behavior.
282282
Now you can simply do ``new URI($uri, true)``.

‎user_guide_src/source/libraries/uri.rst‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ Changing Query Values Without Mutation
194194
.. versionadded:: 4.8.0
195195

196196
You can return a new URI instance with one or more query variables added or replaced by using the
197-
``withAddedQueryVar()`` and ``withAddedQueryVars()`` methods. Existing query variables are preserved unless they
197+
``withQueryVar()`` and ``withQueryVars()`` methods. Existing query variables are preserved unless they
198198
are replaced:
199199

200200
.. literalinclude:: uri/028.php

‎user_guide_src/source/libraries/uri/028.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
$uri = new \CodeIgniter\HTTP\URI('https://example.com/users?q=bob&page=1');
44

5-
$nextPage = $uri->withAddedQueryVar('page', 2);
5+
$nextPage = $uri->withQueryVar('page', 2);
66
// https://example.com/users?q=bob&page=2
77

8-
$filtered = $uri->withAddedQueryVars([
8+
$filtered = $uri->withQueryVars([
99
'q' => 'alice',
1010
'page' => 1,
1111
'role' => 'admin',

0 commit comments

Comments
 (0)