Skip to content
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

[πŸ’‘ FEATURE REQUEST]: Add getter for the PSR7Worker->httpWorker property #21

Merged
merged 3 commits into from
Feb 1, 2024
Merged

[πŸ’‘ FEATURE REQUEST]: Add getter for the PSR7Worker->httpWorker property #21

merged 3 commits into from
Feb 1, 2024

Conversation

FluffyDiscord
Copy link
Contributor

@FluffyDiscord FluffyDiscord commented Jan 31, 2024

Q A
Bugfix? ❌
Breaks BC? ❌
New feature? βœ”οΈ

We are able to get the Spiral Worker from Spiral\RoadRunner\Http\PSR7Worker but for some reason we cannot get the wrapped HttpWorker. This PR fixes that.

Summary by CodeRabbit

  • New Features
    • Introduced a method to obtain HTTP worker instances in the application.
    • Added unit tests to ensure availability of the HTTP worker within the PSR7Worker class.

Copy link

coderabbitai bot commented Jan 31, 2024

Walkthrough

This update introduces an enhancement to the PSR7Worker class by adding a new public method named getHttpWorker. This method allows for the retrieval of an HttpWorker instance, facilitating improved interaction and integration with HTTP services within applications using this class.

Changes

File Change Summary
src/PSR7Worker.php Added getHttpWorker method returning an HttpWorker instance.
tests/Unit/PSR7WorkerTest.php Added PSR7WorkerTest to test getHttpWorker in PSR7Worker.

πŸ‡βœ¨
In the code, a new method takes flight,
getHttpWorker shines, oh so bright.
Through the digital burrow, it hops with ease,
A helpful leap, to fetch with peace.
🌟🐾

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 7a1f7d0 and 4402f93.
Files selected for processing (1)
  • src/PSR7Worker.php (1 hunks)
Additional comments: 13
src/PSR7Worker.php (13)
  • 57-60: The addition of the getHttpWorker method is straightforward and correctly implemented. It provides direct access to the HttpWorker instance as intended by the PR objectives. This method is consistent with the class's design and follows proper PHP syntax and conventions.
  • 54-64: > πŸ“ NOTE

This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [1-1]

The file's declaration and namespace are correctly defined, ensuring that the PSR7Worker class is properly encapsulated within the Spiral\RoadRunner\Http namespace. This is crucial for maintaining the package's structure and avoiding conflicts with classes from other namespaces.

  • 54-64: > πŸ“ NOTE

This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [13-13]

The use of PHP 7.4's typed properties in the class definition enhances type safety and code readability. This modern PHP feature is well-utilized here, contributing to the overall maintainability and robustness of the code.

  • 54-64: > πŸ“ NOTE

This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [33-33]

The constructor's use of dependency injection for ServerRequestFactoryInterface, StreamFactoryInterface, and UploadedFileFactoryInterface is a good practice. It adheres to the SOLID principles, specifically the Dependency Inversion Principle, by depending on abstractions rather than concrete implementations. This design choice facilitates easier testing and future modifications.

  • 54-64: > πŸ“ NOTE

This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [36-36]

Initializing HttpWorker within the constructor and setting $_SERVER to its original state ensures that the PSR7Worker class has all necessary dependencies and context from the start. This approach is clean and avoids potential issues with uninitialized properties or context mismatches.

  • 54-64: > πŸ“ NOTE

This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [43-43]

The getWorker method, which proxies the call to HttpWorker->getWorker(), demonstrates good encapsulation practices. It allows PSR7Worker to expose necessary functionality of the wrapped HttpWorker without breaking encapsulation. This method is a good example of the Facade design pattern, simplifying the interface for clients of PSR7Worker.

  • 62-62: The waitRequest method's implementation, particularly its handling of null returns from HttpWorker->waitRequest(), is correctly done. It ensures that the method can gracefully handle cases where no request is available, returning null as expected. This is an important aspect of robust error handling in asynchronous or event-driven environments.
  • 54-64: > πŸ“ NOTE

This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [73-73]

The respond method's ability to handle both streaming and non-streaming responses based on the chunkSize property is a flexible design choice. It allows for optimized data transfer based on the response size, which can be particularly beneficial in high-performance or resource-constrained environments.

  • 54-64: > πŸ“ NOTE

