-
-
Save AndreTeros/c4e3c1f2d6b056d6e74b24fdc6b35aee to your computer and use it in GitHub Desktop.
Revisions
-
thatside revised this gist
Sep 27, 2019 . 1 changed file with 0 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -32,9 +32,6 @@ public function resolve(Request $request, ArgumentMetadata $argumentMetadata): \ /** @var RequestData $mapped */ $mapped = $requestData::create($request->request); $errors = $this->validator->validate($mapped); -
thatside created this gist
Sep 27, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,47 @@ <?php declare(strict_types=1); namespace Common\ArgumentResolver; use Common\Exception\ValidationErrorException; use Common\Request\RequestData; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Controller\ArgumentValueResolverInterface; use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata; use Symfony\Component\Validator\Validator\ValidatorInterface; class RequestResolver implements ArgumentValueResolverInterface { private $validator; public function __construct(ValidatorInterface $validator) { $this->validator = $validator; } public function supports(Request $request, ArgumentMetadata $argumentMetadata): bool { return is_subclass_of($argumentMetadata->getType(), RequestData::class); } public function resolve(Request $request, ArgumentMetadata $argumentMetadata): \Generator { /** @var RequestData $requestData */ $requestData = $argumentMetadata->getType(); /** @var RequestData $mapped */ $mapped = $requestData::create($request->request); if ($request->attributes->has('companySubdomain')) { $mapped->setCompanySubdomain($request->attributes->get('companySubdomain')); } $errors = $this->validator->validate($mapped); if (count($errors)) { throw new ValidationErrorException($errors); } yield $mapped; } }