[Form] fix form handling with unconventional request methods like OPTIONS
This commit is contained in:
parent
6df49bb9e1
commit
28eabd84f8
@ -13,7 +13,6 @@ namespace Symfony\Component\Form\Extension\HttpFoundation\EventListener;
|
||||
|
||||
use Symfony\Component\Form\FormEvents;
|
||||
use Symfony\Component\Form\FormEvent;
|
||||
use Symfony\Component\Form\Exception\LogicException;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
@ -49,12 +48,19 @@ class BindRequestListener implements EventSubscriberInterface
|
||||
$name = $form->getConfig()->getName();
|
||||
$default = $form->getConfig()->getCompound() ? array() : null;
|
||||
|
||||
// Store the bound data in case of a post request
|
||||
// For request methods that must not have a request body we fetch data
|
||||
// from the query string. Otherwise we look for data in the request body.
|
||||
switch ($request->getMethod()) {
|
||||
case 'POST':
|
||||
case 'PUT':
|
||||
case 'DELETE':
|
||||
case 'PATCH':
|
||||
case 'GET':
|
||||
case 'HEAD':
|
||||
case 'TRACE':
|
||||
$data = '' === $name
|
||||
? $request->query->all()
|
||||
: $request->query->get($name, $default);
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
if ('' === $name) {
|
||||
// Form bound without name
|
||||
$params = $request->request->all();
|
||||
@ -71,19 +77,6 @@ class BindRequestListener implements EventSubscriberInterface
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'GET':
|
||||
$data = '' === $name
|
||||
? $request->query->all()
|
||||
: $request->query->get($name, $default);
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new LogicException(sprintf(
|
||||
'The request method "%s" is not supported',
|
||||
$request->getMethod()
|
||||
));
|
||||
}
|
||||
|
||||
$event->setData($data);
|
||||
|
@ -55,7 +55,9 @@ class HttpFoundationRequestHandler implements RequestHandlerInterface
|
||||
return;
|
||||
}
|
||||
|
||||
if ('GET' === $method) {
|
||||
// For request methods that must not have a request body we fetch data
|
||||
// from the query string. Otherwise we look for data in the request body.
|
||||
if ('GET' === $method || 'HEAD' === $method || 'TRACE' === $method) {
|
||||
if ('' === $name) {
|
||||
$data = $request->query->all();
|
||||
} else {
|
||||
|
@ -63,7 +63,9 @@ class NativeRequestHandler implements RequestHandlerInterface
|
||||
return;
|
||||
}
|
||||
|
||||
if ('GET' === $method) {
|
||||
// For request methods that must not have a request body we fetch data
|
||||
// from the query string. Otherwise we look for data in the request body.
|
||||
if ('GET' === $method || 'HEAD' === $method || 'TRACE' === $method) {
|
||||
if ('' === $name) {
|
||||
$data = $_GET;
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user