Skip to content

feat: resolve spark routes filters for custom placeholders#10263

Open
paulbalandan wants to merge 2 commits into
codeigniter4:4.8from
paulbalandan:sample-uri-generator
Open

feat: resolve spark routes filters for custom placeholders#10263
paulbalandan wants to merge 2 commits into
codeigniter4:4.8from
paulbalandan:sample-uri-generator

Conversation

@paulbalandan
Copy link
Copy Markdown
Member

Description
php spark routes printed <unknown> in the Before/After Filters columns for any route using a custom placeholder registered with $routes->addPlaceholder(). SampleURIGenerator had no sample for such placeholders and substituted
::unknown::, producing a URI that matched no route, so FilterCollector could not resolve its filters. Filter execution at request time was unaffected. This was only the command's display, as confirmed in the issue.

This adds two ways to obtain a sample URI for a custom placeholder:

  • PlaceholderSampleGenerator derives a value from the placeholder's regular expression, covering the fragments common in route patterns (character classes, shorthand escapes, quantifiers, literals, top-level alternation, anchors). Patterns it cannot reverse (lookarounds, backreferences, named groups, etc.) return null, and every candidate is validated with preg_match before use.
  • Config\Routing::$placeholderSamples lets you set or override the sample per placeholder. A value that does not match the placeholder regex is ignored.

SampleURIGenerator resolves each placeholder in this order: a matching$placeholderSamples value, the built-in sample, an auto-generated value, then ::unknown::. Results are memoized per placeholder.

Common patterns such as [A-Z]{3}[0-9]+ and UUIDs now resolve without any configuration. The user guide, changelog, and upgrade notes are updated.

Fixes #9804
Supersedes and closes #10206

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

@github-actions github-actions Bot added the 4.8 PRs that target the `4.8` branch. label Jun 1, 2026
@paulbalandan paulbalandan force-pushed the sample-uri-generator branch from 26ff99a to a17baae Compare June 1, 2026 05:26
Comment thread system/Commands/Utilities/Routes/SampleURIGenerator.php Outdated
Copy link
Copy Markdown
Member

@michalsn michalsn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks!

Bottom line... That's pretty compex for something that's supposed to handle such a small feature ;)

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.

Bug: Route Filters Are Ignored When Using Custom Placeholders in Routing

2 participants