Skip to content
This repository has been archived by the owner on Dec 1, 2023. It is now read-only.

Commit

Permalink
Upgrade sbsedv/input-converter to version 3
Browse files Browse the repository at this point in the history
  • Loading branch information
danielburger1337 committed Apr 17, 2023
1 parent 19b486c commit b434b1d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 14 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
},
"require": {
"php": ">=8.1",
"sbsedv/input-converter": "^2.0",
"sbsedv/input-converter": "^3.0",
"symfony/framework-bundle": "^6.1"
},
"require-dev": {
Expand Down
17 changes: 4 additions & 13 deletions src/EventSubscriber/ConvertInputEventSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use SBSEDV\InputConverter\Exception\MalformedContentException;
use SBSEDV\InputConverter\Exception\UnsupportedRequestException;
use SBSEDV\InputConverter\InputConverter;
use SBSEDV\InputConverter\Request\HttpFoundationRequest;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\Exception\BadRequestException;
use Symfony\Component\HttpKernel\Event\RequestEvent;
Expand All @@ -27,20 +28,10 @@ public function onKernelRequest(RequestEvent $event): void
return;
}

$request = $event->getRequest();

try {
$parsedInput = $this->inputConverter->convert($request);

foreach ($parsedInput->getValues() as $key => $value) {
$request->request->set($key, $value);
}

foreach ($parsedInput->getFiles() as $key => $value) {
$request->files->set($key, $value);
}

$request->attributes->set('_input_converter', $parsedInput->getConverterName());
$this->inputConverter->convert(
new HttpFoundationRequest($event->getRequest())
);
} catch (MalformedContentException $e) {
throw new BadRequestException($e->getMessage(), previous: $e);
} catch (UnsupportedRequestException) {
Expand Down

0 comments on commit b434b1d

Please sign in to comment.