4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Form\Extension\HttpFoundation
;
14 use Symfony\Component\Form\Exception\UnexpectedTypeException
;
15 use Symfony\Component\Form\FormInterface
;
16 use Symfony\Component\Form\RequestHandlerInterface
;
17 use Symfony\Component\HttpFoundation\Request
;
20 * A request processor using the {@link Request} class of the HttpFoundation
23 * @author Bernhard Schussek <bschussek@gmail.com>
25 class HttpFoundationRequestHandler
implements RequestHandlerInterface
30 public function handleRequest(FormInterface
$form, $request = null)
32 if (!$request instanceof Request
) {
33 throw new UnexpectedTypeException($request, 'Symfony\Component\HttpFoundation\Request');
36 $name = $form->getName();
37 $method = $form->getConfig()->getMethod();
39 if ($method !== $request->getMethod()) {
43 if ('GET' === $method) {
45 $data = $request->query
->all();
47 // Don't submit GET requests if the form's name does not exist
49 if (!$request->query
->has($name)) {
53 $data = $request->query
->get($name);
57 $params = $request->request
->all();
58 $files = $request->files
->all();
60 $default = $form->getConfig()->getCompound() ? array() : null;
61 $params = $request->request
->get($name, $default);
62 $files = $request->files
->get($name, $default);
65 if (is_array($params) && is_array($files)) {
66 $data = array_replace_recursive($params, $files);
68 $data = $params ?: $files;
72 // Don't auto-submit the form unless at least one field is present.
73 if ('' === $name && count(array_intersect_key($data, $form->all())) <= 0) {
77 $form->submit($data, 'PATCH' !== $method);