mirror of
https://github.com/nuxsmin/sysPass.git
synced 2026-03-12 11:26:55 +01:00
chore: Refactor upgrade subsystem
Use attributes to detect and load upgrade handlers. Signed-off-by: Rubén D <nuxsmin@syspass.org>
This commit is contained in:
@@ -35,6 +35,7 @@ use SP\Domain\Api\Ports\ApiRequestService;
|
||||
use SP\Domain\Api\Services\JsonRpcResponse;
|
||||
use SP\Domain\Core\Bootstrap\BootstrapInterface;
|
||||
use SP\Domain\Core\Bootstrap\ModuleInterface;
|
||||
use SP\Domain\Http\Code;
|
||||
|
||||
use function SP\logger;
|
||||
use function SP\processException;
|
||||
@@ -73,18 +74,17 @@ final class Bootstrap extends BootstrapBase
|
||||
try {
|
||||
logger('API route');
|
||||
|
||||
$apiRequest = $this->createObjectFor(ApiRequestService::class);
|
||||
$response->headers()->set('Content-type', 'application/json; charset=utf-8');
|
||||
|
||||
$apiRequest = $this->buildInstanceFor(ApiRequestService::class);
|
||||
[$controllerName, $actionName] = explode('/', $apiRequest->getMethod());
|
||||
|
||||
$controllerClass = self::getClassFor($controllerName, $actionName);
|
||||
|
||||
$method = $actionName . 'Action';
|
||||
|
||||
if (!method_exists($controllerClass, $method)) {
|
||||
logger($controllerClass . '::' . $method);
|
||||
|
||||
$response->headers()->set('Content-type', 'application/json; charset=utf-8');
|
||||
$response->code(Code::NOT_FOUND->value);
|
||||
|
||||
return $response->body(
|
||||
JsonRpcResponse::getResponseError(
|
||||
@@ -103,11 +103,11 @@ final class Bootstrap extends BootstrapBase
|
||||
|
||||
logger('Routing call: ' . $controllerClass . '::' . $method);
|
||||
|
||||
return call_user_func([$this->createObjectFor($controllerClass), $method]);
|
||||
return call_user_func([$this->buildInstanceFor($controllerClass), $method]);
|
||||
} catch (Exception $e) {
|
||||
processException($e);
|
||||
|
||||
$response->headers()->set('Content-type', 'application/json; charset=utf-8');
|
||||
$response->code(Code::INTERNAL_SERVER_ERROR->value);
|
||||
|
||||
return $response->body(JsonRpcResponse::getResponseException($e, 0));
|
||||
} finally {
|
||||
|
||||
@@ -30,13 +30,13 @@ use Klein\Request;
|
||||
use Klein\Response;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
use RuntimeException;
|
||||
use SP\Core\Bootstrap\BootstrapBase;
|
||||
use SP\Core\Bootstrap\RouteContext;
|
||||
use SP\Domain\Common\Providers\Filter;
|
||||
use SP\Domain\Core\Bootstrap\BootstrapInterface;
|
||||
use SP\Domain\Core\Bootstrap\ModuleInterface;
|
||||
use SP\Domain\Core\Exceptions\SessionTimeout;
|
||||
use SP\Domain\Http\Code;
|
||||
|
||||
use function SP\__;
|
||||
use function SP\logger;
|
||||
@@ -87,9 +87,10 @@ final class Bootstrap extends BootstrapBase
|
||||
if (!method_exists($controllerClass, $routeContextData->getMethodName())) {
|
||||
logger($controllerClass . '::' . $routeContextData->getMethodName());
|
||||
|
||||
$response->code(404);
|
||||
$response->code(Code::NOT_FOUND->value);
|
||||
$response->append(self::OOPS_MESSAGE);
|
||||
|
||||
throw new RuntimeException(self::OOPS_MESSAGE);
|
||||
return $response;
|
||||
}
|
||||
|
||||
$this->context->setTrasientKey(self::CONTEXT_ACTION_NAME, $routeContextData->getActionName());
|
||||
@@ -109,10 +110,8 @@ final class Bootstrap extends BootstrapBase
|
||||
)
|
||||
);
|
||||
|
||||
$controller = $this->createObjectFor($controllerClass);
|
||||
|
||||
return call_user_func_array(
|
||||
[$controller, $routeContextData->getMethodName()],
|
||||
[$this->buildInstanceFor($controllerClass), $routeContextData->getMethodName()],
|
||||
$routeContextData->getMethodParams()
|
||||
);
|
||||
} catch (SessionTimeout) {
|
||||
@@ -125,7 +124,12 @@ final class Bootstrap extends BootstrapBase
|
||||
if (DEBUG) {
|
||||
echo $e->getTraceAsString();
|
||||
}
|
||||
|
||||
$response->code(Code::INTERNAL_SERVER_ERROR->value);
|
||||
$response->append($e->getMessage());
|
||||
}
|
||||
|
||||
return $response;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user