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\EventListener
;
14 use Symfony\Component\Form\FormEvents
;
15 use Symfony\Component\Form\FormEvent
;
16 use Symfony\Component\Form\Exception\LogicException
;
17 use Symfony\Component\EventDispatcher\EventSubscriberInterface
;
18 use Symfony\Component\HttpFoundation\Request
;
21 * @author Bernhard Schussek <bschussek@gmail.com>
23 * @deprecated Deprecated since version 2.3, to be removed in 3.0. Pass the
24 * Request instance to {@link Form::process()} instead.
26 class BindRequestListener
implements EventSubscriberInterface
28 public static function getSubscribedEvents()
30 // High priority in order to supersede other listeners
31 return array(FormEvents
::PRE_BIND
=> array('preBind', 128));
34 public function preBind(FormEvent
$event)
36 $form = $event->getForm();
38 /* @var Request $request */
39 $request = $event->getData();
41 // Only proceed if we actually deal with a Request
42 if (!$request instanceof Request
) {
46 // Uncomment this as soon as the deprecation note should be shown
47 // trigger_error('Passing a Request instance to Form::submit() is deprecated since version 2.3 and will be disabled in 3.0. Call Form::process($request) instead.', E_USER_DEPRECATED);
49 $name = $form->getConfig()->getName();
50 $default = $form->getConfig()->getCompound() ? array() : null;
52 // Store the bound data in case of a post request
53 switch ($request->getMethod()) {
59 // Form bound without name
60 $params = $request->request
->all();
61 $files = $request->files
->all();
63 $params = $request->request
->get($name, $default);
64 $files = $request->files
->get($name, $default);
67 if (is_array($params) && is_array($files)) {
68 $data = array_replace_recursive($params, $files);
70 $data = $params ?: $files;
77 ? $request->query
->all()
78 : $request->query
->get($name, $default);
83 throw new LogicException(sprintf(
84 'The request method "%s" is not supported',
89 $event->setData($data);