From ff1740f9706bcbc6edeefb1e57e4f180f718deeb Mon Sep 17 00:00:00 2001 From: alexmerlin Date: Thu, 30 May 2024 17:22:22 +0300 Subject: [PATCH] ResponseTrait -> HandlerTrait and ResponseTrait Signed-off-by: alexmerlin --- phpunit.xml | 1 + psalm-baseline.xml | 6 + src/Admin/src/Entity/Admin.php | 8 +- src/Admin/src/Entity/AdminRole.php | 2 +- src/Admin/src/Handler/AdminAccountHandler.php | 6 +- src/Admin/src/Handler/AdminHandler.php | 8 +- src/Admin/src/Handler/AdminRoleHandler.php | 4 +- src/App/src/Handler/ErrorReportHandler.php | 2 +- src/App/src/Handler/HandlerTrait.php | 104 ++++++++++++++++++ src/App/src/Handler/HomeHandler.php | 5 +- src/App/src/Handler/NotFoundHandler.php | 2 +- src/App/src/Handler/ResponseTrait.php | 103 ++--------------- .../ContentNegotiationMiddleware.php | 43 ++------ .../src/Handler/AccountActivateHandler.php | 9 +- src/User/src/Handler/AccountAvatarHandler.php | 4 +- src/User/src/Handler/AccountHandler.php | 8 +- .../src/Handler/AccountRecoveryHandler.php | 6 +- .../Handler/AccountResetPasswordHandler.php | 8 +- src/User/src/Handler/UserActivateHandler.php | 4 +- src/User/src/Handler/UserAvatarHandler.php | 4 +- src/User/src/Handler/UserHandler.php | 8 +- src/User/src/Handler/UserRoleHandler.php | 4 +- 22 files changed, 169 insertions(+), 180 deletions(-) create mode 100644 src/App/src/Handler/HandlerTrait.php diff --git a/phpunit.xml b/phpunit.xml index b875241..4921775 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -2,6 +2,7 @@ diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 9f636fd..e12f145 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -27,4 +27,10 @@ matching + + + $this->responseFactory + $this->resourceGenerator + + diff --git a/src/Admin/src/Entity/Admin.php b/src/Admin/src/Entity/Admin.php index ed338b9..590c63d 100644 --- a/src/Admin/src/Entity/Admin.php +++ b/src/Admin/src/Entity/Admin.php @@ -28,16 +28,16 @@ class Admin extends AbstractEntity implements UserEntityInterface ]; #[ORM\Column(name: "identity", type: "string", length: 100, unique: true)] - protected string $identity; + protected string $identity = ''; #[ORM\Column(name: "firstName", type: "string", length: 255)] - protected string $firstName; + protected string $firstName = ''; #[ORM\Column(name: "lastName", type: "string", length: 255)] - protected string $lastName; + protected string $lastName = ''; #[ORM\Column(name: "password", type: "string", length: 100)] - protected string $password; + protected string $password = ''; #[ORM\Column(name: "status", type: "string", length: 20)] protected string $status = self::STATUS_ACTIVE; diff --git a/src/Admin/src/Entity/AdminRole.php b/src/Admin/src/Entity/AdminRole.php index 0cc4914..614d51d 100644 --- a/src/Admin/src/Entity/AdminRole.php +++ b/src/Admin/src/Entity/AdminRole.php @@ -22,7 +22,7 @@ class AdminRole extends AbstractEntity implements RoleInterface ]; #[ORM\Column(name: "name", type: "string", length: 30, unique: true)] - protected string $name; + protected string $name = ''; public function getName(): string { diff --git a/src/Admin/src/Handler/AdminAccountHandler.php b/src/Admin/src/Handler/AdminAccountHandler.php index ac081c0..e950fed 100644 --- a/src/Admin/src/Handler/AdminAccountHandler.php +++ b/src/Admin/src/Handler/AdminAccountHandler.php @@ -10,7 +10,7 @@ use Api\App\Exception\BadRequestException; use Api\App\Exception\ConflictException; use Api\App\Exception\NotFoundException; -use Api\App\Handler\ResponseTrait; +use Api\App\Handler\HandlerTrait; use Dot\AnnotatedServices\Annotation\Inject; use Mezzio\Hal\HalResponseFactory; use Mezzio\Hal\ResourceGenerator; @@ -20,7 +20,7 @@ class AdminAccountHandler implements RequestHandlerInterface { - use ResponseTrait; + use HandlerTrait; /** * @Inject({ @@ -50,7 +50,7 @@ public function get(ServerRequestInterface $request): ResponseInterface */ public function patch(ServerRequestInterface $request): ResponseInterface { - $inputFilter = (new UpdateAdminInputFilter())->setData($request->getParsedBody()); + $inputFilter = (new UpdateAdminInputFilter())->setData((array) $request->getParsedBody()); if (! $inputFilter->isValid()) { throw (new BadRequestException())->setMessages($inputFilter->getMessages()); } diff --git a/src/Admin/src/Handler/AdminHandler.php b/src/Admin/src/Handler/AdminHandler.php index b9315f2..07be306 100644 --- a/src/Admin/src/Handler/AdminHandler.php +++ b/src/Admin/src/Handler/AdminHandler.php @@ -11,7 +11,7 @@ use Api\App\Exception\BadRequestException; use Api\App\Exception\ConflictException; use Api\App\Exception\NotFoundException; -use Api\App\Handler\ResponseTrait; +use Api\App\Handler\HandlerTrait; use Api\App\Message; use Dot\AnnotatedServices\Annotation\Inject; use Mezzio\Hal\HalResponseFactory; @@ -24,7 +24,7 @@ class AdminHandler implements RequestHandlerInterface { - use ResponseTrait; + use HandlerTrait; /** * @Inject({ @@ -86,7 +86,7 @@ public function getCollection(ServerRequestInterface $request): ResponseInterfac */ public function patch(ServerRequestInterface $request): ResponseInterface { - $inputFilter = (new UpdateAdminInputFilter())->setData($request->getParsedBody()); + $inputFilter = (new UpdateAdminInputFilter())->setData((array) $request->getParsedBody()); if (! $inputFilter->isValid()) { throw (new BadRequestException())->setMessages($inputFilter->getMessages()); } @@ -109,7 +109,7 @@ public function patch(ServerRequestInterface $request): ResponseInterface */ public function post(ServerRequestInterface $request): ResponseInterface { - $inputFilter = (new CreateAdminInputFilter())->setData($request->getParsedBody()); + $inputFilter = (new CreateAdminInputFilter())->setData((array) $request->getParsedBody()); if (! $inputFilter->isValid()) { throw (new BadRequestException())->setMessages($inputFilter->getMessages()); } diff --git a/src/Admin/src/Handler/AdminRoleHandler.php b/src/Admin/src/Handler/AdminRoleHandler.php index 3707c26..6845c51 100644 --- a/src/Admin/src/Handler/AdminRoleHandler.php +++ b/src/Admin/src/Handler/AdminRoleHandler.php @@ -7,7 +7,7 @@ use Api\Admin\Entity\AdminRole; use Api\Admin\Service\AdminRoleServiceInterface; use Api\App\Exception\NotFoundException; -use Api\App\Handler\ResponseTrait; +use Api\App\Handler\HandlerTrait; use Api\App\Message; use Dot\AnnotatedServices\Annotation\Inject; use Mezzio\Hal\HalResponseFactory; @@ -20,7 +20,7 @@ class AdminRoleHandler implements RequestHandlerInterface { - use ResponseTrait; + use HandlerTrait; /** * @Inject({ diff --git a/src/App/src/Handler/ErrorReportHandler.php b/src/App/src/Handler/ErrorReportHandler.php index f451b84..fb355fa 100644 --- a/src/App/src/Handler/ErrorReportHandler.php +++ b/src/App/src/Handler/ErrorReportHandler.php @@ -22,7 +22,7 @@ */ class ErrorReportHandler implements RequestHandlerInterface { - use ResponseTrait; + use HandlerTrait; /** * @Inject({ diff --git a/src/App/src/Handler/HandlerTrait.php b/src/App/src/Handler/HandlerTrait.php new file mode 100644 index 0000000..e0fcc28 --- /dev/null +++ b/src/App/src/Handler/HandlerTrait.php @@ -0,0 +1,104 @@ +getMethod()); + if ($this->isGetCollectionRequest($request, $this->config)) { + $method = 'getCollection'; + } + + if (! method_exists($this, $method)) { + throw new MethodNotAllowedException( + sprintf('Method %s is not implemented for the requested resource.', $method) + ); + } + + return $this->$method($request); + } catch (ConflictException $exception) { + return $this->errorResponse($exception->getMessage(), StatusCodeInterface::STATUS_CONFLICT); + } catch (ForbiddenException $exception) { + return $this->errorResponse($exception->getMessage(), StatusCodeInterface::STATUS_FORBIDDEN); + } catch (ExpiredException $exception) { + return $this->errorResponse($exception->getMessage(), StatusCodeInterface::STATUS_GONE); + } catch (OutOfBoundsException | NotFoundException $exception) { + return $this->errorResponse($exception->getMessage(), StatusCodeInterface::STATUS_NOT_FOUND); + } catch (UnauthorizedException $exception) { + return $this->errorResponse($exception->getMessage(), StatusCodeInterface::STATUS_UNAUTHORIZED); + } catch (MethodNotAllowedException $exception) { + return $this->errorResponse($exception->getMessage(), StatusCodeInterface::STATUS_METHOD_NOT_ALLOWED); + } catch (BadRequestException $exception) { + return $this->errorResponse($exception->getMessages(), StatusCodeInterface::STATUS_BAD_REQUEST); + } catch (MailException | RuntimeException | Exception $exception) { + return $this->errorResponse($exception->getMessage()); + } + } + + /** + * @throws RuntimeException + */ + private function isGetCollectionRequest(ServerRequestInterface $request, array $config): bool + { + if ($request->getMethod() !== RequestMethodInterface::METHOD_GET) { + return false; + } + + if (! array_key_exists(MetadataMap::class, $config)) { + throw new RuntimeException( + sprintf('Unable to load %s from config.', MetadataMap::class) + ); + } + + /** @var RouteResult $routeResult */ + $routeResult = $request->getAttribute(RouteResult::class); + $routeName = $routeResult->getMatchedRouteName(); + + $halConfig = null; + foreach ($config[MetadataMap::class] as $cfg) { + if ($cfg['route'] === $routeName) { + $halConfig = $cfg; + break; + } + } + + return is_array($halConfig) + && array_key_exists('__class__', $halConfig) + && $halConfig['__class__'] === RouteBasedCollectionMetadata::class; + } +} diff --git a/src/App/src/Handler/HomeHandler.php b/src/App/src/Handler/HomeHandler.php index bcc3f8d..d5c1cae 100644 --- a/src/App/src/Handler/HomeHandler.php +++ b/src/App/src/Handler/HomeHandler.php @@ -8,12 +8,11 @@ use Mezzio\Hal\HalResponseFactory; use Mezzio\Hal\ResourceGenerator; use Psr\Http\Message\ResponseInterface; -use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\RequestHandlerInterface; class HomeHandler implements RequestHandlerInterface { - use ResponseTrait; + use HandlerTrait; /** * @Inject({ @@ -29,7 +28,7 @@ public function __construct( ) { } - public function get(ServerRequestInterface $request): ResponseInterface + public function get(): ResponseInterface { return $this->jsonResponse(['message' => 'Welcome to DotKernel API!']); } diff --git a/src/App/src/Handler/NotFoundHandler.php b/src/App/src/Handler/NotFoundHandler.php index 51f6b2d..cd4ff15 100644 --- a/src/App/src/Handler/NotFoundHandler.php +++ b/src/App/src/Handler/NotFoundHandler.php @@ -10,7 +10,7 @@ class NotFoundHandler implements RequestHandlerInterface { - use ResponseTrait; + use HandlerTrait; public function handle(ServerRequestInterface $request): ResponseInterface { diff --git a/src/App/src/Handler/ResponseTrait.php b/src/App/src/Handler/ResponseTrait.php index 738c16c..518ab6b 100644 --- a/src/App/src/Handler/ResponseTrait.php +++ b/src/App/src/Handler/ResponseTrait.php @@ -4,78 +4,16 @@ namespace Api\App\Handler; -use Api\App\Exception\BadRequestException; -use Api\App\Exception\ConflictException; -use Api\App\Exception\ExpiredException; -use Api\App\Exception\ForbiddenException; -use Api\App\Exception\MethodNotAllowedException; -use Api\App\Exception\NotFoundException; -use Api\App\Exception\UnauthorizedException; -use Dot\Mail\Exception\MailException; -use Exception; -use Fig\Http\Message\RequestMethodInterface; use Fig\Http\Message\StatusCodeInterface; use Laminas\Diactoros\Response\EmptyResponse; use Laminas\Diactoros\Response\JsonResponse; -use Laminas\Diactoros\Response\RedirectResponse; -use Mezzio\Hal\HalResponseFactory; -use Mezzio\Hal\Metadata\MetadataMap; -use Mezzio\Hal\Metadata\RouteBasedCollectionMetadata; -use Mezzio\Hal\ResourceGenerator; -use Mezzio\Hal\ResourceGenerator\Exception\OutOfBoundsException; -use Mezzio\Router\RouteResult; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; -use RuntimeException; -use function array_key_exists; use function is_array; -use function method_exists; -use function sprintf; -use function strtolower; trait ResponseTrait { - protected HalResponseFactory $responseFactory; - protected ResourceGenerator $resourceGenerator; - - /** - * @throws Exception - */ - public function handle(ServerRequestInterface $request): ResponseInterface - { - try { - $method = strtolower($request->getMethod()); - if ($this->isGetCollectionRequest($request, $this->config)) { - $method = 'getCollection'; - } - - if (! method_exists($this, $method)) { - throw new MethodNotAllowedException( - sprintf('Method %s is not implemented for the requested resource.', $method) - ); - } - - return $this->$method($request); - } catch (ConflictException $exception) { - return $this->errorResponse($exception->getMessage(), StatusCodeInterface::STATUS_CONFLICT); - } catch (ForbiddenException $exception) { - return $this->errorResponse($exception->getMessage(), StatusCodeInterface::STATUS_FORBIDDEN); - } catch (ExpiredException $exception) { - return $this->errorResponse($exception->getMessage(), StatusCodeInterface::STATUS_GONE); - } catch (OutOfBoundsException | NotFoundException $exception) { - return $this->errorResponse($exception->getMessage(), StatusCodeInterface::STATUS_NOT_FOUND); - } catch (UnauthorizedException $exception) { - return $this->errorResponse($exception->getMessage(), StatusCodeInterface::STATUS_UNAUTHORIZED); - } catch (MethodNotAllowedException $exception) { - return $this->errorResponse($exception->getMessage(), StatusCodeInterface::STATUS_METHOD_NOT_ALLOWED); - } catch (BadRequestException $exception) { - return $this->errorResponse($exception->getMessages(), StatusCodeInterface::STATUS_BAD_REQUEST); - } catch (MailException | RuntimeException | Exception $exception) { - return $this->errorResponse($exception->getMessage(), StatusCodeInterface::STATUS_INTERNAL_SERVER_ERROR); - } - } - public function createResponse(ServerRequestInterface $request, mixed $instance): ResponseInterface { return $this->responseFactory->createResponse( @@ -98,7 +36,7 @@ public function notFoundResponse(): ResponseInterface public function errorResponse( array|string $messages = [], - int $status = StatusCodeInterface::STATUS_BAD_REQUEST + int $status = StatusCodeInterface::STATUS_INTERNAL_SERVER_ERROR ): ResponseInterface { return $this->jsonResponse([ 'error' => [ @@ -118,11 +56,6 @@ public function infoResponse( ], $status); } - public function redirectResponse(string $location): ResponseInterface - { - return new RedirectResponse($location); - } - public function jsonResponse( array|string $messages = [], int $status = StatusCodeInterface::STATUS_OK @@ -130,35 +63,13 @@ public function jsonResponse( return new JsonResponse($messages, $status); } - /** - * @throws RuntimeException - */ - private function isGetCollectionRequest(ServerRequestInterface $request, array $config): bool + public function notAcceptedResponse(string $message): ResponseInterface { - if ($request->getMethod() !== RequestMethodInterface::METHOD_GET) { - return false; - } - - if (! array_key_exists(MetadataMap::class, $config)) { - throw new RuntimeException( - sprintf('Unable to load %s from config.', MetadataMap::class) - ); - } - - /** @var RouteResult $routeResult */ - $routeResult = $request->getAttribute(RouteResult::class); - $routeName = $routeResult->getMatchedRouteName(); - - $halConfig = null; - foreach ($config[MetadataMap::class] as $cfg) { - if ($cfg['route'] === $routeName) { - $halConfig = $cfg; - break; - } - } + return $this->errorResponse($message, StatusCodeInterface::STATUS_NOT_ACCEPTABLE); + } - return is_array($halConfig) - && array_key_exists('__class__', $halConfig) - && $halConfig['__class__'] === RouteBasedCollectionMetadata::class; + public function unsupportedMediaTypeResponse(string $message): ResponseInterface + { + return $this->errorResponse($message, StatusCodeInterface::STATUS_UNSUPPORTED_MEDIA_TYPE); } } diff --git a/src/App/src/Middleware/ContentNegotiationMiddleware.php b/src/App/src/Middleware/ContentNegotiationMiddleware.php index 4b336fb..cd95cc7 100644 --- a/src/App/src/Middleware/ContentNegotiationMiddleware.php +++ b/src/App/src/Middleware/ContentNegotiationMiddleware.php @@ -4,9 +4,8 @@ namespace Api\App\Middleware; +use Api\App\Handler\ResponseTrait; use Dot\AnnotatedServices\Annotation\Inject; -use Fig\Http\Message\StatusCodeInterface; -use Laminas\Diactoros\Response\JsonResponse; use Mezzio\Router\RouteResult; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; @@ -25,6 +24,8 @@ class ContentNegotiationMiddleware implements MiddlewareInterface { + use ResponseTrait; + /** * @Inject({"config.content-negotiation"}) */ @@ -50,23 +51,14 @@ public function process( $contentType = $request->getHeaderLine('Content-Type'); if (! $this->checkContentType($routeName, $contentType)) { - return $this->unsupportedMediaTypeResponse( - 'Unsupported Media Type' - ); + return $this->unsupportedMediaTypeResponse('Unsupported Media Type'); } $response = $handler->handle($request); $responseContentType = $response->getHeaderLine('Content-Type'); - if ( - ! $this->validateResponseContentType( - $responseContentType, - $accept - ) - ) { - return $this->notAcceptedResponse( - 'Unable to resolve Accept header to a representation' - ); + if (! $this->validateResponseContentType($responseContentType, $accept)) { + return $this->notAcceptedResponse('Unable to resolve Accept header to a representation'); } return $response; @@ -104,6 +96,7 @@ public function checkContentType(string $routeName, string $contentType): bool if (empty($contentType)) { return true; } + $acceptList = $this->config['default']['Content-Type'] ?? []; if (isset($this->config[$routeName])) { $acceptList = $this->config[$routeName]['Content-Type'] ?? []; @@ -116,28 +109,6 @@ public function checkContentType(string $routeName, string $contentType): bool } } - public function notAcceptedResponse(string $message): JsonResponse - { - return new JsonResponse([ - 'error' => [ - 'messages' => [ - $message, - ], - ], - ], StatusCodeInterface::STATUS_NOT_ACCEPTABLE); - } - - public function unsupportedMediaTypeResponse(string $message): JsonResponse - { - return new JsonResponse([ - 'error' => [ - 'messages' => [ - $message, - ], - ], - ], StatusCodeInterface::STATUS_UNSUPPORTED_MEDIA_TYPE); - } - public function validateResponseContentType(?string $contentType, array $accept): bool { if (in_array('*/*', $accept, true)) { diff --git a/src/User/src/Handler/AccountActivateHandler.php b/src/User/src/Handler/AccountActivateHandler.php index 2ad1153..0537c37 100644 --- a/src/User/src/Handler/AccountActivateHandler.php +++ b/src/User/src/Handler/AccountActivateHandler.php @@ -7,7 +7,7 @@ use Api\App\Exception\BadRequestException; use Api\App\Exception\ConflictException; use Api\App\Exception\NotFoundException; -use Api\App\Handler\ResponseTrait; +use Api\App\Handler\HandlerTrait; use Api\App\Message; use Api\User\Entity\User; use Api\User\InputFilter\ActivateAccountInputFilter; @@ -17,7 +17,6 @@ use Fig\Http\Message\StatusCodeInterface; use Mezzio\Hal\HalResponseFactory; use Mezzio\Hal\ResourceGenerator; -use Mezzio\Helper\UrlHelper; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\RequestHandlerInterface; @@ -26,14 +25,13 @@ class AccountActivateHandler implements RequestHandlerInterface { - use ResponseTrait; + use HandlerTrait; /** * @Inject({ * HalResponseFactory::class, * ResourceGenerator::class, * UserServiceInterface::class, - * UrlHelper::class, * "config" * }) */ @@ -41,7 +39,6 @@ public function __construct( protected HalResponseFactory $responseFactory, protected ResourceGenerator $resourceGenerator, protected UserServiceInterface $userService, - protected UrlHelper $urlHelper, protected array $config, ) { } @@ -76,7 +73,7 @@ public function patch(ServerRequestInterface $request): ResponseInterface */ public function post(ServerRequestInterface $request): ResponseInterface { - $inputFilter = (new ActivateAccountInputFilter())->setData($request->getParsedBody()); + $inputFilter = (new ActivateAccountInputFilter())->setData((array) $request->getParsedBody()); if (! $inputFilter->isValid()) { throw (new BadRequestException())->setMessages($inputFilter->getMessages()); } diff --git a/src/User/src/Handler/AccountAvatarHandler.php b/src/User/src/Handler/AccountAvatarHandler.php index cceaec8..d2206ac 100644 --- a/src/User/src/Handler/AccountAvatarHandler.php +++ b/src/User/src/Handler/AccountAvatarHandler.php @@ -6,7 +6,7 @@ use Api\App\Exception\BadRequestException; use Api\App\Exception\NotFoundException; -use Api\App\Handler\ResponseTrait; +use Api\App\Handler\HandlerTrait; use Api\App\Message; use Api\User\Entity\User; use Api\User\InputFilter\UpdateAvatarInputFilter; @@ -20,7 +20,7 @@ class AccountAvatarHandler implements RequestHandlerInterface { - use ResponseTrait; + use HandlerTrait; /** * @Inject({ diff --git a/src/User/src/Handler/AccountHandler.php b/src/User/src/Handler/AccountHandler.php index d5f634a..3388d5c 100644 --- a/src/User/src/Handler/AccountHandler.php +++ b/src/User/src/Handler/AccountHandler.php @@ -6,7 +6,7 @@ use Api\App\Exception\BadRequestException; use Api\App\Exception\ConflictException; -use Api\App\Handler\ResponseTrait; +use Api\App\Handler\HandlerTrait; use Api\User\Entity\User; use Api\User\InputFilter\CreateUserInputFilter; use Api\User\InputFilter\UpdateUserInputFilter; @@ -22,7 +22,7 @@ class AccountHandler implements RequestHandlerInterface { - use ResponseTrait; + use HandlerTrait; /** * @Inject({ @@ -64,7 +64,7 @@ public function patch(ServerRequestInterface $request): ResponseInterface { $inputFilter = (new UpdateUserInputFilter()) ->setValidationGroup(['password', 'passwordConfirm', 'detail']) - ->setData($request->getParsedBody()); + ->setData((array) $request->getParsedBody()); if (! $inputFilter->isValid()) { throw (new BadRequestException())->setMessages($inputFilter->getMessages()); } @@ -83,7 +83,7 @@ public function post(ServerRequestInterface $request): ResponseInterface { $inputFilter = (new CreateUserInputFilter()) ->setValidationGroup(['identity', 'password', 'passwordConfirm', 'detail']) - ->setData($request->getParsedBody()); + ->setData((array) $request->getParsedBody()); if (! $inputFilter->isValid()) { throw (new BadRequestException())->setMessages($inputFilter->getMessages()); } diff --git a/src/User/src/Handler/AccountRecoveryHandler.php b/src/User/src/Handler/AccountRecoveryHandler.php index 9e2b242..c3ba86d 100644 --- a/src/User/src/Handler/AccountRecoveryHandler.php +++ b/src/User/src/Handler/AccountRecoveryHandler.php @@ -6,7 +6,7 @@ use Api\App\Exception\BadRequestException; use Api\App\Exception\NotFoundException; -use Api\App\Handler\ResponseTrait; +use Api\App\Handler\HandlerTrait; use Api\App\Message; use Api\User\Entity\User; use Api\User\InputFilter\RecoverIdentityInputFilter; @@ -23,7 +23,7 @@ class AccountRecoveryHandler implements RequestHandlerInterface { - use ResponseTrait; + use HandlerTrait; /** * @Inject({ @@ -48,7 +48,7 @@ public function __construct( */ public function post(ServerRequestInterface $request): ResponseInterface { - $inputFilter = (new RecoverIdentityInputFilter())->setData($request->getParsedBody()); + $inputFilter = (new RecoverIdentityInputFilter())->setData((array) $request->getParsedBody()); if (! $inputFilter->isValid()) { throw (new BadRequestException())->setMessages($inputFilter->getMessages()); } diff --git a/src/User/src/Handler/AccountResetPasswordHandler.php b/src/User/src/Handler/AccountResetPasswordHandler.php index a3772a1..0df19b4 100644 --- a/src/User/src/Handler/AccountResetPasswordHandler.php +++ b/src/User/src/Handler/AccountResetPasswordHandler.php @@ -8,7 +8,7 @@ use Api\App\Exception\ConflictException; use Api\App\Exception\ExpiredException; use Api\App\Exception\NotFoundException; -use Api\App\Handler\ResponseTrait; +use Api\App\Handler\HandlerTrait; use Api\App\Message; use Api\User\Entity\User; use Api\User\Entity\UserResetPasswordEntity; @@ -27,7 +27,7 @@ class AccountResetPasswordHandler implements RequestHandlerInterface { - use ResponseTrait; + use HandlerTrait; /** * @Inject({ @@ -91,7 +91,7 @@ public function patch(ServerRequestInterface $request): ResponseInterface throw new ConflictException(sprintf(Message::RESET_PASSWORD_USED, $hash)); } - $inputFilter = (new UpdatePasswordInputFilter())->setData($request->getParsedBody()); + $inputFilter = (new UpdatePasswordInputFilter())->setData((array) $request->getParsedBody()); if (! $inputFilter->isValid()) { throw (new BadRequestException())->setMessages($inputFilter->getMessages()); } @@ -114,7 +114,7 @@ public function patch(ServerRequestInterface $request): ResponseInterface */ public function post(ServerRequestInterface $request): ResponseInterface { - $inputFilter = (new ResetPasswordInputFilter())->setData($request->getParsedBody()); + $inputFilter = (new ResetPasswordInputFilter())->setData((array) $request->getParsedBody()); if (! $inputFilter->isValid()) { throw (new BadRequestException())->setMessages($inputFilter->getMessages()); } diff --git a/src/User/src/Handler/UserActivateHandler.php b/src/User/src/Handler/UserActivateHandler.php index 1287d1e..a3fd39d 100644 --- a/src/User/src/Handler/UserActivateHandler.php +++ b/src/User/src/Handler/UserActivateHandler.php @@ -6,7 +6,7 @@ use Api\App\Exception\ConflictException; use Api\App\Exception\NotFoundException; -use Api\App\Handler\ResponseTrait; +use Api\App\Handler\HandlerTrait; use Api\App\Message; use Api\User\Entity\User; use Api\User\Service\UserServiceInterface; @@ -22,7 +22,7 @@ class UserActivateHandler implements RequestHandlerInterface { - use ResponseTrait; + use HandlerTrait; /** * @Inject({ diff --git a/src/User/src/Handler/UserAvatarHandler.php b/src/User/src/Handler/UserAvatarHandler.php index 8d68749..5a5c6f5 100644 --- a/src/User/src/Handler/UserAvatarHandler.php +++ b/src/User/src/Handler/UserAvatarHandler.php @@ -6,7 +6,7 @@ use Api\App\Exception\BadRequestException; use Api\App\Exception\NotFoundException; -use Api\App\Handler\ResponseTrait; +use Api\App\Handler\HandlerTrait; use Api\App\Message; use Api\User\Entity\User; use Api\User\InputFilter\UpdateAvatarInputFilter; @@ -23,7 +23,7 @@ class UserAvatarHandler implements RequestHandlerInterface { - use ResponseTrait; + use HandlerTrait; /** * @Inject({ diff --git a/src/User/src/Handler/UserHandler.php b/src/User/src/Handler/UserHandler.php index 86df062..d589fc4 100644 --- a/src/User/src/Handler/UserHandler.php +++ b/src/User/src/Handler/UserHandler.php @@ -7,7 +7,7 @@ use Api\App\Exception\BadRequestException; use Api\App\Exception\ConflictException; use Api\App\Exception\NotFoundException; -use Api\App\Handler\ResponseTrait; +use Api\App\Handler\HandlerTrait; use Api\App\Message; use Api\User\Entity\User; use Api\User\InputFilter\CreateUserInputFilter; @@ -26,7 +26,7 @@ class UserHandler implements RequestHandlerInterface { - use ResponseTrait; + use HandlerTrait; /** * @Inject({ @@ -88,7 +88,7 @@ public function getCollection(ServerRequestInterface $request): ResponseInterfac */ public function patch(ServerRequestInterface $request): ResponseInterface { - $inputFilter = (new UpdateUserInputFilter())->setData($request->getParsedBody()); + $inputFilter = (new UpdateUserInputFilter())->setData((array) $request->getParsedBody()); if (! $inputFilter->isValid()) { throw (new BadRequestException())->setMessages($inputFilter->getMessages()); } @@ -111,7 +111,7 @@ public function patch(ServerRequestInterface $request): ResponseInterface */ public function post(ServerRequestInterface $request): ResponseInterface { - $inputFilter = (new CreateUserInputFilter())->setData($request->getParsedBody()); + $inputFilter = (new CreateUserInputFilter())->setData((array) $request->getParsedBody()); if (! $inputFilter->isValid()) { throw (new BadRequestException())->setMessages($inputFilter->getMessages()); } diff --git a/src/User/src/Handler/UserRoleHandler.php b/src/User/src/Handler/UserRoleHandler.php index 4c98ed1..39e2e2f 100644 --- a/src/User/src/Handler/UserRoleHandler.php +++ b/src/User/src/Handler/UserRoleHandler.php @@ -5,7 +5,7 @@ namespace Api\User\Handler; use Api\App\Exception\NotFoundException; -use Api\App\Handler\ResponseTrait; +use Api\App\Handler\HandlerTrait; use Api\App\Message; use Api\User\Entity\UserRole; use Api\User\Service\UserRoleServiceInterface; @@ -20,7 +20,7 @@ class UserRoleHandler implements RequestHandlerInterface { - use ResponseTrait; + use HandlerTrait; /** * @Inject({