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; 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,21 @@ protected function buildDefaultConditionNode(Form $form, ConditionNodeInterface } } } + + /** + * @param string $eventName + * @param object $event + * + * @return mixed + */ + protected function dispatch($eventName, $event) + { + 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); + } + } }