<?php
namespace App\Package\Admin\Tools\EventSubscriber\EntityUpdateSubscriber;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use App\Package\Admin\Main\Event\EntityUpdateEvent;
/**
* EntityUpdateSubscriber
*
* Subscriber which listens for entity update event (created or updated)
* - if entity has "dispatchEntityUpdateEvent" function then calls it
*
* @author Daniel Balowski <d.balowski@openform.pl> (_creator)
* @copyright Openform
* @since 03.2019
*/
class EntityUpdateSubscriber implements EventSubscriberInterface
{
/**
* @return array
*/
public static function getSubscribedEvents() : array
{
return [
EntityUpdateEvent::NAME => [
[ 'onEntityUpdate', 1000 ],
]
];
}
/**
* On entity update event
*
* @param EntityUpdateEvent $entity
*
* @return void
*/
public function onEntityUpdate(EntityUpdateEvent $event)
{
$entity = $event->getUpdatedEntity();
if (method_exists($entity, 'dispatchEntityUpdateEvent')) {
$entity->dispatchEntityUpdateEvent();
}
return;
}
}