tandrewcl / api-request-convert
Convert request content to DTO classes
Installs: 145
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- php: >=8.0.2
- symfony/http-kernel: ^6.2
README
About bundle
This bundle is a simple solution to convert request to DTO classes
Installation
Step 1: Download the Bundle
Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:
$ composer require tandrewcl/api-request-convert
This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.
Step 2: Config and Usage
Thanks for Symfony flex Bundle is auto enabled in config/bundles.php
... use tandrewcl\ApiRequestConvertBundle\DTO\ResolvableInputDTOInterface; ... class LoginDTO implements ResolvableInputDTOInterface { #[Assert\NotBlank] #[Assert\Length(max: 16)] public ?string $login = null; #[Assert\NotBlank] #[Assert\Length(max: 16)] public ?string $password = null; public function handleRequest(Request $request): void { $params = $request->request->all(); $this->login = $params['login'] ?? null; $this->password = $params['password'] ?? null; } }
... use tandrewcl\ApiResponseConvertBundle\Handler\ResponseHandler; ... class FooController { public function loginAction(LoginDTO $loginDTO): Response { ... $authResult = $authService->auth($loginDTO->login, $loginDTO->password); ... }