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\Core\EventListener
;
14 use Symfony\Component\Form\FormEvents
;
15 use Symfony\Component\Form\FormEvent
;
16 use Symfony\Component\EventDispatcher\EventSubscriberInterface
;
19 * Adds a protocol to a URL if it doesn't already have one.
21 * @author Bernhard Schussek <bschussek@gmail.com>
23 class FixUrlProtocolListener
implements EventSubscriberInterface
25 private $defaultProtocol;
27 public function __construct($defaultProtocol = 'http')
29 $this->defaultProtocol
= $defaultProtocol;
32 public function onSubmit(FormEvent
$event)
34 $data = $event->getData();
36 if ($this->defaultProtocol
&& $data && !preg_match('~^\w+://~', $data)) {
37 $event->setData($this->defaultProtocol
.'://'.$data);
42 * Alias of {@link onSubmit()}.
44 * @deprecated Deprecated since version 2.3, to be removed in 3.0. Use
45 * {@link onSubmit()} instead.
47 public function onBind(FormEvent
$event)
49 $this->onSubmit($event);
52 public static function getSubscribedEvents()
54 return array(FormEvents
::SUBMIT
=> 'onSubmit');