Extract FileExtension routine from Accept content negotiation#175
Extract FileExtension routine from Accept content negotiation#175alganet merged 1 commit intoRespect:masterfrom
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #175 +/- ##
============================================
- Coverage 96.68% 96.67% -0.02%
- Complexity 418 430 +12
============================================
Files 30 31 +1
Lines 1056 1082 +26
============================================
+ Hits 1021 1046 +25
- Misses 35 36 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR separates URL file-extension handling from Accept header content negotiation by introducing a dedicated FileExtension routine and updating route matching so only declared extensions are stripped (preserving dots in normal path segments like john.doe).
Changes:
- Add
src/Routines/FileExtensionto map declared URL extensions (e.g..json,.html) to response transforms, with support for cascading compound extensions (e.g..json.en). - Remove URL-extension behavior from
AbstractAccept, making it purely header-based negotiation. - Update route matching + tests/docs/examples to use
fileExtension()and ensure only declared extensions are stripped.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
src/Routines/FileExtension.php |
New routine for extension-based response transforms and extension “peeling”. |
src/Routes/AbstractRoute.php |
Updates matching to strip only declared extensions and stores remaining suffix for routines. |
src/Routines/AbstractAccept.php |
Removes URL-extension coupling; keeps negotiation header-only. |
src/Routines/IgnorableFileExtension.php |
Promotes marker interface to a real contract via getExtensions(). |
tests/Routes/AbstractRouteTest.php |
Adjusts extension-stripping assertions to match new behavior. |
tests/RouterTest.php |
Renames/updates URL extension tests; adds cascade + leniency + exception/global-accept tests. |
docs/README.md |
Adds fileExtension() documentation section. |
example/full.php |
Adds a fileExtension() usage example for JSON/HTML. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
Add a dedicated FileExtension routine that handles URL extension mapping (.json, .html, etc.) independently from Accept header negotiation. Only declared extensions are stripped during route matching, so dots in paths like /users/john.doe no longer get mangled. Multiple FileExtension routines can cascade for compound extensions like .json.en — each peels its extension from right to left. Decouple AbstractAccept from IgnorableFileExtension entirely, making it pure header-based content negotiation. Promote IgnorableFileExtension from marker interface to a real interface with getExtensions() so route matching knows exactly which extensions to strip.
Add a dedicated FileExtension routine that handles URL extension mapping (.json, .html, etc.) independently from Accept header negotiation. Only declared extensions are stripped during route matching, so dots in paths like /users/john.doe no longer get mangled.
Multiple FileExtension routines can cascade for compound extensions like .json.en — each peels its extension from right to left.
Decouple AbstractAccept from IgnorableFileExtension entirely, making it pure header-based content negotiation. Promote IgnorableFileExtension from marker interface to a real interface with getExtensions() so route matching knows exactly which extensions to strip.