Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions src/http/StatelessApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,12 @@ public function handle(ServerRequestInterface $request): ResponseInterface

$this->state = self::STATE_END;

return $this->terminate($response);
$psrResponse = $this->terminate($response);
} catch (Throwable $e) {
return $this->terminate($this->handleError($e));
$psrResponse = $this->terminate($this->handleError($e));
}

return $psrResponse;
}

/**
Expand Down Expand Up @@ -373,7 +375,7 @@ protected static function parseMemoryLimit(string $limit): int
* Resets the StatelessApplication state and prepares the Yii2 environment for handling a PSR-7 request.
*
* Performs a full reinitialization of the application state, including event tracking, error handler cleanup,
* session management, and PSR-7 request injection.
* request adapter reset, session management, and PSR-7 request injection.
*
* This method ensures that the application is ready to process a new stateless request in worker or SAPI
* environments, maintaining strict type safety and compatibility with Yii2 core components.
Expand Down Expand Up @@ -406,6 +408,7 @@ protected function reset(ServerRequestInterface $request): void
$this->requestedParams = [];

$this->errorHandler->setResponse($this->response);
$this->request->reset();
$this->request->setPsr7Request($request);

$this->session->close();
Expand All @@ -423,7 +426,7 @@ protected function reset(ServerRequestInterface $request): void
/**
* Finalizes the application lifecycle and converts the Yii2 Response to a PSR-7 ResponseInterface.
*
* Cleans up registered events, resets uploaded files, flushes the logger, and resets the request state.
* Cleans up registered events, resets uploaded files, flushes the logger.
*
* This method ensures that all application resources are released and the response is converted to a PSR-7
* ResponseInterface for interoperability with PSR-7 compatible HTTP stacks.
Expand All @@ -443,8 +446,6 @@ protected function terminate(Response $response): ResponseInterface

Yii::getLogger()->flush(true);

$this->request->reset();

return $response->getPsr7Response();
}

Expand Down
Loading