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
DMS-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.

How to make JMS Serializer and LiipImagine works together

API json

I’m working on writing the API for the front-end on AngularJS. To do this, I use the standard bundles set for Symfony:

FOSRestBundle
JMSSerializerBundle
NelmioApiDocBundle

I had a task to give a reference to thumb and preview in objects that contain pictures. I have already used in the code LiipImagineBundle and for generating links in api also wanted to use this bundle. After a search for the right solution to me, I was surprised that there are no ready-made bundle for this.

Just want to say that I am obviously not a fan of JMSSerializerBundle, as the project is not actively supported giving some limitations when working with it. Symfony Serializer will be better, but life is not so simple) Also, please note that the API, what I write, is scheduled to be open, so it have to be simple for understanding.

Let us return to the subject. Realizing that I need to write my bike I started writing it) As the project for which it was needed not a little, I had to support different configurations. For example the picture may have several filters or one. Since I use to upload data on server VichUploaderBundle, I need make the support of generation links given by this bundle.

In JMSSerializerBundle there are two events that are invoked when the object serializing:

  • serializer.pre_serialize used if we need to change some information in the object. For example in object are picture field with reference to the original picture, and you need to change field data to thumb url.
  • serializer.post_serialize used if you want to add additional information to the  serialized object. For example there are a field image with a link to the original image and it can not be overwritten because it is already used somewhere then we can add a new field image_thumb for example, and put in it a reference to the thumb.

Documentation and bundle are on GitHub LiipImagineSerializationBundle.

Working with HelloSign in Symfony

Hellosign logo

I use HelloSign api on current project. They have PHP sdk but haven’t Symfony bundle.

So at first I use their sdk without symfony integration but in this way you not have dependency injection and working with login parameters not so comfortable. Thats why I decided write wrapper for their SDK.

Documentation and HelloSignBundle at Github.