- Notifications
You must be signed in to change notification settings - Fork 8
feat: add support for PSR-7 ServerRequest #108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
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
Implements feature request #25 by adding support for PSR-7 ServerRequest objects to the HAR library. Changes: - Add Request::fromPsr7ServerRequest() method to convert PSR-7 ServerRequest to HAR Request format - Create ServerRequest adapter class (Adapter\Psr7\ServerRequest) that implements ServerRequestInterface - ServerRequest adapter supports all PSR-7 ServerRequest features: - Server parameters (getServerParams) - Cookie parameters (getCookieParams, withCookieParams) - Query parameters (getQueryParams, withQueryParams) - Parsed body (getParsedBody, withParsedBody) - Uploaded files (getUploadedFiles, withUploadedFiles) - Attributes (getAttributes, getAttribute, withAttribute, withoutAttribute) - Add comprehensive unit tests for both the conversion method and adapter - Fix null return type issues in Request::getQueryString(), CookiesTrait::getCookies(), and MimeTypeTrait::getMimeType() - Update PostData to use Query::build() instead of deprecated build_query() All tests passing (67 tests, 165 assertions).
57d4444 to 8b21a77 Compare Simplifies the ServerRequest constructor to only accept a HAR Request parameter, similar to the parent Request adapter. This improves consistency and follows the immutability pattern established in the codebase. Changes: - ServerRequest constructor now only accepts \Deviantintegral\Har\Request - Request parameter is cloned to preserve immutability - All ServerRequest-specific properties initialized from HAR request - All `with*` methods use clone pattern instead of constructor parameters - Add `withServerParams()` method for testing/internal use - Use reflection to update both MessageBase::$message and Request::$request properties when modifying the underlying HAR request - Update Request::fromPsr7ServerRequest() to extract cookies and query params directly from PSR-7 ServerRequest - Update tests to use builder pattern with `with*` methods All tests passing (67 tests, 165 assertions).
Removes all properties and functionality from ServerRequest that are not part of the HAR specification, making it a lossy conversion as intended. Changes: - Remove serverParams, uploadedFiles, and attributes properties - getServerParams() now always returns empty array - getUploadedFiles() now always returns empty array - getAttributes() now always returns empty array - getAttribute() now always returns the default value - withUploadedFiles(), withAttribute(), withoutAttribute() are now no-ops that return clones without storing any data - Keep cookieParams, queryParams, and parsedBody as they can be derived from HAR specification (cookies, queryString, postData) - Update tests to reflect lossy conversion behavior This makes ServerRequest a pure HAR-based adapter. When converting from PSR-7 ServerRequest to HAR Request, only HAR-supported data is preserved. When converting back, non-HAR properties will be empty/default values. All tests passing (67 tests, 164 assertions).
Refactors ServerRequest to follow the same pattern as the Request adapter by deriving all values from the underlying HAR request instead of storing them as separate properties. Changes: - Remove $cookieParams, $queryParams, and $parsedBody properties - All getters now derive values from getHarRequest() on-the-fly - All with* methods clone the HAR request, modify it, and return new static($request) - Remove cloneWithHarRequest() helper and reflection code - Simplify overridden parent methods to use new static($request) pattern - Ensure immutability by always creating new PostData objects in withParsedBody This makes ServerRequest completely stateless - all state is stored in the HAR request object, following the same pattern as the parent Request adapter. All tests passing (67 tests, 164 assertions).
Adds 8 new test methods to achieve complete code coverage of the ServerRequest adapter class. New tests: - testGetParsedBodyWithNoPostData: Tests null return when no post data - testGetParsedBodyWithFormUrlEncodedText: Tests parsing form-encoded text - testGetParsedBodyWithNonFormEncodedText: Tests null return for non-form content - testWithParsedBodyObject: Tests withParsedBody() with object parameter - testWithRequestTarget: Tests withRequestTarget() override - testWithAddedHeader: Tests withAddedHeader() override - testWithoutHeader: Tests withoutHeader() override - testWithProtocolVersion: Tests withProtocolVersion() override All tests verify that ServerRequest state (cookies, query params) is preserved across operations, ensuring immutability. Test results: 75 tests, 179 assertions (up from 67/164)
This was referenced Dec 12, 2025
Closed
deviantintegral added a commit that referenced this pull request Dec 14, 2025
🤖 I have created a release *beep* *boop* --- ## [0.4.0](0.3.0...v0.4.0) (2025-12-14) ### Features * add pre-commit hooks for php-cs-fixer and phpunit ([#109](#109)) ([80a12c4](80a12c4)) * add support for PSR-7 ServerRequest ([#108](#108)) ([7df2364](7df2364)) * drop support for PHP 8.0 and 8.1 ([#104](#104)) ([2241b8d](2241b8d)) ### Bug Fixes * set release-please manifest version to 0.4.0 ([72ccbee](72ccbee)) ### Miscellaneous Chores * **config:** migrate Renovate config ([#98](#98)) ([83d168d](83d168d)) * **deps:** update actions/upload-artifact action to v6 ([#107](#107)) ([54c890a](54c890a)) * fix nullable param deprecation ([#110](#110)) ([79ced46](79ced46)) * upgrade PHPUnit to ^11||^12 ([#106](#106)) ([4617172](4617172)) * upgrade symfony/console to ^7||^8 ([#105](#105)) ([4002a2c](4002a2c)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
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.
Implements feature request #25 by adding support for PSR-7 ServerRequest objects to the HAR library.
Changes:
refs: #25