Skip to content

Refactor Application to return Response from processRequest #350

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

bckp
Copy link
Contributor

@bckp bckp commented Jun 22, 2025

  • bug fix / new feature?
    refactor
  • BC break?
    yes
  • doc PR: nette/docs
    not yet, i will add it when i know this PR can be merged

Changed Application::processRequest to return a Response object instead of sending it directly. Updated run() to call send() on the returned Response. This improves testability and separation of concerns by decoupling request processing from response sending.

This is code regarding my issue #348, this would really help us create long-running application, as with simple change we can run processRequest and get response for PSR response, all other stuff can be done, but without this, we are forced to do ob_cache and it is not nice solution :)

Changed Application::processRequest to return a Response object instead of sending it directly. Updated run() to call send() on the returned Response. This improves testability and separation of concerns by decoupling request processing from response sending.
@Copilot Copilot AI review requested due to automatic review settings June 22, 2025 19:33
Copy link

@Copilot 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 refactors the Application class to decouple request processing from response sending by having processRequest return a Response object rather than sending it directly. Key changes include updating the run() method to call send() on the Response, modifying processRequest’s return type, and adjusting error handling accordingly.

Comments suppressed due to low confidence (1)

src/Application/Application.php:124

  • Update the PHPDoc block for processRequest to reflect that it now returns a Response object instead of void. This improves clarity and API documentation.
	public function processRequest(Request $request): Response

@@ -74,15 +74,15 @@ public function run(): void
{
try {
Arrays::invoke($this->onStartup, $this);
$this->processRequest($this->createInitialRequest());
$this->processRequest($this->createInitialRequest())->send($this->httpRequest, $this->httpResponse);
Copy link
Preview

Copilot AI Jun 22, 2025

Choose a reason for hiding this comment

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

[nitpick] For enhanced readability and debugging, consider storing the returned Response in a temporary variable before calling send().

Suggested change
$this->processRequest($this->createInitialRequest())->send($this->httpRequest, $this->httpResponse);
$response = $this->processRequest($this->createInitialRequest());
$response->send($this->httpRequest, $this->httpResponse);

Copilot uses AI. Check for mistakes.

Arrays::invoke($this->onShutdown, $this);

} catch (\Throwable $e) {
$this->sendHttpCode($e);
Arrays::invoke($this->onError, $this, $e);
if ($this->catchExceptions && ($req = $this->createErrorRequest($e))) {
try {
$this->processRequest($req);
$this->processRequest($req)->send($this->httpRequest, $this->httpResponse);
Copy link
Preview

Copilot AI Jun 22, 2025

Choose a reason for hiding this comment

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

[nitpick] For consistency with the run() method, consider assigning the returned Response to a variable before invoking send(), which can help with error handling and debugging.

Suggested change
$this->processRequest($req)->send($this->httpRequest, $this->httpResponse);
$response = $this->processRequest($req);
$response->send($this->httpRequest, $this->httpResponse);

Copilot uses AI. Check for mistakes.

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.

1 participant