From 109df85ad37998de6ffe98d71d594718dfc00703 Mon Sep 17 00:00:00 2001 From: Steve Nebes Date: Tue, 16 Apr 2019 00:41:55 -0500 Subject: [PATCH 1/7] config tree root (#1) --- DependencyInjection/Configuration.php | 1 - 1 file changed, 1 deletion(-) diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index db809e5..8658bf1 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -2,7 +2,6 @@ namespace Lexik\Bundle\FormFilterBundle\DependencyInjection; -use Lexik\Bundle\FormFilterBundle\Filter\FilterOperands; use Symfony\Component\Config\Definition\Builder\TreeBuilder; use Symfony\Component\Config\Definition\ConfigurationInterface; From 35837c025a8ec0d21836af46e9052694070d4e6f Mon Sep 17 00:00:00 2001 From: Steve Nebes Date: Sun, 1 Sep 2019 15:37:43 -0500 Subject: [PATCH 2/7] Update event & dispatching for symfony/contracts style events --- Event/ApplyFilterConditionEvent.php | 1 - Event/Event.php | 16 ++++++++++++++++ Event/GetFilterConditionEvent.php | 1 - Event/PrepareEvent.php | 1 - Filter/FilterBuilderUpdater.php | 22 +++++++++++++++++++--- 5 files changed, 35 insertions(+), 6 deletions(-) create mode 100644 Event/Event.php diff --git a/Event/ApplyFilterConditionEvent.php b/Event/ApplyFilterConditionEvent.php index 05d24c0..0187fac 100644 --- a/Event/ApplyFilterConditionEvent.php +++ b/Event/ApplyFilterConditionEvent.php @@ -3,7 +3,6 @@ namespace Lexik\Bundle\FormFilterBundle\Event; use Lexik\Bundle\FormFilterBundle\Filter\Condition\ConditionBuilderInterface; -use Symfony\Component\EventDispatcher\Event; /** * Event class to compute the WHERE clause from the conditions. diff --git a/Event/Event.php b/Event/Event.php new file mode 100644 index 0000000..3c4b192 --- /dev/null +++ b/Event/Event.php @@ -0,0 +1,16 @@ +dispatcher->dispatch(FilterEvents::PREPARE, $event); + $this->dispatch(FilterEvents::PREPARE, $event); if (!$event->getFilterQuery() instanceof QueryInterface) { throw new \RuntimeException("Couldn't find any filter query object."); @@ -103,7 +104,7 @@ public function addFilterConditions(FormInterface $form, $queryBuilder, $alias = // walk condition nodes to add condition on the query builder instance $name = sprintf('lexik_filter.apply_filters.%s', $event->getFilterQuery()->getEventPartName()); - $this->dispatcher->dispatch($name, new ApplyFilterConditionEvent($queryBuilder, $this->conditionBuilder)); + $this->dispatch($name, new ApplyFilterConditionEvent($queryBuilder, $this->conditionBuilder)); $this->conditionBuilder = null; @@ -207,7 +208,7 @@ protected function getFilterCondition(FormInterface $form, AbstractType $formTyp } $event = new GetFilterConditionEvent($filterQuery, $field, $values); - $this->dispatcher->dispatch($eventName, $event); + $this->dispatch($eventName, $event); $condition = $event->getCondition(); } @@ -288,4 +289,19 @@ protected function buildDefaultConditionNode(Form $form, ConditionNodeInterface } } } + + /** + * @param string|object $eventName + * @param string|object $event + * + * @return mixed + */ + protected function dispatch($eventName, $event) + { + if ($event instanceof ContractsEvent) { + return $this->dispatcher->dispatch($event, $eventName); + } else { + return $this->dispatcher->dispatch($eventName, $event); + } + } } From 49508c07f457e3bc5be4eaad690ac6a616b712ca Mon Sep 17 00:00:00 2001 From: Steve Nebes Date: Wed, 4 Sep 2019 19:17:38 -0500 Subject: [PATCH 3/7] Updated legacy identifying logic --- Event/ApplyFilterConditionEvent.php | 1 + Event/Event.php | 16 ---------------- Event/GetFilterConditionEvent.php | 1 + Event/PrepareEvent.php | 1 + Filter/FilterBuilderUpdater.php | 3 +-- 5 files changed, 4 insertions(+), 18 deletions(-) delete mode 100644 Event/Event.php diff --git a/Event/ApplyFilterConditionEvent.php b/Event/ApplyFilterConditionEvent.php index 0187fac..877a6c2 100644 --- a/Event/ApplyFilterConditionEvent.php +++ b/Event/ApplyFilterConditionEvent.php @@ -3,6 +3,7 @@ namespace Lexik\Bundle\FormFilterBundle\Event; use Lexik\Bundle\FormFilterBundle\Filter\Condition\ConditionBuilderInterface; +use Symfony\Contracts\EventDispatcher\Event; /** * Event class to compute the WHERE clause from the conditions. diff --git a/Event/Event.php b/Event/Event.php deleted file mode 100644 index 3c4b192..0000000 --- a/Event/Event.php +++ /dev/null @@ -1,16 +0,0 @@ - diff --git a/Event/PrepareEvent.php b/Event/PrepareEvent.php index a5f08fc..c80a248 100644 --- a/Event/PrepareEvent.php +++ b/Event/PrepareEvent.php @@ -3,6 +3,7 @@ namespace Lexik\Bundle\FormFilterBundle\Event; use Lexik\Bundle\FormFilterBundle\Filter\Query\QueryInterface; +use Symfony\Contracts\EventDispatcher\Event; /** * Get alias and expression builder for filter builder diff --git a/Filter/FilterBuilderUpdater.php b/Filter/FilterBuilderUpdater.php index ba4982c..1ab5959 100644 --- a/Filter/FilterBuilderUpdater.php +++ b/Filter/FilterBuilderUpdater.php @@ -6,7 +6,6 @@ use Symfony\Component\Form\Form; use Symfony\Component\Form\FormInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; -use Symfony\Contracts\EventDispatcher\Event as ContractsEvent; use Lexik\Bundle\FormFilterBundle\Filter\Condition\ConditionBuilder; use Lexik\Bundle\FormFilterBundle\Filter\Condition\ConditionBuilderInterface; use Lexik\Bundle\FormFilterBundle\Filter\Condition\ConditionInterface; @@ -298,7 +297,7 @@ protected function buildDefaultConditionNode(Form $form, ConditionNodeInterface */ protected function dispatch($eventName, $event) { - if ($event instanceof ContractsEvent) { + if ($this->dispatcher instanceof EventDispatcherInterface) { return $this->dispatcher->dispatch($event, $eventName); } else { return $this->dispatcher->dispatch($eventName, $event); From ad048051f888c63e472a63a203408f96d9826194 Mon Sep 17 00:00:00 2001 From: Steve Nebes Date: Wed, 4 Sep 2019 19:30:35 -0500 Subject: [PATCH 4/7] Updated legacy identifying logic --- Event/ApplyFilterConditionEvent.php | 1 - Event/Event.php | 16 ++++++++++++++++ Event/GetFilterConditionEvent.php | 1 - Event/PrepareEvent.php | 1 - 4 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 Event/Event.php diff --git a/Event/ApplyFilterConditionEvent.php b/Event/ApplyFilterConditionEvent.php index 877a6c2..0187fac 100644 --- a/Event/ApplyFilterConditionEvent.php +++ b/Event/ApplyFilterConditionEvent.php @@ -3,7 +3,6 @@ namespace Lexik\Bundle\FormFilterBundle\Event; use Lexik\Bundle\FormFilterBundle\Filter\Condition\ConditionBuilderInterface; -use Symfony\Contracts\EventDispatcher\Event; /** * Event class to compute the WHERE clause from the conditions. diff --git a/Event/Event.php b/Event/Event.php new file mode 100644 index 0000000..3c4b192 --- /dev/null +++ b/Event/Event.php @@ -0,0 +1,16 @@ + diff --git a/Event/PrepareEvent.php b/Event/PrepareEvent.php index c80a248..a5f08fc 100644 --- a/Event/PrepareEvent.php +++ b/Event/PrepareEvent.php @@ -3,7 +3,6 @@ namespace Lexik\Bundle\FormFilterBundle\Event; use Lexik\Bundle\FormFilterBundle\Filter\Query\QueryInterface; -use Symfony\Contracts\EventDispatcher\Event; /** * Get alias and expression builder for filter builder From f7dc809a24b12392bd5e40f4037c1b747131aad5 Mon Sep 17 00:00:00 2001 From: Steve Nebes Date: Wed, 4 Sep 2019 19:32:14 -0500 Subject: [PATCH 5/7] Updated legacy identifying logic --- Filter/FilterBuilderUpdater.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Filter/FilterBuilderUpdater.php b/Filter/FilterBuilderUpdater.php index 1ab5959..b0f9afd 100644 --- a/Filter/FilterBuilderUpdater.php +++ b/Filter/FilterBuilderUpdater.php @@ -290,16 +290,18 @@ protected function buildDefaultConditionNode(Form $form, ConditionNodeInterface } /** - * @param string|object $eventName - * @param string|object $event + * @param string $eventName + * @param object $event * * @return mixed */ protected function dispatch($eventName, $event) { if ($this->dispatcher instanceof EventDispatcherInterface) { + // Event dispatcher 4.3+ return $this->dispatcher->dispatch($event, $eventName); } else { + // Event dispatcher < 4.3 return $this->dispatcher->dispatch($eventName, $event); } } From 380113ef0e7019de3548daa280c4bf8e12632de1 Mon Sep 17 00:00:00 2001 From: Steve Nebes Date: Wed, 4 Sep 2019 19:47:18 -0500 Subject: [PATCH 6/7] Updated legacy identifying logic --- Filter/FilterBuilderUpdater.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Filter/FilterBuilderUpdater.php b/Filter/FilterBuilderUpdater.php index b0f9afd..549d401 100644 --- a/Filter/FilterBuilderUpdater.php +++ b/Filter/FilterBuilderUpdater.php @@ -298,11 +298,11 @@ protected function buildDefaultConditionNode(Form $form, ConditionNodeInterface protected function dispatch($eventName, $event) { if ($this->dispatcher instanceof EventDispatcherInterface) { - // Event dispatcher 4.3+ - return $this->dispatcher->dispatch($event, $eventName); - } else { // Event dispatcher < 4.3 return $this->dispatcher->dispatch($eventName, $event); + } else { + // Event dispatcher 4.3+ + return $this->dispatcher->dispatch($event, $eventName); } } } From 72f5b1a8e19c766e3a7391956ea0c0f5be8ca6e6 Mon Sep 17 00:00:00 2001 From: Steve Nebes Date: Wed, 4 Sep 2019 19:59:12 -0500 Subject: [PATCH 7/7] Updated legacy identifying logic --- Filter/FilterBuilderUpdater.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Filter/FilterBuilderUpdater.php b/Filter/FilterBuilderUpdater.php index 549d401..f852f81 100644 --- a/Filter/FilterBuilderUpdater.php +++ b/Filter/FilterBuilderUpdater.php @@ -6,6 +6,7 @@ use Symfony\Component\Form\Form; use Symfony\Component\Form\FormInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; +use Symfony\Contracts\EventDispatcher\EventDispatcherInterface as ContractsEventDispatcherInterface; use Lexik\Bundle\FormFilterBundle\Filter\Condition\ConditionBuilder; use Lexik\Bundle\FormFilterBundle\Filter\Condition\ConditionBuilderInterface; use Lexik\Bundle\FormFilterBundle\Filter\Condition\ConditionInterface; @@ -297,12 +298,12 @@ protected function buildDefaultConditionNode(Form $form, ConditionNodeInterface */ protected function dispatch($eventName, $event) { - if ($this->dispatcher instanceof EventDispatcherInterface) { - // Event dispatcher < 4.3 - return $this->dispatcher->dispatch($eventName, $event); - } else { + if ($this->dispatcher instanceof ContractsEventDispatcherInterface) { // Event dispatcher 4.3+ return $this->dispatcher->dispatch($event, $eventName); + } else { + // Event dispatcher < 4.3 + return $this->dispatcher->dispatch($eventName, $event); } } }