Compare commits
2 Commits
2c18f74f97
...
a1e05da920
Author | SHA1 | Date | |
---|---|---|---|
a1e05da920 | |||
64d7972cec |
6
Jenkinsfile
vendored
6
Jenkinsfile
vendored
@ -32,7 +32,7 @@ pipeline {
|
|||||||
sh 'vendor/bin/phpunit --log-junit unit_test_results.xml --testdox tests'
|
sh 'vendor/bin/phpunit --log-junit unit_test_results.xml --testdox tests'
|
||||||
}
|
}
|
||||||
post {
|
post {
|
||||||
always {
|
success {
|
||||||
archiveArtifacts 'unit_test_results.xml'
|
archiveArtifacts 'unit_test_results.xml'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -47,10 +47,10 @@ pipeline {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
steps {
|
steps {
|
||||||
sh 'php -d memory_limit=1G vendor/bin/phpstan analyse -c phpstan.neon --error-format=prettyJson > static_code_analysis_results.json'
|
sh 'php vendor/bin/phpstan analyse -c phpstan.neon --error-format=prettyJson > static_code_analysis_results.json'
|
||||||
}
|
}
|
||||||
post {
|
post {
|
||||||
always {
|
success {
|
||||||
archiveArtifacts 'static_code_analysis_results.json'
|
archiveArtifacts 'static_code_analysis_results.json'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,9 @@
|
|||||||
<?php namespace SokoWeb\Response;
|
<?php namespace SokoWeb\Response;
|
||||||
|
|
||||||
use ErrorException;
|
|
||||||
use Exception;
|
|
||||||
use SokoWeb\Interfaces\Response\IRedirect;
|
use SokoWeb\Interfaces\Response\IRedirect;
|
||||||
use SokoWeb\Interfaces\Response\IContent;
|
use SokoWeb\Interfaces\Response\IContent;
|
||||||
use SokoWeb\Interfaces\Authentication\IAuthenticationRequired;
|
use SokoWeb\Interfaces\Authentication\IAuthenticationRequired;
|
||||||
use SokoWeb\Interfaces\Authorization\ISecured;
|
use SokoWeb\Interfaces\Authorization\ISecured;
|
||||||
use SokoWeb\Interfaces\Database\IConnection;
|
|
||||||
use SokoWeb\Interfaces\Request\IRequest;
|
use SokoWeb\Interfaces\Request\IRequest;
|
||||||
use SokoWeb\Response\Redirect;
|
use SokoWeb\Response\Redirect;
|
||||||
use SokoWeb\Response\HtmlContent;
|
use SokoWeb\Response\HtmlContent;
|
||||||
@ -17,8 +14,6 @@ class HttpResponse
|
|||||||
{
|
{
|
||||||
private IRequest $request;
|
private IRequest $request;
|
||||||
|
|
||||||
private IConnection $dbConnection;
|
|
||||||
|
|
||||||
private RouteCollection $routeCollection;
|
private RouteCollection $routeCollection;
|
||||||
|
|
||||||
private array $appConfig;
|
private array $appConfig;
|
||||||
@ -31,16 +26,12 @@ class HttpResponse
|
|||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
IRequest $request,
|
IRequest $request,
|
||||||
IConnection $dbConnection,
|
|
||||||
RouteCollection $routeCollection,
|
RouteCollection $routeCollection,
|
||||||
array $appConfig,
|
array $appConfig,
|
||||||
string $requestMethod,
|
string $requestMethod,
|
||||||
string $requestUrl
|
string $requestUrl
|
||||||
) {
|
) {
|
||||||
set_error_handler([$this, 'exceptionsErrorHandler']);
|
|
||||||
|
|
||||||
$this->request = $request;
|
$this->request = $request;
|
||||||
$this->dbConnection = $dbConnection;
|
|
||||||
$this->routeCollection = $routeCollection;
|
$this->routeCollection = $routeCollection;
|
||||||
$this->appConfig = $appConfig;
|
$this->appConfig = $appConfig;
|
||||||
$this->method = strtolower($requestMethod);
|
$this->method = strtolower($requestMethod);
|
||||||
@ -48,11 +39,6 @@ class HttpResponse
|
|||||||
$this->rawUrl = $requestUrl;
|
$this->rawUrl = $requestUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function exceptionsErrorHandler($severity, $message, $filename, $lineno)
|
|
||||||
{
|
|
||||||
throw new ErrorException($message, 0, $severity, $filename, $lineno);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function render(): void
|
public function render(): void
|
||||||
{
|
{
|
||||||
$match = $this->routeCollection->match($this->method, $this->parsedUrl['path']);
|
$match = $this->routeCollection->match($this->method, $this->parsedUrl['path']);
|
||||||
@ -89,16 +75,7 @@ class HttpResponse
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->dbConnection->startTransaction();
|
$response = call_user_func([$controller, $handler[1]]);
|
||||||
try {
|
|
||||||
$response = call_user_func([$controller, $handler[1]]);
|
|
||||||
} catch (Exception $exception) {
|
|
||||||
$this->dbConnection->rollback();
|
|
||||||
$this->render500($exception);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$this->dbConnection->commit();
|
|
||||||
|
|
||||||
if ($response instanceof IContent) {
|
if ($response instanceof IContent) {
|
||||||
header('Content-Type: ' . $response->getContentType() . '; charset=UTF-8');
|
header('Content-Type: ' . $response->getContentType() . '; charset=UTF-8');
|
||||||
$response->render();
|
$response->render();
|
||||||
@ -129,17 +106,4 @@ class HttpResponse
|
|||||||
header('Content-Type: text/html; charset=UTF-8', true, 404);
|
header('Content-Type: text/html; charset=UTF-8', true, 404);
|
||||||
$content->render();
|
$content->render();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function render500(Exception $exception): void
|
|
||||||
{
|
|
||||||
if (empty($_ENV['DEV'])) {
|
|
||||||
$exceptionToPrint = null;
|
|
||||||
} else {
|
|
||||||
$exceptionToPrint = (string)$exception;
|
|
||||||
}
|
|
||||||
|
|
||||||
$content = new HtmlContent($this->appConfig['error500View'], ['exceptionToPrint' => $exceptionToPrint]);
|
|
||||||
header('Content-Type: text/html; charset=UTF-8', true, 500);
|
|
||||||
$content->render();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user