Skip to content
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
10 changes: 10 additions & 0 deletions system/HTTP/URI.php
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,8 @@ protected function refreshPath(): self
* to clean the various parts of the query keys and values.
*
* @return $this
*
* @TODO Deprecated in the next major version. Use withQuery() instead for immutability.
*/
public function setQuery(string $query)
{
Expand Down Expand Up @@ -859,6 +861,8 @@ public function withQuery(string $query): static
* portion of the URI.
*
* @return $this
*
* @TODO Deprecated in the next major version. Use withQueryArray() instead for immutability.
*/
public function setQueryArray(array $query)
{
Expand Down Expand Up @@ -891,6 +895,8 @@ public function withQueryArray(array $query): static
* @param int|string|null $value
*
* @return $this
*
* @TODO Deprecated in the next major version. Use withQueryVar() or withQueryVars() instead for immutability.
*/
public function addQuery(string $key, $value = null)
{
Expand Down Expand Up @@ -939,6 +945,8 @@ public function withQueryVars(array $params): static
* @param string ...$params
*
* @return $this
*
* @TODO Deprecated in the next major version. Use withoutQueryVars() instead for immutability.
*/
public function stripQuery(...$params)
{
Expand Down Expand Up @@ -972,6 +980,8 @@ public function withoutQueryVars(string ...$params): static
* @param string ...$params
*
* @return $this
*
* @TODO Deprecated in the next major version. Use withOnlyQueryVars() instead for immutability.
*/
public function keepQuery(...$params)
{
Expand Down
23 changes: 20 additions & 3 deletions user_guide_src/source/libraries/uri.rst
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,25 @@ Changing Query Values Without Mutation

.. versionadded:: 4.8.0

The immutable query methods provide alternatives to the older mutable methods:

+-----------------------+--------------------------------------------+
| Mutable method | Immutable alternative |
+=======================+============================================+
| ``setQuery()`` | ``withQuery()`` |
+-----------------------+--------------------------------------------+
| ``setQueryArray()`` | ``withQueryArray()`` |
+-----------------------+--------------------------------------------+
| ``addQuery()`` | ``withQueryVar()`` / ``withQueryVars()`` |
+-----------------------+--------------------------------------------+
| ``stripQuery()`` | ``withoutQueryVars()`` |
+-----------------------+--------------------------------------------+
| ``keepQuery()`` | ``withOnlyQueryVars()`` |
+-----------------------+--------------------------------------------+

The ``with*()`` methods return a cloned URI instance and do not modify the original URI.
The older mutable methods change the current URI instance.

You can return a new URI instance with its query variables replaced by using the
``withQuery()`` and ``withQueryArray()`` methods:

Expand All @@ -204,13 +223,11 @@ are replaced:

.. literalinclude:: uri/028.php

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

.. literalinclude:: uri/030.php

The original URI instance is not modified.

Filtering Query Values
^^^^^^^^^^^^^^^^^^^^^^

Expand Down
Loading