]> git.immae.eu Git - github/wallabag/wallabag.git/blob - vendor/symfony/form/Symfony/Component/Form/Tests/Fixtures/FixedFilterListener.php
twig implementation
[github/wallabag/wallabag.git] / vendor / symfony / form / Symfony / Component / Form / Tests / Fixtures / FixedFilterListener.php
1 <?php
2
3 /*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12 namespace Symfony\Component\Form\Tests\Fixtures;
13
14 use Symfony\Component\Form\FormEvents;
15 use Symfony\Component\Form\FormEvent;
16 use Symfony\Component\EventDispatcher\EventSubscriberInterface;
17
18 class FixedFilterListener implements EventSubscriberInterface
19 {
20 private $mapping;
21
22 public function __construct(array $mapping)
23 {
24 $this->mapping = array_merge(array(
25 'preSubmit' => array(),
26 'onSubmit' => array(),
27 'preSetData' => array(),
28 ), $mapping);
29 }
30
31 public function preSubmit(FormEvent $event)
32 {
33 $data = $event->getData();
34
35 if (isset($this->mapping['preSubmit'][$data])) {
36 $event->setData($this->mapping['preSubmit'][$data]);
37 }
38 }
39
40 public function onSubmit(FormEvent $event)
41 {
42 $data = $event->getData();
43
44 if (isset($this->mapping['onSubmit'][$data])) {
45 $event->setData($this->mapping['onSubmit'][$data]);
46 }
47 }
48
49 public function preSetData(FormEvent $event)
50 {
51 $data = $event->getData();
52
53 if (isset($this->mapping['preSetData'][$data])) {
54 $event->setData($this->mapping['preSetData'][$data]);
55 }
56 }
57
58 public static function getSubscribedEvents()
59 {
60 return array(
61 FormEvents::PRE_SUBMIT => 'preSubmit',
62 FormEvents::SUBMIT => 'onSubmit',
63 FormEvents::PRE_SET_DATA => 'preSetData',
64 );
65 }
66 }