This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [85-85]

The streamToGenerator method is an innovative use of PHP's generators for streaming response data. This method efficiently handles large responses by breaking them into manageable chunks, reducing memory usage. The implementation is correct and considers both fixed-size and unknown-size streams, ensuring compatibility with various response types.

  • 54-64: > πŸ“ NOTE

This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [108-108]

The configureServer method's approach to reconstructing the $_SERVER superglobal from the RoadRunner request object is thorough and well-implemented. It ensures that the PSR-7 request object created later in the process has a complete and accurate server environment, which is crucial for compatibility with applications expecting certain $_SERVER values.

  • 54-64: > πŸ“ NOTE

This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [138-138]

The mapRequest method's comprehensive mapping from the RoadRunner request to a PSR-7 request object is well-executed. It correctly handles all aspects of the request, including method, URI, headers, cookies, query parameters, uploaded files, and body content. This method is a key component of the class, enabling the seamless integration of RoadRunner with PSR-7 based applications.

  • 54-64: > πŸ“ NOTE

This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [176-176]

The wrapUploads method's handling of uploaded files, converting them to instances of UploadedFileInterface, is correctly implemented. It ensures that files uploaded through RoadRunner requests are properly encapsulated in PSR-7 compliant objects, facilitating their handling in user applications. This method demonstrates attention to detail in adhering to PSR-7 standards.

  • 54-64: > πŸ“ NOTE

This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [198-198]

The static method fetchProtocolVersion correctly normalizes HTTP protocol versions to valid values expected by PSR-7 implementations. This normalization is important for ensuring compatibility across different HTTP clients and servers, especially given the variations in protocol version notation.

@codecov-commenter
Copy link

codecov-commenter commented Feb 1, 2024

Codecov Report

All modified and coverable lines are covered by tests βœ…

Comparison is base (7a1f7d0) 18.85% compared to head (9592623) 21.46%.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@             Coverage Diff              @@
##                3.x      #21      +/-   ##
============================================
+ Coverage     18.85%   21.46%   +2.61%     
- Complexity       60       61       +1     
============================================
  Files             4        4              
  Lines           175      177       +2     
============================================
+ Hits             33       38       +5     
+ Misses          142      139       -3     

β˜” View full report in Codecov by Sentry.
πŸ“’ Have feedback on the report? Share it here.

@msmakouz msmakouz added the enhancement New feature or request label Feb 1, 2024
Copy link
Member

@roxblnfk roxblnfk left a comment

Choose a reason for hiding this comment

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

Without HttpWorker, we don't have the ability to use some specific functionality like early hints.
I think an access to a lower-level abstraction seems like a good solution. However, I would prefer to see all the capabilities of HttpWorker in PSR7Worker.

@roxblnfk
Copy link
Member

roxblnfk commented Feb 1, 2024

BTW @FluffyDiscord could you add some Unit Test to cover this getter?

Copy link
Contributor

@rustatian rustatian left a comment

Choose a reason for hiding this comment

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

lgtm

@FluffyDiscord
Copy link
Contributor Author

BTW @FluffyDiscord could you add some Unit Test to cover this getter?

I guess I can

@FluffyDiscord
Copy link
Contributor Author

Would the last commit do? I am not sure how you would like to create the test, should have asked.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 4402f93 and 9592623.
Files selected for processing (1)
  • tests/Unit/PSR7WorkerTest.php (1 hunks)

tests/Unit/PSR7WorkerTest.php Outdated Show resolved Hide resolved
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 9592623 and 1ca8061.
Files selected for processing (1)
  • tests/Unit/PSR7WorkerTest.php (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • tests/Unit/PSR7WorkerTest.php

@roxblnfk roxblnfk merged commit ddd6432 into roadrunner-php:3.x Feb 1, 2024
5 checks passed
@FluffyDiscord
Copy link
Contributor Author

Would it be possible to release new package version with this feature?

@rustatian
Copy link
Contributor

Yep, will be released shortly.
@msmakouz Could you please take a look and manage the release?

FluffyDiscord added a commit to FluffyDiscord/roadrunner-symfony-bundle that referenced this pull request Feb 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants