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
;
21 * @author Bernhard Schussek <bschussek@gmail.com>
23 class TrimListener
implements EventSubscriberInterface
25 public function preSubmit(FormEvent
$event)
27 $data = $event->getData();
29 if (!is_string($data)) {
33 if (null !== $result = @preg_replace('/^[\pZ\p{Cc}]+|[\pZ\p{Cc}]+$/u', '', $data)) {
34 $event->setData($result);
36 $event->setData(trim($data));
41 * Alias of {@link preSubmit()}.
43 * @deprecated Deprecated since version 2.3, to be removed in 3.0. Use
44 * {@link preSubmit()} instead.
46 public function preBind(FormEvent
$event)
48 $this->preSubmit($event);
51 public static function getSubscribedEvents()
53 return array(FormEvents
::PRE_SUBMIT
=> 'preSubmit');