execute every db command in a transaction in controllers

This commit is contained in:
Bence Pőcze 2023-04-18 22:22:02 +02:00
parent 644197fae8
commit 51801d4228
Signed by: bence
GPG Key ID: DC5BD6E95A333E6D

View File

@ -4,6 +4,7 @@ use SokoWeb\Interfaces\Response\IRedirect;
use SokoWeb\Interfaces\Response\IContent;
use SokoWeb\Interfaces\Authentication\IAuthenticationRequired;
use SokoWeb\Interfaces\Authorization\ISecured;
use SokoWeb\Interfaces\Database\IConnection;
use SokoWeb\Interfaces\Request\IRequest;
use SokoWeb\Response\Redirect;
use SokoWeb\Response\HtmlContent;
@ -14,6 +15,8 @@ class HttpResponse
{
private IRequest $request;
private IConnection $dbConnection;
private RouteCollection $routeCollection;
private array $appConfig;
@ -26,12 +29,14 @@ class HttpResponse
public function __construct(
IRequest $request,
IConnection $dbConnection,
RouteCollection $routeCollection,
array $appConfig,
string $requestMethod,
string $requestUrl
) {
$this->request = $request;
$this->dbConnection = $dbConnection;
$this->routeCollection = $routeCollection;
$this->appConfig = $appConfig;
$this->method = strtolower($requestMethod);
@ -75,7 +80,10 @@ class HttpResponse
return;
}
$this->dbConnection->startTransaction();
$response = call_user_func([$controller, $handler[1]]);
$this->dbConnection->commit();
if ($response instanceof IContent) {
header('Content-Type: ' . $response->getContentType() . '; charset=UTF-8');
$response->render();