for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Zenstruck\Foundry\Tests\Fixtures\Event;
use Doctrine\Bundle\DoctrineBundle\EventSubscriber\EventSubscriberInterface;
use Doctrine\ORM\Event\LifecycleEventArgs;
use Doctrine\ORM\Events;
use Zenstruck\Foundry\Tests\Fixtures\Entity\Comment;
class CommentEventSubscriber implements EventSubscriberInterface
{
public const COMMENT_BODY = 'test-event';
public const NEW_COMMENT_BODY = 'new body';
public function getSubscribedEvents(): array
return [Events::postPersist];
}
public function postPersist(LifecycleEventArgs $event): void
if (
!$event->getObject() instanceof Comment
|| $event->getObject()->getBody() !== self::COMMENT_BODY
) {
return;
$event->getObject()->setBody(self::NEW_COMMENT_BODY);
$event->getEntityManager()->flush();