intermediate commit

This commit is contained in:
Flo 2024-08-24 20:28:40 +00:00
parent edf1817bac
commit a13fb94628
17 changed files with 36 additions and 43 deletions

View File

@ -2,7 +2,7 @@
declare(strict_types=1); declare(strict_types=1);
use Template\Infrastructure\Exception\Middleware\TemplateExceptionHandlerMiddleware; use Template\Infrastructure\Exception\Middleware\ExceptionHandlerMiddleware;
use Template\Infrastructure\Request\Middleware\AnalyzeBodyMiddleware; use Template\Infrastructure\Request\Middleware\AnalyzeBodyMiddleware;
use Template\Infrastructure\Request\Middleware\AnalyzeHeaderMiddleware; use Template\Infrastructure\Request\Middleware\AnalyzeHeaderMiddleware;
use Template\Infrastructure\Session\Middleware\SessionMiddleware; use Template\Infrastructure\Session\Middleware\SessionMiddleware;
@ -68,7 +68,7 @@ return function (Application $app, MiddlewareFactory $factory, ContainerInterfac
//// Pre Template Space //// Pre Template Space
$app->pipe(TemplateExceptionHandlerMiddleware::class); $app->pipe(ExceptionHandlerMiddleware::class);
$app->pipe(AnalyzeHeaderMiddleware::class); $app->pipe(AnalyzeHeaderMiddleware::class);
$app->pipe(AnalyzeBodyMiddleware::class); $app->pipe(AnalyzeBodyMiddleware::class);

View File

@ -4,24 +4,20 @@ declare(strict_types=1);
namespace Template\API\External\Authentication\Handler; namespace Template\API\External\Authentication\Handler;
use Template\Handling\Registration\Handler\Command\RegisterUser\RegisterUserCommandBuilder;
use Template\Handling\Registration\Handler\Command\RegisterUser\RegisterUserCommandHandler;
use Template\Infrastructure\Exception\Middleware\TemplateExceptionHandlerMiddleware;
use Template\Infrastructure\Logging\Logger\Logger;
use Template\Infrastructure\Request\Middleware\AnalyzeHeaderMiddleware;
use Template\Infrastructure\Response\SuccessResponse;
use Template\Infrastructure\Session\Middleware\SessionMiddleware;
use Laminas\Diactoros\Response\JsonResponse;
use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface; use Psr\Http\Server\RequestHandlerInterface;
use Template\Handling\Registration\Handler\Command\RegisterUser\RegisterUserCommandBuilder;
use Template\Handling\Registration\Handler\Command\RegisterUser\RegisterUserCommandHandler;
use Template\Infrastructure\Logging\Logger\Logger;
use Template\Infrastructure\Request\Middleware\AnalyzeHeaderMiddleware;
use Template\Infrastructure\Response\SuccessResponse;
class RegisterUserHandler implements RequestHandlerInterface class RegisterUserHandler implements RequestHandlerInterface
{ {
public function __construct( public function __construct(
private readonly RegisterUserCommandHandler $handler, private readonly RegisterUserCommandHandler $handler,
private readonly RegisterUserCommandBuilder $builder, private readonly RegisterUserCommandBuilder $builder
private readonly Logger $logger
) { ) {
} }

View File

@ -4,10 +4,10 @@ namespace Template\Handling\Registration\Exception;
use Template\Infrastructure\Exception\ErrorCode; use Template\Infrastructure\Exception\ErrorCode;
use Template\Infrastructure\Exception\ErrorDomain; use Template\Infrastructure\Exception\ErrorDomain;
use Template\Infrastructure\Exception\Exception\TemplateException; use Template\Infrastructure\Exception\Exception\Exception;
use Ramsey\Uuid\UuidInterface; use Ramsey\Uuid\UuidInterface;
class RegistrationNotFoundByIdException extends TemplateException class RegistrationNotFoundByIdException extends Exception
{ {
private const MESSAGE = 'A Registration with the id %s was not be found!'; private const MESSAGE = 'A Registration with the id %s was not be found!';
public function __construct( public function __construct(

View File

@ -4,9 +4,9 @@ namespace Template\Handling\Registration\Exception;
use Template\Infrastructure\Exception\ErrorCode; use Template\Infrastructure\Exception\ErrorCode;
use Template\Infrastructure\Exception\ErrorDomain; use Template\Infrastructure\Exception\ErrorDomain;
use Template\Infrastructure\Exception\Exception\TemplateException; use Template\Infrastructure\Exception\Exception\Exception;
class RegistrationWithIdentifierAlreadyExistsException extends TemplateException class RegistrationWithIdentifierAlreadyExistsException extends Exception
{ {
private const MESSAGE = 'A Registration with the identifier %s does already exist!'; private const MESSAGE = 'A Registration with the identifier %s does already exist!';

View File

@ -8,7 +8,7 @@ use Template\Handling\Registration\Exception\RegistrationWithIdentifierAlreadyEx
use Template\Handling\Registration\Handler\Command\ConfirmRegistration\ConfirmRegistrationCommand; use Template\Handling\Registration\Handler\Command\ConfirmRegistration\ConfirmRegistrationCommand;
use Template\Handling\Registration\Rule\RegistrationWithIdentifierAlreadyExistsRule; use Template\Handling\Registration\Rule\RegistrationWithIdentifierAlreadyExistsRule;
use Template\Handling\User\Exception\UserPasswordMismatchException; use Template\Handling\User\Exception\UserPasswordMismatchException;
use Template\Handling\User\Exception\UserWithIdentifierAlreadyExists; use Template\Handling\User\Exception\UserWithIdentifierAlreadyExistsException;
use Template\Handling\User\Handler\Command\CreateUser\CreateUserCommandBuilder; use Template\Handling\User\Handler\Command\CreateUser\CreateUserCommandBuilder;
use Template\Handling\User\Handler\Command\CreateUser\CreateUserCommandHandler; use Template\Handling\User\Handler\Command\CreateUser\CreateUserCommandHandler;
use Template\Handling\User\Rule\UserPasswordMatchRule; use Template\Handling\User\Rule\UserPasswordMatchRule;

View File

@ -6,7 +6,7 @@ namespace Template\Handling\Registration\Pipeline\RegisterUser\Step;
use Template\Handling\Registration\Exception\RegistrationWithIdentifierAlreadyExistsException; use Template\Handling\Registration\Exception\RegistrationWithIdentifierAlreadyExistsException;
use Template\Handling\Registration\Rule\RegistrationWithIdentifierAlreadyExistsRule; use Template\Handling\Registration\Rule\RegistrationWithIdentifierAlreadyExistsRule;
use Template\Handling\User\Exception\UserWithIdentifierAlreadyExists; use Template\Handling\User\Exception\UserWithIdentifierAlreadyExistsException;
use Template\Handling\User\Rule\UserWithIdentifierAlreadyExistsRule; use Template\Handling\User\Rule\UserWithIdentifierAlreadyExistsRule;
use teewurst\Pipeline\PipelineInterface; use teewurst\Pipeline\PipelineInterface;
use teewurst\Pipeline\TaskInterface; use teewurst\Pipeline\TaskInterface;
@ -21,7 +21,7 @@ class CheckIdentifierStep implements TaskInterface
/** /**
* @throws RegistrationWithIdentifierAlreadyExistsException * @throws RegistrationWithIdentifierAlreadyExistsException
* @throws UserWithIdentifierAlreadyExists * @throws UserWithIdentifierAlreadyExistsException
*/ */
public function __invoke( public function __invoke(
$payload, $payload,

View File

@ -4,9 +4,9 @@ namespace Template\Handling\Role\Exception;
use Template\Infrastructure\Exception\ErrorCode; use Template\Infrastructure\Exception\ErrorCode;
use Template\Infrastructure\Exception\ErrorDomain; use Template\Infrastructure\Exception\ErrorDomain;
use Template\Infrastructure\Exception\Exception\TemplateException; use Template\Infrastructure\Exception\Exception\Exception;
class RoleNotFoundByIdentifierException extends TemplateException { class RoleNotFoundByIdentifierException extends Exception {
private const MESSAGE = 'The role with the Identifier %s was not found!'; private const MESSAGE = 'The role with the Identifier %s was not found!';

View File

@ -4,9 +4,9 @@ namespace Template\Handling\User\Exception;
use Template\Infrastructure\Exception\ErrorCode; use Template\Infrastructure\Exception\ErrorCode;
use Template\Infrastructure\Exception\ErrorDomain; use Template\Infrastructure\Exception\ErrorDomain;
use Template\Infrastructure\Exception\Exception\TemplateException; use Template\Infrastructure\Exception\Exception\Exception;
class UserNotFoundByIdentifierException extends TemplateException { class UserNotFoundByIdentifierException extends Exception {
private const MESSAGE = 'The user with the Identifier %s was not found!'; private const MESSAGE = 'The user with the Identifier %s was not found!';

View File

@ -4,9 +4,9 @@ namespace Template\Handling\User\Exception;
use Template\Infrastructure\Exception\ErrorCode; use Template\Infrastructure\Exception\ErrorCode;
use Template\Infrastructure\Exception\ErrorDomain; use Template\Infrastructure\Exception\ErrorDomain;
use Template\Infrastructure\Exception\Exception\TemplateException; use Template\Infrastructure\Exception\Exception\Exception;
class UserPasswordMismatchException extends TemplateException { class UserPasswordMismatchException extends Exception {
private const MESSAGE = 'The two passwords do not match!'; private const MESSAGE = 'The two passwords do not match!';

View File

@ -4,9 +4,9 @@ namespace Template\Handling\User\Exception;
use Template\Infrastructure\Exception\ErrorCode; use Template\Infrastructure\Exception\ErrorCode;
use Template\Infrastructure\Exception\ErrorDomain; use Template\Infrastructure\Exception\ErrorDomain;
use Template\Infrastructure\Exception\Exception\TemplateException; use Template\Infrastructure\Exception\Exception\Exception;
class UserWithIdentifierAlreadyExists extends TemplateException { class UserWithIdentifierAlreadyExistsException extends Exception {
private const MESSAGE = 'A User with the identifier %s does already exist!'; private const MESSAGE = 'A User with the identifier %s does already exist!';

View File

@ -4,9 +4,9 @@ namespace Template\Handling\User\Exception;
use Template\Infrastructure\Exception\ErrorCode; use Template\Infrastructure\Exception\ErrorCode;
use Template\Infrastructure\Exception\ErrorDomain; use Template\Infrastructure\Exception\ErrorDomain;
use Template\Infrastructure\Exception\Exception\TemplateException; use Template\Infrastructure\Exception\Exception\Exception;
class UserWrongPasswordException extends TemplateException { class UserWrongPasswordException extends Exception {
private const MESSAGE = 'The given password is incorrect!'; private const MESSAGE = 'The given password is incorrect!';

View File

@ -4,7 +4,7 @@ namespace Template\Handling\User\Rule;
use Template\Data\Business\Repository\UserRepository; use Template\Data\Business\Repository\UserRepository;
use Template\Handling\User\Exception\UserPasswordMismatchException; use Template\Handling\User\Exception\UserPasswordMismatchException;
use Template\Handling\User\Exception\UserWithIdentifierAlreadyExists; use Template\Handling\User\Exception\UserWithIdentifierAlreadyExistsException;
use Reinfi\DependencyInjection\Annotation\InjectDoctrineRepository; use Reinfi\DependencyInjection\Annotation\InjectDoctrineRepository;
class UserPasswordMatchRule class UserPasswordMatchRule

View File

@ -3,7 +3,7 @@
namespace Template\Handling\User\Rule; namespace Template\Handling\User\Rule;
use Template\Data\Business\Repository\UserRepository; use Template\Data\Business\Repository\UserRepository;
use Template\Handling\User\Exception\UserWithIdentifierAlreadyExists; use Template\Handling\User\Exception\UserWithIdentifierAlreadyExistsException;
use Reinfi\DependencyInjection\Annotation\InjectDoctrineRepository; use Reinfi\DependencyInjection\Annotation\InjectDoctrineRepository;
class UserWithIdentifierAlreadyExistsRule class UserWithIdentifierAlreadyExistsRule
@ -23,7 +23,7 @@ class UserWithIdentifierAlreadyExistsRule
$user = $this->userRepository->findByIdentifier($identifier); $user = $this->userRepository->findByIdentifier($identifier);
if ($user !== null) { if ($user !== null) {
throw new UserWithIdentifierAlreadyExists($identifier); throw new UserWithIdentifierAlreadyExistsException($identifier);
} }
} }
} }

View File

@ -2,11 +2,11 @@
declare(strict_types=1); declare(strict_types=1);
use Template\Infrastructure\Exception\Middleware\TemplateExceptionHandlerMiddleware; use Template\Infrastructure\Exception\Middleware\ExceptionHandlerMiddleware;
use Reinfi\DependencyInjection\Factory\AutoWiringFactory; use Reinfi\DependencyInjection\Factory\AutoWiringFactory;
return [ return [
'factories' => [ 'factories' => [
TemplateExceptionHandlerMiddleware::class => AutoWiringFactory::class, ExceptionHandlerMiddleware::class => AutoWiringFactory::class,
], ],
]; ];

View File

@ -2,11 +2,10 @@
namespace Template\Infrastructure\Exception\Exception; namespace Template\Infrastructure\Exception\Exception;
use Exception;
use Template\Infrastructure\Exception\ErrorCode; use Template\Infrastructure\Exception\ErrorCode;
use Template\Infrastructure\Exception\ErrorDomain; use Template\Infrastructure\Exception\ErrorDomain;
class TemplateException extends Exception { class Exception extends \Exception {
private readonly ErrorDomain $errorDomain; private readonly ErrorDomain $errorDomain;
private readonly ErrorCode $errorCode; private readonly ErrorCode $errorCode;

View File

@ -2,7 +2,7 @@
namespace Template\Infrastructure\Exception\Middleware; namespace Template\Infrastructure\Exception\Middleware;
use Template\Infrastructure\Exception\Exception\TemplateException; use Template\Infrastructure\Exception\Exception\Exception;
use Template\Infrastructure\Logging\Logger\Logger; use Template\Infrastructure\Logging\Logger\Logger;
use Template\Infrastructure\Response\ErrorResponse; use Template\Infrastructure\Response\ErrorResponse;
use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ResponseInterface;
@ -10,7 +10,7 @@ use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface; use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface; use Psr\Http\Server\RequestHandlerInterface;
class TemplateExceptionHandlerMiddleware implements MiddlewareInterface class ExceptionHandlerMiddleware implements MiddlewareInterface
{ {
public function __construct( public function __construct(
private readonly Logger $logger private readonly Logger $logger
@ -24,7 +24,7 @@ class TemplateExceptionHandlerMiddleware implements MiddlewareInterface
{ {
try { try {
return $handler->handle($request); return $handler->handle($request);
} catch (TemplateException $exception) { } catch (Exception $exception) {
$this->logger->exception($exception); $this->logger->exception($exception);
return new ErrorResponse( return new ErrorResponse(

View File

@ -2,10 +2,8 @@
namespace Template\Infrastructure\Logging\Logger; namespace Template\Infrastructure\Logging\Logger;
use Template\Infrastructure\Exception\Exception\TemplateException; use Template\Infrastructure\Exception\Exception\Exception;
use Template\Infrastructure\Logging\Handler\FileStreamHandler;
use Monolog\ErrorHandler; use Monolog\ErrorHandler;
use Monolog\Handler\StreamHandler;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use Stringable; use Stringable;
use Throwable; use Throwable;
@ -26,7 +24,7 @@ class Logger implements LoggerInterface
'trace' => $exception->getTraceAsString() 'trace' => $exception->getTraceAsString()
]*/; ]*/;
if ($exception instanceof TemplateException) { if ($exception instanceof Exception) {
$exceptionContext = array_merge([ $exceptionContext = array_merge([
'errorDomain' => $exception->getErrorDomain()->value, 'errorDomain' => $exception->getErrorDomain()->value,
'errorCode' => $exception->getErrorCode()->value, 'errorCode' => $exception->getErrorCode()->value,