From a13fb94628f74290de063fe4461f48eba9ce4148 Mon Sep 17 00:00:00 2001 From: Flo Date: Sat, 24 Aug 2024 20:28:40 +0000 Subject: [PATCH] intermediate commit --- config/pipeline.php | 4 ++-- .../src/Handler/RegisterUserHandler.php | 16 ++++++---------- .../RegistrationNotFoundByIdException.php | 4 ++-- ...ationWithIdentifierAlreadyExistsException.php | 4 ++-- .../ConfirmRegistration/Step/CreateUserStep.php | 2 +- .../RegisterUser/Step/CheckIdentifierStep.php | 4 ++-- .../RoleNotFoundByIdentifierException.php | 4 ++-- .../UserNotFoundByIdentifierException.php | 4 ++-- .../Exception/UserPasswordMismatchException.php | 4 ++-- ...UserWithIdentifierAlreadyExistsException.php} | 4 ++-- .../src/Exception/UserWrongPasswordException.php | 4 ++-- .../User/src/Rule/UserPasswordMatchRule.php | 2 +- .../Rule/UserWithIdentifierAlreadyExistsRule.php | 4 ++-- .../Exception/config/service_manager.php | 4 ++-- .../{TemplateException.php => Exception.php} | 3 +-- ...leware.php => ExceptionHandlerMiddleware.php} | 6 +++--- src/Infrastructure/Logging/src/Logger/Logger.php | 6 ++---- 17 files changed, 36 insertions(+), 43 deletions(-) rename src/HandlingDomain/User/src/Exception/{UserWithIdentifierAlreadyExists.php => UserWithIdentifierAlreadyExistsException.php} (76%) rename src/Infrastructure/Exception/src/Exception/{TemplateException.php => Exception.php} (93%) rename src/Infrastructure/Exception/src/Middleware/{TemplateExceptionHandlerMiddleware.php => ExceptionHandlerMiddleware.php} (82%) diff --git a/config/pipeline.php b/config/pipeline.php index aeaaeb4..4d19afa 100644 --- a/config/pipeline.php +++ b/config/pipeline.php @@ -2,7 +2,7 @@ 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\AnalyzeHeaderMiddleware; use Template\Infrastructure\Session\Middleware\SessionMiddleware; @@ -68,7 +68,7 @@ return function (Application $app, MiddlewareFactory $factory, ContainerInterfac //// Pre Template Space - $app->pipe(TemplateExceptionHandlerMiddleware::class); + $app->pipe(ExceptionHandlerMiddleware::class); $app->pipe(AnalyzeHeaderMiddleware::class); $app->pipe(AnalyzeBodyMiddleware::class); diff --git a/src/ApiDomain/External/Authentication/src/Handler/RegisterUserHandler.php b/src/ApiDomain/External/Authentication/src/Handler/RegisterUserHandler.php index be1aee4..7a330c2 100644 --- a/src/ApiDomain/External/Authentication/src/Handler/RegisterUserHandler.php +++ b/src/ApiDomain/External/Authentication/src/Handler/RegisterUserHandler.php @@ -4,24 +4,20 @@ declare(strict_types=1); 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\ServerRequestInterface; 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 { public function __construct( private readonly RegisterUserCommandHandler $handler, - private readonly RegisterUserCommandBuilder $builder, - private readonly Logger $logger + private readonly RegisterUserCommandBuilder $builder ) { } diff --git a/src/HandlingDomain/Registration/src/Exception/RegistrationNotFoundByIdException.php b/src/HandlingDomain/Registration/src/Exception/RegistrationNotFoundByIdException.php index cff982b..e1f9ba7 100644 --- a/src/HandlingDomain/Registration/src/Exception/RegistrationNotFoundByIdException.php +++ b/src/HandlingDomain/Registration/src/Exception/RegistrationNotFoundByIdException.php @@ -4,10 +4,10 @@ namespace Template\Handling\Registration\Exception; use Template\Infrastructure\Exception\ErrorCode; use Template\Infrastructure\Exception\ErrorDomain; -use Template\Infrastructure\Exception\Exception\TemplateException; +use Template\Infrastructure\Exception\Exception\Exception; 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!'; public function __construct( diff --git a/src/HandlingDomain/Registration/src/Exception/RegistrationWithIdentifierAlreadyExistsException.php b/src/HandlingDomain/Registration/src/Exception/RegistrationWithIdentifierAlreadyExistsException.php index e66bea3..c86afc5 100644 --- a/src/HandlingDomain/Registration/src/Exception/RegistrationWithIdentifierAlreadyExistsException.php +++ b/src/HandlingDomain/Registration/src/Exception/RegistrationWithIdentifierAlreadyExistsException.php @@ -4,9 +4,9 @@ namespace Template\Handling\Registration\Exception; use Template\Infrastructure\Exception\ErrorCode; 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!'; diff --git a/src/HandlingDomain/Registration/src/Pipeline/ConfirmRegistration/Step/CreateUserStep.php b/src/HandlingDomain/Registration/src/Pipeline/ConfirmRegistration/Step/CreateUserStep.php index 23c033a..00f9ad4 100644 --- a/src/HandlingDomain/Registration/src/Pipeline/ConfirmRegistration/Step/CreateUserStep.php +++ b/src/HandlingDomain/Registration/src/Pipeline/ConfirmRegistration/Step/CreateUserStep.php @@ -8,7 +8,7 @@ use Template\Handling\Registration\Exception\RegistrationWithIdentifierAlreadyEx use Template\Handling\Registration\Handler\Command\ConfirmRegistration\ConfirmRegistrationCommand; use Template\Handling\Registration\Rule\RegistrationWithIdentifierAlreadyExistsRule; 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\CreateUserCommandHandler; use Template\Handling\User\Rule\UserPasswordMatchRule; diff --git a/src/HandlingDomain/Registration/src/Pipeline/RegisterUser/Step/CheckIdentifierStep.php b/src/HandlingDomain/Registration/src/Pipeline/RegisterUser/Step/CheckIdentifierStep.php index 69deef4..cab145f 100644 --- a/src/HandlingDomain/Registration/src/Pipeline/RegisterUser/Step/CheckIdentifierStep.php +++ b/src/HandlingDomain/Registration/src/Pipeline/RegisterUser/Step/CheckIdentifierStep.php @@ -6,7 +6,7 @@ namespace Template\Handling\Registration\Pipeline\RegisterUser\Step; use Template\Handling\Registration\Exception\RegistrationWithIdentifierAlreadyExistsException; 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 teewurst\Pipeline\PipelineInterface; use teewurst\Pipeline\TaskInterface; @@ -21,7 +21,7 @@ class CheckIdentifierStep implements TaskInterface /** * @throws RegistrationWithIdentifierAlreadyExistsException - * @throws UserWithIdentifierAlreadyExists + * @throws UserWithIdentifierAlreadyExistsException */ public function __invoke( $payload, diff --git a/src/HandlingDomain/Role/src/Exception/RoleNotFoundByIdentifierException.php b/src/HandlingDomain/Role/src/Exception/RoleNotFoundByIdentifierException.php index 6f1b635..c4675c5 100644 --- a/src/HandlingDomain/Role/src/Exception/RoleNotFoundByIdentifierException.php +++ b/src/HandlingDomain/Role/src/Exception/RoleNotFoundByIdentifierException.php @@ -4,9 +4,9 @@ namespace Template\Handling\Role\Exception; use Template\Infrastructure\Exception\ErrorCode; 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!'; diff --git a/src/HandlingDomain/User/src/Exception/UserNotFoundByIdentifierException.php b/src/HandlingDomain/User/src/Exception/UserNotFoundByIdentifierException.php index ffb945a..09e56f0 100644 --- a/src/HandlingDomain/User/src/Exception/UserNotFoundByIdentifierException.php +++ b/src/HandlingDomain/User/src/Exception/UserNotFoundByIdentifierException.php @@ -4,9 +4,9 @@ namespace Template\Handling\User\Exception; use Template\Infrastructure\Exception\ErrorCode; 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!'; diff --git a/src/HandlingDomain/User/src/Exception/UserPasswordMismatchException.php b/src/HandlingDomain/User/src/Exception/UserPasswordMismatchException.php index 572936a..844e2c7 100644 --- a/src/HandlingDomain/User/src/Exception/UserPasswordMismatchException.php +++ b/src/HandlingDomain/User/src/Exception/UserPasswordMismatchException.php @@ -4,9 +4,9 @@ namespace Template\Handling\User\Exception; use Template\Infrastructure\Exception\ErrorCode; 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!'; diff --git a/src/HandlingDomain/User/src/Exception/UserWithIdentifierAlreadyExists.php b/src/HandlingDomain/User/src/Exception/UserWithIdentifierAlreadyExistsException.php similarity index 76% rename from src/HandlingDomain/User/src/Exception/UserWithIdentifierAlreadyExists.php rename to src/HandlingDomain/User/src/Exception/UserWithIdentifierAlreadyExistsException.php index f734c38..28d4767 100644 --- a/src/HandlingDomain/User/src/Exception/UserWithIdentifierAlreadyExists.php +++ b/src/HandlingDomain/User/src/Exception/UserWithIdentifierAlreadyExistsException.php @@ -4,9 +4,9 @@ namespace Template\Handling\User\Exception; use Template\Infrastructure\Exception\ErrorCode; 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!'; diff --git a/src/HandlingDomain/User/src/Exception/UserWrongPasswordException.php b/src/HandlingDomain/User/src/Exception/UserWrongPasswordException.php index 1109357..3cbe5be 100644 --- a/src/HandlingDomain/User/src/Exception/UserWrongPasswordException.php +++ b/src/HandlingDomain/User/src/Exception/UserWrongPasswordException.php @@ -4,9 +4,9 @@ namespace Template\Handling\User\Exception; use Template\Infrastructure\Exception\ErrorCode; 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!'; diff --git a/src/HandlingDomain/User/src/Rule/UserPasswordMatchRule.php b/src/HandlingDomain/User/src/Rule/UserPasswordMatchRule.php index 6b340ff..e49dcca 100644 --- a/src/HandlingDomain/User/src/Rule/UserPasswordMatchRule.php +++ b/src/HandlingDomain/User/src/Rule/UserPasswordMatchRule.php @@ -4,7 +4,7 @@ namespace Template\Handling\User\Rule; use Template\Data\Business\Repository\UserRepository; use Template\Handling\User\Exception\UserPasswordMismatchException; -use Template\Handling\User\Exception\UserWithIdentifierAlreadyExists; +use Template\Handling\User\Exception\UserWithIdentifierAlreadyExistsException; use Reinfi\DependencyInjection\Annotation\InjectDoctrineRepository; class UserPasswordMatchRule diff --git a/src/HandlingDomain/User/src/Rule/UserWithIdentifierAlreadyExistsRule.php b/src/HandlingDomain/User/src/Rule/UserWithIdentifierAlreadyExistsRule.php index 70b186a..3333725 100644 --- a/src/HandlingDomain/User/src/Rule/UserWithIdentifierAlreadyExistsRule.php +++ b/src/HandlingDomain/User/src/Rule/UserWithIdentifierAlreadyExistsRule.php @@ -3,7 +3,7 @@ namespace Template\Handling\User\Rule; use Template\Data\Business\Repository\UserRepository; -use Template\Handling\User\Exception\UserWithIdentifierAlreadyExists; +use Template\Handling\User\Exception\UserWithIdentifierAlreadyExistsException; use Reinfi\DependencyInjection\Annotation\InjectDoctrineRepository; class UserWithIdentifierAlreadyExistsRule @@ -23,7 +23,7 @@ class UserWithIdentifierAlreadyExistsRule $user = $this->userRepository->findByIdentifier($identifier); if ($user !== null) { - throw new UserWithIdentifierAlreadyExists($identifier); + throw new UserWithIdentifierAlreadyExistsException($identifier); } } } \ No newline at end of file diff --git a/src/Infrastructure/Exception/config/service_manager.php b/src/Infrastructure/Exception/config/service_manager.php index 99fb496..060c7c0 100644 --- a/src/Infrastructure/Exception/config/service_manager.php +++ b/src/Infrastructure/Exception/config/service_manager.php @@ -2,11 +2,11 @@ declare(strict_types=1); -use Template\Infrastructure\Exception\Middleware\TemplateExceptionHandlerMiddleware; +use Template\Infrastructure\Exception\Middleware\ExceptionHandlerMiddleware; use Reinfi\DependencyInjection\Factory\AutoWiringFactory; return [ 'factories' => [ - TemplateExceptionHandlerMiddleware::class => AutoWiringFactory::class, + ExceptionHandlerMiddleware::class => AutoWiringFactory::class, ], ]; diff --git a/src/Infrastructure/Exception/src/Exception/TemplateException.php b/src/Infrastructure/Exception/src/Exception/Exception.php similarity index 93% rename from src/Infrastructure/Exception/src/Exception/TemplateException.php rename to src/Infrastructure/Exception/src/Exception/Exception.php index 30c44a1..ff11d6a 100644 --- a/src/Infrastructure/Exception/src/Exception/TemplateException.php +++ b/src/Infrastructure/Exception/src/Exception/Exception.php @@ -2,11 +2,10 @@ namespace Template\Infrastructure\Exception\Exception; -use Exception; use Template\Infrastructure\Exception\ErrorCode; use Template\Infrastructure\Exception\ErrorDomain; -class TemplateException extends Exception { +class Exception extends \Exception { private readonly ErrorDomain $errorDomain; private readonly ErrorCode $errorCode; diff --git a/src/Infrastructure/Exception/src/Middleware/TemplateExceptionHandlerMiddleware.php b/src/Infrastructure/Exception/src/Middleware/ExceptionHandlerMiddleware.php similarity index 82% rename from src/Infrastructure/Exception/src/Middleware/TemplateExceptionHandlerMiddleware.php rename to src/Infrastructure/Exception/src/Middleware/ExceptionHandlerMiddleware.php index 3a709a6..a3c715f 100644 --- a/src/Infrastructure/Exception/src/Middleware/TemplateExceptionHandlerMiddleware.php +++ b/src/Infrastructure/Exception/src/Middleware/ExceptionHandlerMiddleware.php @@ -2,7 +2,7 @@ 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\Response\ErrorResponse; use Psr\Http\Message\ResponseInterface; @@ -10,7 +10,7 @@ use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\MiddlewareInterface; use Psr\Http\Server\RequestHandlerInterface; -class TemplateExceptionHandlerMiddleware implements MiddlewareInterface +class ExceptionHandlerMiddleware implements MiddlewareInterface { public function __construct( private readonly Logger $logger @@ -24,7 +24,7 @@ class TemplateExceptionHandlerMiddleware implements MiddlewareInterface { try { return $handler->handle($request); - } catch (TemplateException $exception) { + } catch (Exception $exception) { $this->logger->exception($exception); return new ErrorResponse( diff --git a/src/Infrastructure/Logging/src/Logger/Logger.php b/src/Infrastructure/Logging/src/Logger/Logger.php index ac4e55a..a34c867 100644 --- a/src/Infrastructure/Logging/src/Logger/Logger.php +++ b/src/Infrastructure/Logging/src/Logger/Logger.php @@ -2,10 +2,8 @@ namespace Template\Infrastructure\Logging\Logger; -use Template\Infrastructure\Exception\Exception\TemplateException; -use Template\Infrastructure\Logging\Handler\FileStreamHandler; +use Template\Infrastructure\Exception\Exception\Exception; use Monolog\ErrorHandler; -use Monolog\Handler\StreamHandler; use Psr\Log\LoggerInterface; use Stringable; use Throwable; @@ -26,7 +24,7 @@ class Logger implements LoggerInterface 'trace' => $exception->getTraceAsString() ]*/; - if ($exception instanceof TemplateException) { + if ($exception instanceof Exception) { $exceptionContext = array_merge([ 'errorDomain' => $exception->getErrorDomain()->value, 'errorCode' => $exception->getErrorCode()->value,