📜 ⬆️ ⬇️

How to make friends JMS Serializer and LiipImagineBundle

I am currently writing a front-end API for AngularJS. For this, I use the standard symfony bundle:


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

Just want to say that I am clearly not a fan of JMSSerializerBundle, since the project is not actively supported, which gives some limitations when working with it + it is not written entirely with regard to performance. Symfony Serializer will be better, but life is not so simple)
')
Also please note that the API is scheduled to be open and links to the thumb should be sent in the answer. Just write in the dock, use the url http://example.com/resolver/filter/image/name.jpg for getting the thumb is not suitable, and not beautiful as that)

Let's return to the topic. Realizing that you need to write your bike, I started writing it. Since the project for which he needed was not a small one had to be done so that a different configuration would be supported. For example, the picture may have several filters and may not be. Since I use to load everything onto the VichUploaderBundle server, I had to generate links, considering that the field being serialized could be the field of this bundle.

In JMSSerializerBundle there are two events that are raised when serializing the object serializer.pre_serialize and serializer.post_serialize that I used.


The documentation on using bundla and the bundle itself are on the GitHub LiipImagineSerializationBundle .

Source: https://habr.com/ru/post/279043/


All Articles