1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55:
<?php
namespace ApiBundle\EventListener\Doctrine;
use ApiBundle\Entity\Mandate;
use ApiBundle\Manager\NonPersistentEntityManagerInterface;
use Doctrine\ORM\Event\LifecycleEventArgs;
use Doctrine\ORM\Event\PreFlushEventArgs;
class MandateListener
{
private $manager;
public function __construct(NonPersistentEntityManagerInterface $manager)
{
if (false === $manager->supports(Mandate::class)) {
throw new \InvalidArgumentException(
sprintf('The manager %s does not support %s objects.', get_class($manager), Mandate::class)
);
}
$this->manager = $manager;
}
public function preFlush(Mandate $mandate, PreFlushEventArgs $args)
{
$this->manager->update($mandate);
}
public function preRemove(Mandate $mandate, LifecycleEventArgs $event)
{
$this->manager->remove($mandate);
}
}