1
0
mirror of synced 2025-01-08 10:27:09 +03:00
DeliveryModuleBundle/EventSubscriber/SerializeListener.php
2020-02-19 19:00:09 +03:00

28 lines
794 B
PHP

<?php
namespace RetailCrm\DeliveryModuleBundle\EventSubscriber;
use JMS\Serializer\EventDispatcher\Events;
use JMS\Serializer\EventDispatcher\EventSubscriberInterface;
use JMS\Serializer\EventDispatcher\PreSerializeEvent;
use RetailCrm\DeliveryModuleBundle\Model\ResponseResult;
class SerializeListener implements EventSubscriberInterface
{
public static function getSubscribedEvents()
{
return [
['event' => Events::PRE_SERIALIZE, 'method' => 'onPreSerialize', 'class' => ResponseResult::class],
];
}
public function onPreSerialize(PreSerializeEvent $event)
{
if (is_object($event->getObject())) {
$event->setType(get_class($event->getObject()));
} else {
$event->setType('string');
}
}
}