1
0
mirror of synced 2025-01-09 02:37:09 +03:00
DeliveryModuleBundle/EventSubscriber/SerializeListener.php

28 lines
794 B
PHP
Raw Normal View History

2019-12-26 17:47:33 +03:00
<?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');
}
}
}