Skip to content

Commit b8c152d

Browse files
authored
docs(uri): clarify mutable query alternatives (#10348)
- add a user guide table mapping mutable query methods to immutable helpers - note that immutable query helpers clone the URI instead of mutating it - add TODO notes for future mutable query method deprecations Signed-off-by: memleakd <121398829+memleakd@users.noreply.github.com>
1 parent 4e8c5de commit b8c152d

2 files changed

Lines changed: 30 additions & 3 deletions

File tree

system/HTTP/URI.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,8 @@ protected function refreshPath(): self
817817
* to clean the various parts of the query keys and values.
818818
*
819819
* @return $this
820+
*
821+
* @TODO Deprecated in the next major version. Use withQuery() instead for immutability.
820822
*/
821823
public function setQuery(string $query)
822824
{
@@ -859,6 +861,8 @@ public function withQuery(string $query): static
859861
* portion of the URI.
860862
*
861863
* @return $this
864+
*
865+
* @TODO Deprecated in the next major version. Use withQueryArray() instead for immutability.
862866
*/
863867
public function setQueryArray(array $query)
864868
{
@@ -891,6 +895,8 @@ public function withQueryArray(array $query): static
891895
* @param int|string|null $value
892896
*
893897
* @return $this
898+
*
899+
* @TODO Deprecated in the next major version. Use withQueryVar() or withQueryVars() instead for immutability.
894900
*/
895901
public function addQuery(string $key, $value = null)
896902
{
@@ -939,6 +945,8 @@ public function withQueryVars(array $params): static
939945
* @param string ...$params
940946
*
941947
* @return $this
948+
*
949+
* @TODO Deprecated in the next major version. Use withoutQueryVars() instead for immutability.
942950
*/
943951
public function stripQuery(...$params)
944952
{
@@ -972,6 +980,8 @@ public function withoutQueryVars(string ...$params): static
972980
* @param string ...$params
973981
*
974982
* @return $this
983+
*
984+
* @TODO Deprecated in the next major version. Use withOnlyQueryVars() instead for immutability.
975985
*/
976986
public function keepQuery(...$params)
977987
{

user_guide_src/source/libraries/uri.rst

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,25 @@ Changing Query Values Without Mutation
193193

194194
.. versionadded:: 4.8.0
195195

196+
The immutable query methods provide alternatives to the older mutable methods:
197+
198+
+-----------------------+--------------------------------------------+
199+
| Mutable method | Immutable alternative |
200+
+=======================+============================================+
201+
| ``setQuery()`` | ``withQuery()`` |
202+
+-----------------------+--------------------------------------------+
203+
| ``setQueryArray()`` | ``withQueryArray()`` |
204+
+-----------------------+--------------------------------------------+
205+
| ``addQuery()`` | ``withQueryVar()`` / ``withQueryVars()`` |
206+
+-----------------------+--------------------------------------------+
207+
| ``stripQuery()`` | ``withoutQueryVars()`` |
208+
+-----------------------+--------------------------------------------+
209+
| ``keepQuery()`` | ``withOnlyQueryVars()`` |
210+
+-----------------------+--------------------------------------------+
211+
212+
The ``with*()`` methods return a cloned URI instance and do not modify the original URI.
213+
The older mutable methods change the current URI instance.
214+
196215
You can return a new URI instance with its query variables replaced by using the
197216
``withQuery()`` and ``withQueryArray()`` methods:
198217

@@ -204,13 +223,11 @@ are replaced:
204223

205224
.. literalinclude:: uri/028.php
206225

207-
You can also return a new URI instance with query variables removed or filtered by using the
226+
You can return a new URI instance with query variables removed or filtered by using the
208227
``withoutQueryVars()`` and ``withOnlyQueryVars()`` methods:
209228

210229
.. literalinclude:: uri/030.php
211230

212-
The original URI instance is not modified.
213-
214231
Filtering Query Values
215232
^^^^^^^^^^^^^^^^^^^^^^
216233

0 commit comments

Comments
 (0)