feat: Add dual PSR-7 version support and related documentation#8
Merged
Conversation
- Introduced compatibility for both PSR-7 v1.x and v2.x in PivotPHP. - Added scripts for switching between PSR-7 versions and checking the current version. - Updated composer.json to enforce PSR-7 v2.0 as the default while allowing v1.x. - Enhanced README.md with instructions for version switching and compatibility details. - Created detailed implementation summary and PSR-7 compatibility status documentation. - Implemented Psr7VersionDetector for automatic version detection. - Added Psr7V1CompatibilityTrait for PHPDoc annotations to support v1.x. - Refactored HTTP components to maintain compliance with both PSR-7 versions. - Improved testing and validation scripts for both PSR-7 versions.
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR adds support for both PSR-7 v1.x and v2.x in PivotPHP by introducing automatic detection, version-switching scripts, updated composer constraints, PHPDoc compatibility traits, and extensive documentation updates.
- Implemented a
Psr7VersionDetectorfor runtime PSR-7 version detection. - Added scripts (
switch-psr7-version.php,adapt-psr7-v1.php) to toggle return-type signatures and update composer requirements. - Updated documentation (
docs/technical/*) andcomposer.jsonfor dual PSR-7 compatibility.
Reviewed Changes
Copilot reviewed 20 out of 20 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/Http/Psr7/* (multiple) | Removed/added return types on PSR-7 methods for v1/v2 compatibility |
| src/Http/Psr7/Factory/Psr7VersionDetector.php | Added version detection logic |
| src/Http/Psr7/Psr7V1CompatibilityTrait.php | Introduced PHPDoc stubs for v1.x |
| scripts/switch-psr7-version.php | Script to switch between PSR-7 versions |
| scripts/adapt-psr7-v1.php | Script to strip return types for v1.x |
| composer.json | Adjusted PSR-7 requirement |
| docs/technical/http/README.md | Expanded HTTP component docs with PSR-7 dual-support section |
| docs/technical/compatibility/psr7-*.md | New compatibility guides |
Comments suppressed due to low confidence (5)
README.md:150
- The README mentions a
--checkflag, but the switch script only accepts1or2; update the documentation or implement support for--checkin the script to avoid confusion.
php scripts/switch-psr7-version.php --check
docs/technical/http/README.md:125
- The example references
withHeaderStrict, which is not defined in the PSR-7 implementation; either remove this call or provide its implementation details.
$response = $response->withHeaderStrict('X-Custom', $value);
src/Http/Psr7/Uri.php:66
- [nitpick] When targeting PSR-7 v1.x (no native return types), consider adding
@return stringto the docblock ofgetScheme()(and similar methods) to maintain IDE and static analysis support.
public function getScheme()
src/Http/Psr7/Factory/Psr7VersionDetector.php:22
- Add unit tests for
Psr7VersionDetector::getVersion(),isV1(), andisV2()to validate correct detection across environments and to ensure the version cache reset works as expected.
public static function getVersion(): string
composer.json:42
- The composer constraint now only allows PSR-7 v1.x; to match the PR description and support both versions (or default to v2.x), restore the constraint to "^1.1|^2.0" or set a default of "^2.0" while allowing "^1.1".
"psr/http-message": "^1.1",
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull Request Template
📋 Descrição
Descreva resumidamente as mudanças feitas neste PR.
🎯 Tipo de Mudança
🧪 Como foi testado?
Descreva os testes que você executou para verificar suas mudanças.
📝 Checklist
🔗 Issues Relacionadas
Fixes #7