Skip to content

Extract FileExtension routine from Accept content negotiation#175

Merged
alganet merged 1 commit intoRespect:masterfrom
alganet:file-ext
Mar 18, 2026
Merged

Extract FileExtension routine from Accept content negotiation#175
alganet merged 1 commit intoRespect:masterfrom
alganet:file-ext

Conversation

@alganet
Copy link
Member

@alganet alganet commented Mar 18, 2026

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.

@alganet alganet requested a review from Copilot March 18, 2026 06:14
@alganet alganet marked this pull request as ready for review March 18, 2026 06:15
@codecov-commenter
Copy link

codecov-commenter commented Mar 18, 2026

Codecov Report

❌ Patch coverage is 95.74468% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 96.67%. Comparing base (089f417) to head (8cf6a7b).

Files with missing lines Patch % Lines
src/Routines/FileExtension.php 92.59% 2 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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/FileExtension to 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.
@alganet alganet merged commit 94d7d69 into Respect:master Mar 18, 2026
3 checks passed
@alganet alganet deleted the file-ext branch March 18, 2026 06:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants