forked from KnpLabs/knp-components
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFiltrationSubscriber.php
37 lines (30 loc) · 1008 Bytes
/
FiltrationSubscriber.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
<?php
namespace Knp\Component\Pager\Event\Subscriber\Filtration;
use Knp\Component\Pager\Event\BeforeEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class FiltrationSubscriber implements EventSubscriberInterface
{
/**
* Lazy-load state tracker
*/
private bool $isLoaded = false;
public function before(BeforeEvent $event): void
{
// Do not lazy-load more than once
if ($this->isLoaded) {
return;
}
/** @var \Symfony\Component\EventDispatcher\EventDispatcherInterface $dispatcher */
$dispatcher = $event->getEventDispatcher();
// hook all standard filtration subscribers
$dispatcher->addSubscriber(new Doctrine\ORM\QuerySubscriber());
$dispatcher->addSubscriber(new PropelQuerySubscriber());
$this->isLoaded = true;
}
public static function getSubscribedEvents(): array
{
return [
'knp_pager.before' => ['before', 1],
];
}
}