[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\FormEvents;
|
||||||
use Symfony\Component\Form\FormEvent;
|
use Symfony\Component\Form\FormEvent;
|
||||||
use Symfony\Component\Form\Exception\LogicException;
|
|
||||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
|
||||||
@ -49,12 +48,19 @@ class BindRequestListener implements EventSubscriberInterface
|
|||||||
$name = $form->getConfig()->getName();
|
$name = $form->getConfig()->getName();
|
||||||
$default = $form->getConfig()->getCompound() ? array() : null;
|
$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()) {
|
switch ($request->getMethod()) {
|
||||||
case 'POST':
|
case 'GET':
|
||||||
case 'PUT':
|
case 'HEAD':
|
||||||
case 'DELETE':
|
case 'TRACE':
|
||||||
case 'PATCH':
|
$data = '' === $name
|
||||||
|
? $request->query->all()
|
||||||
|
: $request->query->get($name, $default);
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
if ('' === $name) {
|
if ('' === $name) {
|
||||||
// Form bound without name
|
// Form bound without name
|
||||||
$params = $request->request->all();
|
$params = $request->request->all();
|
||||||
@ -71,19 +77,6 @@ class BindRequestListener implements EventSubscriberInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
break;
|
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);
|
$event->setData($data);
|
||||||
|
@ -55,7 +55,9 @@ class HttpFoundationRequestHandler implements RequestHandlerInterface
|
|||||||
return;
|
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) {
|
if ('' === $name) {
|
||||||
$data = $request->query->all();
|
$data = $request->query->all();
|
||||||
} else {
|
} else {
|
||||||
|
@ -63,7 +63,9 @@ class NativeRequestHandler implements RequestHandlerInterface
|
|||||||
return;
|
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) {
|
if ('' === $name) {
|
||||||
$data = $_GET;
|
$data = $_GET;
|
||||||
} else {
|
} else {
|
||||||
|
Reference in New Issue
Block a user