Skip to content

Conversation

@deviantintegral
Copy link
Owner

@deviantintegral deviantintegral commented Dec 12, 2025

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 that are also supported by the HAR spec.
  • Fix null return type issues in Request::getQueryString(), CookiesTrait::getCookies(), and MimeTypeTrait::getMimeType()
  • Update PostData to use Query::build() instead of deprecated build_query()

refs: #25

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).
@deviantintegral deviantintegral force-pushed the claude/implement-issue-25-XIXN1 branch from 57d4444 to 8b21a77 Compare December 12, 2025 21:23
claude and others added 8 commits December 12, 2025 21:41
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)
@deviantintegral deviantintegral merged commit 7df2364 into main Dec 14, 2025
8 of 11 checks passed
This was referenced Dec 12, 2025
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

Labels

None yet

3 participants