/
FilterListener.php
55 lines (47 loc) · 1.12 KB
/
FilterListener.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php declare(strict_types = 1);
namespace Bukashk0zzz\FilterBundle\Form\EventListener;
use Bukashk0zzz\FilterBundle\Service\Filter;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
/**
* Class FilterListener
*/
class FilterListener implements EventSubscriberInterface
{
/**
* @var Filter
*/
protected $filterService;
/**
* FilterListener constructor.
*
* @param Filter $filterService
*/
public function __construct(Filter $filterService)
{
$this->filterService = $filterService;
}
/**
* @return string[]
*/
public static function getSubscribedEvents(): array
{
return [
FormEvents::POST_SUBMIT => 'onPostSubmit',
];
}
/**
* @param FormEvent $event
*
* @return void
*/
public function onPostSubmit(FormEvent $event): void
{
$clientData = $event->getData();
if (!\is_object($clientData)) {
return;
}
$this->filterService->filterEntity($clientData);
}
}