for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Dontdrinkandroot\Event\Listener;
use DateTime;
use Doctrine\ORM\Event\LifecycleEventArgs;
use Dontdrinkandroot\Entity\CreatedEntityInterface;
/**
* @author Philip Washington Sorst <[email protected]>
*/
class CreatedEntityListener
{
public function prePersist(LifecycleEventArgs $args): void
$entity = $args->getEntity();
if (is_a($entity, CreatedEntityInterface::class)) {
/** @var CreatedEntityInterface $createdEntity */
$createdEntity = $entity;
if (null === $createdEntity->getCreated()) {
$createdEntity->setCreated(new DateTime());
}