我需要在Symfony 2上为我的网站实现RESTful API,因此我使用了FOSRestBundle和JMSSerializerBundle
这是我为实体编写的序列化器yml:
Acme\DemoBundle\Entity\Product:
exclusion_policy: ALL
accessor_order: custom
custom_accessor_order: [id, title]
properties:
id:
expose: true
title:
expose: true
virtual_properties:
getMainPhoto:
serialized_name: photo
问题在于
getMainPhoto
返回的是完整大小的图片url。我想在向API客户端发送响应之前对此URL进行预处理,以便我可以生成所需图像的调整大小版本的新URL。我已经在SF2中有一个可以完成此任务的服务:$resized_url = $someService->generateResizedUrl($item->getMainPhoto(), 640, 480);
但我不知道如何在JMSSerializer中使用此服务。也许有一些回调函数可以用于FOSRestBundle\JMSSerializerBundle,在它发送响应之前运行?