From b855799c3d2a5af92ba353e9d4c0a4b8d3f365ae Mon Sep 17 00:00:00 2001 From: Dominik Zogg Date: Sun, 28 Jan 2024 22:00:47 +0100 Subject: [PATCH] chubbyphp-parsing --- composer.json | 1 + config/prod.php | 13 ++++ src/Dto/LinkResponse.php | 15 ++++ src/Dto/ModelRequestInterface.php | 14 ++++ src/Dto/PetRequest.php | 59 +++++++++++++++ src/Dto/PetResponse.php | 28 ++++++++ src/Dto/VaccinationRequest.php | 10 +++ src/Dto/VaccinationResponse.php | 10 +++ src/Model/ModelInterface.php | 2 +- src/Model/Pet.php | 17 +++++ src/Model/Vaccination.php | 9 ++- src/Parsing/ParsingInterface.php | 14 ++++ src/Parsing/PetParsing.php | 48 +++++++++++++ .../Api/Crud/CreateRequestHandler.php | 63 ++++++++-------- .../Api/Crud/ReadRequestHandler.php | 25 ++++++- .../Api/Crud/UpdateRequestHandler.php | 72 +++++++++---------- src/ServiceFactory/Parsing/ParserFactory.php | 18 +++++ .../Parsing/PetParsingFactory.php | 21 ++++++ .../Crud/PetCreateRequestHandlerFactory.php | 16 ++--- .../Api/Crud/PetReadRequestHandlerFactory.php | 8 ++- .../Crud/PetUpdateRequestHandlerFactory.php | 14 ++-- 21 files changed, 387 insertions(+), 90 deletions(-) create mode 100644 src/Dto/LinkResponse.php create mode 100644 src/Dto/ModelRequestInterface.php create mode 100644 src/Dto/PetRequest.php create mode 100644 src/Dto/PetResponse.php create mode 100644 src/Dto/VaccinationRequest.php create mode 100644 src/Dto/VaccinationResponse.php create mode 100644 src/Parsing/ParsingInterface.php create mode 100644 src/Parsing/PetParsing.php create mode 100644 src/ServiceFactory/Parsing/ParserFactory.php create mode 100644 src/ServiceFactory/Parsing/PetParsingFactory.php diff --git a/composer.json b/composer.json index 4b03f7f8..90eeb341 100644 --- a/composer.json +++ b/composer.json @@ -27,6 +27,7 @@ "chubbyphp/chubbyphp-laminas-config-doctrine": "^2.1", "chubbyphp/chubbyphp-laminas-config-factory": "^1.3", "chubbyphp/chubbyphp-negotiation": "^2.0", + "chubbyphp/chubbyphp-parsing": "^1.0@dev", "chubbyphp/chubbyphp-serialization": "^4.0", "chubbyphp/chubbyphp-validation": "^4.0", "doctrine/orm": "^2.17.2", diff --git a/config/prod.php b/config/prod.php index 54cca0f7..37993aa8 100644 --- a/config/prod.php +++ b/config/prod.php @@ -8,6 +8,8 @@ use App\Mapping\Orm\VaccinationMapping; use App\Model\Pet; use App\Model\Vaccination; +use App\Parsing\PetParsing; +use App\Parsing\VaccinationParsing; use App\Repository\PetRepository; use App\RequestHandler\Api\Crud\CreateRequestHandler; use App\RequestHandler\Api\Crud\DeleteRequestHandler; @@ -34,6 +36,8 @@ use App\ServiceFactory\Logger\LoggerFactory; use App\ServiceFactory\Negotiation\AcceptNegotiatorSupportedMediaTypesFactory; use App\ServiceFactory\Negotiation\ContentTypeNegotiatorSupportedMediaTypesFactory; +use App\ServiceFactory\Parsing\ParserFactory; +use App\ServiceFactory\Parsing\PetParsingFactory; use App\ServiceFactory\Repository\PetRepositoryFactory; use App\ServiceFactory\RequestHandler\Api\Crud\PetCreateRequestHandlerFactory; use App\ServiceFactory\RequestHandler\Api\Crud\PetDeleteRequestHandlerFactory; @@ -54,8 +58,12 @@ use Chubbyphp\ApiHttp\ServiceFactory\ResponseManagerFactory; use Chubbyphp\Cors\CorsMiddleware; use Chubbyphp\Cors\ServiceFactory\CorsMiddlewareFactory; +use Chubbyphp\DecodeEncode\Decoder\DecoderInterface; use Chubbyphp\DecodeEncode\Decoder\TypeDecoderInterface; +use Chubbyphp\DecodeEncode\Encoder\EncoderInterface; use Chubbyphp\DecodeEncode\Encoder\TypeEncoderInterface; +use Chubbyphp\DecodeEncode\ServiceFactory\DecoderFactory; +use Chubbyphp\DecodeEncode\ServiceFactory\EncoderFactory; use Chubbyphp\Deserialization\DeserializerInterface; use Chubbyphp\Deserialization\Mapping\DenormalizationObjectMappingInterface; use Chubbyphp\Deserialization\ServiceFactory\DeserializerFactory; @@ -74,6 +82,7 @@ use Chubbyphp\Negotiation\ContentTypeNegotiatorInterface; use Chubbyphp\Negotiation\ServiceFactory\AcceptNegotiatorFactory; use Chubbyphp\Negotiation\ServiceFactory\ContentTypeNegotiatorFactory; +use Chubbyphp\Parsing\ParserInterface; use Chubbyphp\Serialization\Mapping\NormalizationObjectMappingInterface; use Chubbyphp\Serialization\SerializerInterface; use Chubbyphp\Serialization\ServiceFactory\SerializerFactory; @@ -127,8 +136,10 @@ ContentTypeNegotiatorInterface::class . 'supportedMediaTypes[]' => ContentTypeNegotiatorSupportedMediaTypesFactory::class, ContentTypeNegotiatorInterface::class => ContentTypeNegotiatorFactory::class, CorsMiddleware::class => CorsMiddlewareFactory::class, + DecoderInterface::class => DecoderFactory::class, DenormalizationObjectMappingInterface::class . '[]' => DenormalizationObjectMappingsFactory::class, DeserializerInterface::class => DeserializerFactory::class, + EncoderInterface::class => EncoderFactory::class, EntityManagerInterface::class => EntityManagerFactory::class, EntityManagerProvider::class => ContainerEntityManagerProviderFactory::class, ExceptionMiddleware::class => ExceptionMiddlewareFactory::class, @@ -137,6 +148,7 @@ MiddlewareInterface::class . '[]' => MiddlewaresFactory::class, NormalizationObjectMappingInterface::class . '[]' => NormalizationObjectMappingsFactory::class, OpenapiRequestHandler::class => OpenapiRequestHandlerFactory::class, + ParserInterface::class => ParserFactory::class, Pet::class . CreateRequestHandler::class => PetCreateRequestHandlerFactory::class, Pet::class . DeleteRequestHandler::class => PetDeleteRequestHandlerFactory::class, Pet::class . ListRequestHandler::class => PetListRequestHandlerFactory::class, @@ -144,6 +156,7 @@ Pet::class . UpdateRequestHandler::class => PetUpdateRequestHandlerFactory::class, PetCollectionFactory::class => PetCollectionFactoryFactory::class, PetFactory::class => PetFactoryFactory::class, + PetParsing::class => PetParsingFactory::class, PetRepository::class => PetRepositoryFactory::class, PingRequestHandler::class => PingRequestHandlerFactory::class, RequestManagerInterface::class => RequestManagerFactory::class, diff --git a/src/Dto/LinkResponse.php b/src/Dto/LinkResponse.php new file mode 100644 index 00000000..097acab5 --- /dev/null +++ b/src/Dto/LinkResponse.php @@ -0,0 +1,15 @@ + + */ + public array $attributes; +} diff --git a/src/Dto/ModelRequestInterface.php b/src/Dto/ModelRequestInterface.php new file mode 100644 index 00000000..27732018 --- /dev/null +++ b/src/Dto/ModelRequestInterface.php @@ -0,0 +1,14 @@ + + */ + public array $vaccinations; + + public function createModel(): ModelInterface + { + $vaccinations = []; + foreach ($this->vaccinations as $vaccinationRequest) { + $vaccination = new Vaccination(); + $vaccination->setName($vaccinationRequest->name); + + $vaccinations[] = $vaccination; + } + + $model = new Pet(); + $model->setName($this->name); + $model->setTag($this->tag); + $model->setVaccinations($vaccinations); + + return $model; + } + + /** + * @param Pet $model + */ + public function updateModel(ModelInterface $model): ModelInterface + { + $vaccinations = []; + foreach ($this->vaccinations as $vaccinationRequest) { + $vaccination = new Vaccination(); + $vaccination->setName($vaccinationRequest->name); + + $vaccinations[] = $vaccination; + } + + $model->setName($this->name); + $model->setTag($this->tag); + $model->setVaccinations($vaccinations); + + return $model; + } +} diff --git a/src/Dto/PetResponse.php b/src/Dto/PetResponse.php new file mode 100644 index 00000000..b187b630 --- /dev/null +++ b/src/Dto/PetResponse.php @@ -0,0 +1,28 @@ + + */ + public array $vaccinations; + + /** + * @var array + */ + public array $_links; +} diff --git a/src/Dto/VaccinationRequest.php b/src/Dto/VaccinationRequest.php new file mode 100644 index 00000000..e234440f --- /dev/null +++ b/src/Dto/VaccinationRequest.php @@ -0,0 +1,10 @@ +vaccinations->getValues(); } + + public function jsonSerialize(): array + { + $vaccinations = []; + foreach ($this->vaccinations as $vaccination) { + $vaccinations[] = $vaccination->jsonSerialize(); + } + + return [ + 'id' => $this->id, + 'createdAt' => $this->createdAt, + 'updatedAt' => $this->updatedAt, + 'name' => $this->name, + 'tag' => $this->tag, + 'vaccinations' => $vaccinations, + ]; + } } diff --git a/src/Model/Vaccination.php b/src/Model/Vaccination.php index a5087ea3..70fe1fe0 100644 --- a/src/Model/Vaccination.php +++ b/src/Model/Vaccination.php @@ -6,7 +6,7 @@ use Ramsey\Uuid\Uuid; -final class Vaccination +final class Vaccination implements \JsonSerializable { private string $id; @@ -38,4 +38,11 @@ public function setPet(?Pet $pet): void { $this->pet = $pet; } + + public function jsonSerialize(): array + { + return [ + 'name' => $this->name, + ]; + } } diff --git a/src/Parsing/ParsingInterface.php b/src/Parsing/ParsingInterface.php new file mode 100644 index 00000000..8f07b0c8 --- /dev/null +++ b/src/Parsing/ParsingInterface.php @@ -0,0 +1,14 @@ +parser; + + return $p->object([ + 'name' => $p->string(), + 'tag' => $p->string()->nullable(), + 'vaccinations' => $p->array($p->object([ + 'name' => $p->string(), + ], VaccinationRequest::class)), + ], PetRequest::class)->ignore(['id', 'createdAt', 'updatedAt', '_links']); + } + + public function getResponeSchema(): SchemaInterface + { + $p = $this->parser; + + return $p->object([ + 'id' => $p->string(), + 'createdAt' => $p->dateTime()->toString(), + 'updatedAt' => $p->dateTime()->nullable()->toString(), + 'name' => $p->string(), + 'tag' => $p->string()->nullable(), + 'vaccinations' => $p->array($p->object([ + 'name' => $p->string(), + ], VaccinationResponse::class)), + '_links' => $p->record($p->object(['href' => $p->string(), 'attributes' => $p->array($p->string())], LinkResponse::class)), + ], PetResponse::class); + } +} diff --git a/src/RequestHandler/Api/Crud/CreateRequestHandler.php b/src/RequestHandler/Api/Crud/CreateRequestHandler.php index 820d7453..35b137d4 100644 --- a/src/RequestHandler/Api/Crud/CreateRequestHandler.php +++ b/src/RequestHandler/Api/Crud/CreateRequestHandler.php @@ -4,18 +4,13 @@ namespace App\RequestHandler\Api\Crud; -use App\Factory\ModelFactoryInterface; -use App\Model\ModelInterface; +use App\Parsing\ParsingInterface; use App\Repository\RepositoryInterface; -use Chubbyphp\ApiHttp\Manager\RequestManagerInterface; -use Chubbyphp\ApiHttp\Manager\ResponseManagerInterface; -use Chubbyphp\Deserialization\Denormalizer\DenormalizerContextBuilder; -use Chubbyphp\Deserialization\Denormalizer\DenormalizerContextInterface; +use Chubbyphp\DecodeEncode\Decoder\DecoderInterface; +use Chubbyphp\DecodeEncode\Encoder\EncoderInterface; use Chubbyphp\HttpException\HttpException; -use Chubbyphp\Serialization\Normalizer\NormalizerContextBuilder; -use Chubbyphp\Serialization\Normalizer\NormalizerContextInterface; -use Chubbyphp\Validation\Error\ApiProblemErrorMessages; -use Chubbyphp\Validation\ValidatorInterface; +use Chubbyphp\Parsing\ParserErrorException; +use Psr\Http\Message\ResponseFactoryInterface; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\RequestHandlerInterface; @@ -23,11 +18,11 @@ final class CreateRequestHandler implements RequestHandlerInterface { public function __construct( - private ModelFactoryInterface $factory, + private DecoderInterface $decoder, + private ParsingInterface $parsing, private RepositoryInterface $repository, - private RequestManagerInterface $requestManager, - private ResponseManagerInterface $responseManager, - private ValidatorInterface $validator + private EncoderInterface $encoder, + private ResponseFactoryInterface $responseFactory, ) {} public function handle(ServerRequestInterface $request): ResponseInterface @@ -35,31 +30,35 @@ public function handle(ServerRequestInterface $request): ResponseInterface $accept = $request->getAttribute('accept'); $contentType = $request->getAttribute('contentType'); - /** @var ModelInterface $model */ - $model = $this->requestManager->getDataFromRequestBody( - $request, - $this->factory->create(), - $contentType, - $this->getDenormalizerContext() - ); + $input = $this->decoder->decode((string) $request->getBody(), $contentType); - if ([] !== $errors = $this->validator->validate($model)) { - throw HttpException::createUnprocessableEntity(['invalidParameters' => (new ApiProblemErrorMessages($errors))->getMessages()]); + try { + /** @var DtoToModelInterface $dto */ + $dto = $this->parsing->getRequestSchema()->parse($input); + } catch (ParserErrorException $e) { + throw HttpException::createUnprocessableEntity(['invalidParameters' => $e->getApiProblemErrorMessages()]); } + $model = $dto->createModel(); + $this->repository->persist($model); $this->repository->flush(); - return $this->responseManager->create($model, $accept, 201, $this->getNormalizerContext($request)); - } + $output = $this->encoder->encode( + (array) $this->parsing->getResponeSchema()->parse([ + ...$model->jsonSerialize(), + '_links' => [ + 'read' => ['href' => '/api/pets/'.$model->getId(), 'attributes' => ['method' => 'GET']], + 'update' => ['href' => '/api/pets/'.$model->getId(), 'attributes' => ['method' => 'PUT']], + 'delete' => ['href' => '/api/pets/'.$model->getId(), 'attributes' => ['method' => 'DELETE']], + ], + ]), + $accept + ); - private function getDenormalizerContext(): DenormalizerContextInterface - { - return DenormalizerContextBuilder::create()->setClearMissing(true)->getContext(); - } + $response = $this->responseFactory->createResponse(201)->withHeader('Content-Type', $accept); + $response->getBody()->write($output); - private function getNormalizerContext(ServerRequestInterface $request): NormalizerContextInterface - { - return NormalizerContextBuilder::create()->setRequest($request)->getContext(); + return $response; } } diff --git a/src/RequestHandler/Api/Crud/ReadRequestHandler.php b/src/RequestHandler/Api/Crud/ReadRequestHandler.php index 3c4cc671..7c7b1ac0 100644 --- a/src/RequestHandler/Api/Crud/ReadRequestHandler.php +++ b/src/RequestHandler/Api/Crud/ReadRequestHandler.php @@ -4,11 +4,13 @@ namespace App\RequestHandler\Api\Crud; +use App\Parsing\ParsingInterface; use App\Repository\RepositoryInterface; -use Chubbyphp\ApiHttp\Manager\ResponseManagerInterface; +use Chubbyphp\DecodeEncode\Encoder\EncoderInterface; use Chubbyphp\HttpException\HttpException; use Chubbyphp\Serialization\Normalizer\NormalizerContextBuilder; use Chubbyphp\Serialization\Normalizer\NormalizerContextInterface; +use Psr\Http\Message\ResponseFactoryInterface; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\RequestHandlerInterface; @@ -17,8 +19,10 @@ final class ReadRequestHandler implements RequestHandlerInterface { public function __construct( + private ParsingInterface $parsing, private RepositoryInterface $repository, - private ResponseManagerInterface $responseManager + private EncoderInterface $encoder, + private ResponseFactoryInterface $responseFactory, ) {} public function handle(ServerRequestInterface $request): ResponseInterface @@ -30,7 +34,22 @@ public function handle(ServerRequestInterface $request): ResponseInterface throw HttpException::createNotFound(); } - return $this->responseManager->create($model, $accept, 200, $this->getNormalizerContext($request)); + $output = $this->encoder->encode( + (array) $this->parsing->getResponeSchema()->parse([ + ...$model->jsonSerialize(), + '_links' => [ + 'read' => ['href' => '/api/pets/'.$model->getId(), 'attributes' => ['method' => 'GET']], + 'update' => ['href' => '/api/pets/'.$model->getId(), 'attributes' => ['method' => 'PUT']], + 'delete' => ['href' => '/api/pets/'.$model->getId(), 'attributes' => ['method' => 'DELETE']], + ], + ]), + $accept + ); + + $response = $this->responseFactory->createResponse(200)->withHeader('Content-Type', $accept); + $response->getBody()->write($output); + + return $response; } private function getNormalizerContext(ServerRequestInterface $request): NormalizerContextInterface diff --git a/src/RequestHandler/Api/Crud/UpdateRequestHandler.php b/src/RequestHandler/Api/Crud/UpdateRequestHandler.php index 6690580f..6ca8518c 100644 --- a/src/RequestHandler/Api/Crud/UpdateRequestHandler.php +++ b/src/RequestHandler/Api/Crud/UpdateRequestHandler.php @@ -4,17 +4,14 @@ namespace App\RequestHandler\Api\Crud; -use App\Model\ModelInterface; +use App\Dto\ModelRequestInterface; +use App\Parsing\ParsingInterface; use App\Repository\RepositoryInterface; -use Chubbyphp\ApiHttp\Manager\RequestManagerInterface; -use Chubbyphp\ApiHttp\Manager\ResponseManagerInterface; -use Chubbyphp\Deserialization\Denormalizer\DenormalizerContextBuilder; -use Chubbyphp\Deserialization\Denormalizer\DenormalizerContextInterface; +use Chubbyphp\DecodeEncode\Decoder\DecoderInterface; +use Chubbyphp\DecodeEncode\Encoder\EncoderInterface; use Chubbyphp\HttpException\HttpException; -use Chubbyphp\Serialization\Normalizer\NormalizerContextBuilder; -use Chubbyphp\Serialization\Normalizer\NormalizerContextInterface; -use Chubbyphp\Validation\Error\ApiProblemErrorMessages; -use Chubbyphp\Validation\ValidatorInterface; +use Chubbyphp\Parsing\ParserErrorException; +use Psr\Http\Message\ResponseFactoryInterface; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\RequestHandlerInterface; @@ -23,10 +20,11 @@ final class UpdateRequestHandler implements RequestHandlerInterface { public function __construct( + private DecoderInterface $decoder, + private ParsingInterface $parsing, private RepositoryInterface $repository, - private RequestManagerInterface $requestManager, - private ResponseManagerInterface $responseManager, - private ValidatorInterface $validator + private EncoderInterface $encoder, + private ResponseFactoryInterface $responseFactory, ) {} public function handle(ServerRequestInterface $request): ResponseInterface @@ -39,39 +37,39 @@ public function handle(ServerRequestInterface $request): ResponseInterface throw HttpException::createNotFound(); } - /** @var ModelInterface $model */ - $model = $this->requestManager->getDataFromRequestBody( - $request, - $model, - $contentType, - $this->getDenormalizerContext() - ); + $input = $this->decoder->decode((string) $request->getBody(), $contentType); - if ([] !== $errors = $this->validator->validate($model)) { - throw HttpException::createUnprocessableEntity([ - 'invalidParameters' => (new ApiProblemErrorMessages($errors))->getMessages(), - ]); + try { + /** @var ModelRequestInterface $modelRequest */ + $modelRequest = $this->parsing->getRequestSchema()->parse($input); + } catch (ParserErrorException $e) { + throw HttpException::createUnprocessableEntity(['invalidParameters' => $e->getApiProblemErrorMessages()]); } - $model->setUpdatedAt(new \DateTimeImmutable()); + $model = $modelRequest->updateModel($model); $this->repository->persist($model); $this->repository->flush(); - return $this->responseManager->create($model, $accept, 200, $this->getNormalizerContext($request)); - } + try { + } catch (ParserErrorException $e) { + } - private function getDenormalizerContext(): DenormalizerContextInterface - { - return DenormalizerContextBuilder::create() - ->setAllowedAdditionalFields(['id', 'createdAt', 'updatedAt', '_links']) - ->setClearMissing(true) - ->getContext() - ; - } + $output = $this->encoder->encode( + (array) $this->parsing->getResponeSchema()->parse([ + ...$model->jsonSerialize(), + '_links' => [ + 'read' => ['href' => '/api/pets/'.$model->getId(), 'attributes' => ['method' => 'GET']], + 'update' => ['href' => '/api/pets/'.$model->getId(), 'attributes' => ['method' => 'PUT']], + 'delete' => ['href' => '/api/pets/'.$model->getId(), 'attributes' => ['method' => 'DELETE']], + ], + ]), + $accept + ); - private function getNormalizerContext(ServerRequestInterface $request): NormalizerContextInterface - { - return NormalizerContextBuilder::create()->setRequest($request)->getContext(); + $response = $this->responseFactory->createResponse(200)->withHeader('Content-Type', $accept); + $response->getBody()->write($output); + + return $response; } } diff --git a/src/ServiceFactory/Parsing/ParserFactory.php b/src/ServiceFactory/Parsing/ParserFactory.php new file mode 100644 index 00000000..2e52462c --- /dev/null +++ b/src/ServiceFactory/Parsing/ParserFactory.php @@ -0,0 +1,18 @@ +resolveDependency($container, Parser::class, ParserFactory::class); + + return new PetParsing($parser); + } +} diff --git a/src/ServiceFactory/RequestHandler/Api/Crud/PetCreateRequestHandlerFactory.php b/src/ServiceFactory/RequestHandler/Api/Crud/PetCreateRequestHandlerFactory.php index 1e83dc35..8e48b619 100644 --- a/src/ServiceFactory/RequestHandler/Api/Crud/PetCreateRequestHandlerFactory.php +++ b/src/ServiceFactory/RequestHandler/Api/Crud/PetCreateRequestHandlerFactory.php @@ -4,24 +4,24 @@ namespace App\ServiceFactory\RequestHandler\Api\Crud; -use App\Factory\Model\PetFactory; +use App\Parsing\PetParsing; use App\Repository\PetRepository; use App\RequestHandler\Api\Crud\CreateRequestHandler; -use Chubbyphp\ApiHttp\Manager\RequestManagerInterface; -use Chubbyphp\ApiHttp\Manager\ResponseManagerInterface; -use Chubbyphp\Validation\ValidatorInterface; +use Chubbyphp\DecodeEncode\Decoder\DecoderInterface; +use Chubbyphp\DecodeEncode\Encoder\EncoderInterface; use Psr\Container\ContainerInterface; +use Psr\Http\Message\ResponseFactoryInterface; final class PetCreateRequestHandlerFactory { public function __invoke(ContainerInterface $container): CreateRequestHandler { return new CreateRequestHandler( - $container->get(PetFactory::class), + $container->get(DecoderInterface::class), + $container->get(PetParsing::class), $container->get(PetRepository::class), - $container->get(RequestManagerInterface::class), - $container->get(ResponseManagerInterface::class), - $container->get(ValidatorInterface::class) + $container->get(EncoderInterface::class), + $container->get(ResponseFactoryInterface::class), ); } } diff --git a/src/ServiceFactory/RequestHandler/Api/Crud/PetReadRequestHandlerFactory.php b/src/ServiceFactory/RequestHandler/Api/Crud/PetReadRequestHandlerFactory.php index 4ce4666c..215d07c6 100644 --- a/src/ServiceFactory/RequestHandler/Api/Crud/PetReadRequestHandlerFactory.php +++ b/src/ServiceFactory/RequestHandler/Api/Crud/PetReadRequestHandlerFactory.php @@ -4,18 +4,22 @@ namespace App\ServiceFactory\RequestHandler\Api\Crud; +use App\Parsing\PetParsing; use App\Repository\PetRepository; use App\RequestHandler\Api\Crud\ReadRequestHandler; -use Chubbyphp\ApiHttp\Manager\ResponseManagerInterface; +use Chubbyphp\DecodeEncode\Encoder\EncoderInterface; use Psr\Container\ContainerInterface; +use Psr\Http\Message\ResponseFactoryInterface; final class PetReadRequestHandlerFactory { public function __invoke(ContainerInterface $container): ReadRequestHandler { return new ReadRequestHandler( + $container->get(PetParsing::class), $container->get(PetRepository::class), - $container->get(ResponseManagerInterface::class) + $container->get(EncoderInterface::class), + $container->get(ResponseFactoryInterface::class), ); } } diff --git a/src/ServiceFactory/RequestHandler/Api/Crud/PetUpdateRequestHandlerFactory.php b/src/ServiceFactory/RequestHandler/Api/Crud/PetUpdateRequestHandlerFactory.php index b092ab8e..26e7db0b 100644 --- a/src/ServiceFactory/RequestHandler/Api/Crud/PetUpdateRequestHandlerFactory.php +++ b/src/ServiceFactory/RequestHandler/Api/Crud/PetUpdateRequestHandlerFactory.php @@ -4,22 +4,24 @@ namespace App\ServiceFactory\RequestHandler\Api\Crud; +use App\Parsing\PetParsing; use App\Repository\PetRepository; use App\RequestHandler\Api\Crud\UpdateRequestHandler; -use Chubbyphp\ApiHttp\Manager\RequestManagerInterface; -use Chubbyphp\ApiHttp\Manager\ResponseManagerInterface; -use Chubbyphp\Validation\ValidatorInterface; +use Chubbyphp\DecodeEncode\Decoder\DecoderInterface; +use Chubbyphp\DecodeEncode\Encoder\EncoderInterface; use Psr\Container\ContainerInterface; +use Psr\Http\Message\ResponseFactoryInterface; final class PetUpdateRequestHandlerFactory { public function __invoke(ContainerInterface $container): UpdateRequestHandler { return new UpdateRequestHandler( + $container->get(DecoderInterface::class), + $container->get(PetParsing::class), $container->get(PetRepository::class), - $container->get(RequestManagerInterface::class), - $container->get(ResponseManagerInterface::class), - $container->get(ValidatorInterface::class) + $container->get(EncoderInterface::class), + $container->get(ResponseFactoryInterface::class), ); } }