Filtering data in Symfony

Data filter

All lovers of Symfony knows that it does not have a filter component.
There are wonderful and comfortable Constraints and even was an attempt to create a filter component with same logic (issue filters on Github), but no one took to do it.

When I once again faced with the task of filtering large amounts of data from a user, I realized that it is time to solve the problem of how to filter data more global/nice/comfortable.

After some research, I realized that there is nothing fundamentally new in filtering on php. There are 2 popular components:

Zend Filter

Please note that the last one is not very well supported by the author.
There symfony bundle for DMS-Filter but it is not compatible with the Symfony 3.  I did not like the code for DMS-Filter. I understand that can do everything a little easier.

After analyzing the situation, I realized that the fastest and most reliable way to write a filter bundle, are using the well-documented and test coverage filters -Zend Filters. Just want to add, that in the past, I have worked with Zend Framework 1 and this component was close and clear for me.

I wanted to make the logic of the filters similarly to Symfony Constraints.
The result was written bundle, which adds a service that can be used to filter the object based on the annotations. Also, bundle can filter form object if it is annotated.

Documentation that I used at the time of writing this bundle:

How to Create a Form Type Extension
Form Events
How to Dynamically Modify Forms Using Form Events
How to Register Event Listeners and Subscribers
Documentation and bundle can be found on GitHub FilterBundle.

Leave a Reply

Your email address will not be published. Required fields are marked *