feat: add immutable URI query replacement helpers#10268
Conversation
- add immutable URI helpers for replacing and filtering query vars - document the full immutable query helper family - cover clone behavior, raw query strings, fragments, and invalid query strings Signed-off-by: memleakd <121398829+memleakd@users.noreply.github.com>
URI query replacement helpers
michalsn
left a comment
There was a problem hiding this comment.
Thanks, this looks like a good direction to me.
One thing I think would make this clearer for users is adding a small table to the URI user guide that lists the mutable query methods next to their immutable alternatives, for example:
| Mutable method | Immutable alternative |
|---|---|
setQuery() |
withQuery() |
setQueryArray() |
withQueryArray() |
addQuery() |
withQueryVar() / withQueryVars() |
stripQuery() |
withoutQueryVars() |
keepQuery() |
withOnlyQueryVars() |
It would also be useful to add a short note that the with*() methods return a cloned URI and do not modify the original instance, while the older methods modify the current instance.
For the mutable methods, could you also add TODO/docblock notes that they should eventually be deprecated in the next major version in favor of the immutable alternatives?
Maybe something like:
@TODO Deprecated in the next major version. Use withQuery() instead for immutability.
adjusted per method.
|
Actually, this feels like something for a follow-up PR. If you have time and energy to work on it, I would really appreciate it. |
|
Thanks @michalsn, really appreciate the review and approval. I'll leave this PR as-is now and prepare a small follow-up for the docs. |
Description
This PR follows up on the recently added
URI::withQueryVar()/withQueryVars()helpers by adding the remaining immutable query helpers for the existing mutable query APIs:Each method returns a cloned URI and leaves the original instance unchanged.
The naming follows the direction discussed in #10242:
setQuery()->withQuery()setQueryArray()->withQueryArray()stripQuery()->withoutQueryVars()keepQuery()->withOnlyQueryVars()I kept
withQueryParams()out of this because PSR-7 uses that name onServerRequestInterface, notUriInterface, andwithQueryArray()keeps the URI-side API clearer.Tests cover cloning behavior, query replacement, raw query strings, fragments, filtering/removal, and invalid query strings.
Checklist: