diff --git a/composer.json b/composer.json index 4b03f7f8..1a4ad641 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,8 @@ "chubbyphp/chubbyphp-laminas-config": "^1.4", "chubbyphp/chubbyphp-laminas-config-doctrine": "^2.1", "chubbyphp/chubbyphp-laminas-config-factory": "^1.3", - "chubbyphp/chubbyphp-negotiation": "^2.0", + "chubbyphp/chubbyphp-negotiation": "^2.1", + "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..074474f6 100644 --- a/config/prod.php +++ b/config/prod.php @@ -2,12 +2,14 @@ declare(strict_types=1); +use App\Enrich\EnrichInterface; use App\Factory\Collection\PetCollectionFactory; use App\Factory\Model\PetFactory; use App\Mapping\Orm\PetMapping; use App\Mapping\Orm\VaccinationMapping; use App\Model\Pet; use App\Model\Vaccination; +use App\Parsing\PetParsing; use App\Repository\PetRepository; use App\RequestHandler\Api\Crud\CreateRequestHandler; use App\RequestHandler\Api\Crud\DeleteRequestHandler; @@ -21,6 +23,7 @@ use App\ServiceFactory\DecodeEncode\TypeDecodersFactory; use App\ServiceFactory\DecodeEncode\TypeEncodersFactory; use App\ServiceFactory\Deserialization\DenormalizationObjectMappingsFactory; +use App\ServiceFactory\Enrich\PetEnrichFactory; use App\ServiceFactory\Factory\Collection\PetCollectionFactoryFactory; use App\ServiceFactory\Factory\Model\PetFactoryFactory; use App\ServiceFactory\Framework\ExceptionMiddlewareFactory; @@ -34,6 +37,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; @@ -46,16 +51,18 @@ use App\ServiceFactory\Validation\ValidationMappingProviderFactory; use Chubbyphp\ApiHttp\Manager\RequestManagerInterface; use Chubbyphp\ApiHttp\Manager\ResponseManagerInterface; -use Chubbyphp\ApiHttp\Middleware\AcceptAndContentTypeMiddleware; use Chubbyphp\ApiHttp\Middleware\ApiExceptionMiddleware; -use Chubbyphp\ApiHttp\ServiceFactory\AcceptAndContentTypeMiddlewareFactory; use Chubbyphp\ApiHttp\ServiceFactory\ApiExceptionMiddlewareFactory; use Chubbyphp\ApiHttp\ServiceFactory\RequestManagerFactory; 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; @@ -72,8 +79,13 @@ use Chubbyphp\Laminas\Config\Doctrine\ServiceFactory\Persistence\Mapping\Driver\ClassMapDriverFactory; use Chubbyphp\Negotiation\AcceptNegotiatorInterface; use Chubbyphp\Negotiation\ContentTypeNegotiatorInterface; +use Chubbyphp\Negotiation\Middleware\AcceptMiddleware; +use Chubbyphp\Negotiation\Middleware\ContentTypeMiddleware; +use Chubbyphp\Negotiation\ServiceFactory\AcceptMiddlewareFactory; use Chubbyphp\Negotiation\ServiceFactory\AcceptNegotiatorFactory; +use Chubbyphp\Negotiation\ServiceFactory\ContentTypeMiddlewareFactory; use Chubbyphp\Negotiation\ServiceFactory\ContentTypeNegotiatorFactory; +use Chubbyphp\Parsing\ParserInterface; use Chubbyphp\Serialization\Mapping\NormalizationObjectMappingInterface; use Chubbyphp\Serialization\SerializerInterface; use Chubbyphp\Serialization\ServiceFactory\SerializerFactory; @@ -116,7 +128,7 @@ EntityManager::class => EntityManagerInterface::class, ], 'factories' => [ - AcceptAndContentTypeMiddleware::class => AcceptAndContentTypeMiddlewareFactory::class, + AcceptMiddleware::class => AcceptMiddlewareFactory::class, AcceptNegotiatorInterface::class . 'supportedMediaTypes[]' => AcceptNegotiatorSupportedMediaTypesFactory::class, AcceptNegotiatorInterface::class => AcceptNegotiatorFactory::class, ApiExceptionMiddleware::class => ApiExceptionMiddlewareFactory::class, @@ -124,11 +136,14 @@ Command::class . '[]' => CommandsFactory::class, Connection::class => ConnectionFactory::class, ConnectionProvider::class => ContainerConnectionProviderFactory::class, + ContentTypeMiddleware::class => ContentTypeMiddlewareFactory::class, 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,13 +152,16 @@ 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 . EnrichInterface::class => PetEnrichFactory::class, Pet::class . ListRequestHandler::class => PetListRequestHandlerFactory::class, Pet::class . ReadRequestHandler::class => PetReadRequestHandlerFactory::class, 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 @@ + + */ + public function enrich(ModelInterface $model): array + { + return [ + ...$model->jsonSerialize(), + '_links' => [ + 'read' => ['href' => $this->basePath.$model->getId(), 'attributes' => ['method' => 'GET']], + 'update' => ['href' => $this->basePath.$model->getId(), 'attributes' => ['method' => 'PUT']], + 'delete' => ['href' => $this->basePath.$model->getId(), 'attributes' => ['method' => 'DELETE']], + ], + ]; + } +} diff --git a/src/Enrich/EnrichInterface.php b/src/Enrich/EnrichInterface.php new file mode 100644 index 00000000..9fa5cfea --- /dev/null +++ b/src/Enrich/EnrichInterface.php @@ -0,0 +1,15 @@ + + */ + public function enrich(ModelInterface $model): array; +} diff --git a/src/Model/ModelInterface.php b/src/Model/ModelInterface.php index 3742af10..4c4dcd29 100644 --- a/src/Model/ModelInterface.php +++ b/src/Model/ModelInterface.php @@ -4,7 +4,7 @@ namespace App\Model; -interface ModelInterface +interface ModelInterface extends \JsonSerializable { public function getId(): string; diff --git a/src/Model/Pet.php b/src/Model/Pet.php index c341ec8d..8ce07efc 100644 --- a/src/Model/Pet.php +++ b/src/Model/Pet.php @@ -106,4 +106,21 @@ public function getVaccinations(): array { return $this->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..bdb253b2 100644 --- a/src/RequestHandler/Api/Crud/CreateRequestHandler.php +++ b/src/RequestHandler/Api/Crud/CreateRequestHandler.php @@ -4,18 +4,14 @@ namespace App\RequestHandler\Api\Crud; -use App\Factory\ModelFactoryInterface; -use App\Model\ModelInterface; +use App\Enrich\EnrichInterface; +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 +19,12 @@ 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 EnrichInterface $enrich, + private EncoderInterface $encoder, + private ResponseFactoryInterface $responseFactory, ) {} public function handle(ServerRequestInterface $request): ResponseInterface @@ -35,31 +32,28 @@ 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($this->enrich->enrich($model)), + $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..5fe4b618 100644 --- a/src/RequestHandler/Api/Crud/ReadRequestHandler.php +++ b/src/RequestHandler/Api/Crud/ReadRequestHandler.php @@ -4,11 +4,14 @@ namespace App\RequestHandler\Api\Crud; +use App\Enrich\EnrichInterface; +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 +20,11 @@ final class ReadRequestHandler implements RequestHandlerInterface { public function __construct( + private ParsingInterface $parsing, private RepositoryInterface $repository, - private ResponseManagerInterface $responseManager + private EnrichInterface $enrich, + private EncoderInterface $encoder, + private ResponseFactoryInterface $responseFactory, ) {} public function handle(ServerRequestInterface $request): ResponseInterface @@ -30,7 +36,15 @@ 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($this->enrich->enrich($model)), + $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..acdebc93 100644 --- a/src/RequestHandler/Api/Crud/UpdateRequestHandler.php +++ b/src/RequestHandler/Api/Crud/UpdateRequestHandler.php @@ -4,17 +4,15 @@ namespace App\RequestHandler\Api\Crud; -use App\Model\ModelInterface; +use App\Dto\ModelRequestInterface; +use App\Enrich\EnrichInterface; +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 +21,12 @@ 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 EnrichInterface $enrich, + private EncoderInterface $encoder, + private ResponseFactoryInterface $responseFactory, ) {} public function handle(ServerRequestInterface $request): ResponseInterface @@ -39,39 +39,32 @@ 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($this->enrich->enrich($model)), + $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/Enrich/PetEnrichFactory.php b/src/ServiceFactory/Enrich/PetEnrichFactory.php new file mode 100644 index 00000000..9c531ba0 --- /dev/null +++ b/src/ServiceFactory/Enrich/PetEnrichFactory.php @@ -0,0 +1,18 @@ +getRoutes() ); } 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..a4340aac 100644 --- a/src/ServiceFactory/RequestHandler/Api/Crud/PetCreateRequestHandlerFactory.php +++ b/src/ServiceFactory/RequestHandler/Api/Crud/PetCreateRequestHandlerFactory.php @@ -4,24 +4,27 @@ namespace App\ServiceFactory\RequestHandler\Api\Crud; -use App\Factory\Model\PetFactory; +use App\Enrich\EnrichInterface; +use App\Model\Pet; +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(Pet::class.EnrichInterface::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..47c9ee55 100644 --- a/src/ServiceFactory/RequestHandler/Api/Crud/PetReadRequestHandlerFactory.php +++ b/src/ServiceFactory/RequestHandler/Api/Crud/PetReadRequestHandlerFactory.php @@ -4,18 +4,25 @@ namespace App\ServiceFactory\RequestHandler\Api\Crud; +use App\Enrich\EnrichInterface; +use App\Model\Pet; +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(Pet::class.EnrichInterface::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..ab6486ad 100644 --- a/src/ServiceFactory/RequestHandler/Api/Crud/PetUpdateRequestHandlerFactory.php +++ b/src/ServiceFactory/RequestHandler/Api/Crud/PetUpdateRequestHandlerFactory.php @@ -4,22 +4,27 @@ namespace App\ServiceFactory\RequestHandler\Api\Crud; +use App\Enrich\EnrichInterface; +use App\Model\Pet; +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(Pet::class.EnrichInterface::class), + $container->get(EncoderInterface::class), + $container->get(ResponseFactoryInterface::class), ); } }