Skip to content

feat: add immutable URI query replacement helpers#10268

Open
memleakd wants to merge 1 commit into
codeigniter4:4.8from
memleakd:feat/uri-query-immutable-helpers
Open

feat: add immutable URI query replacement helpers#10268
memleakd wants to merge 1 commit into
codeigniter4:4.8from
memleakd:feat/uri-query-immutable-helpers

Conversation

@memleakd
Copy link
Copy Markdown
Contributor

@memleakd memleakd commented Jun 1, 2026

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:

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

$next = $uri->withQuery('page=2');

$filtered = $uri->withQueryArray([
    'q'    => 'alice',
    'role' => 'admin',
]);

$withoutPage = $uri->withoutQueryVars('page');

$onlyFilters = $uri->withOnlyQueryVars('q', 'role');

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 on ServerRequestInterface, not UriInterface, and withQueryArray() keeps the URI-side API clearer.

Tests cover cloning behavior, query replacement, raw query strings, fragments, filtering/removal, and invalid query strings.

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value (without duplication)
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

- 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>
@github-actions github-actions Bot added the 4.8 PRs that target the `4.8` branch. label Jun 1, 2026
@memleakd memleakd changed the title feat: add immutable URI query replacement helpers feat: add immutable URI query replacement helpers Jun 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

4.8 PRs that target the `4.8` branch.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant