<?php
# src/Entity/MyExpirableEntity.php
namespace App\Entity;
use Cloudstek\DoctrineBehaviour\ExpirableInterface;
use Cloudstek\DoctrineBehaviour\ExpirableTrait;
class MyExpirableEntity implements ExpirableInterface
{
use ExpirableTrait;
// ... Your entity code here.
}
<?php
# src/MyClass.php
namespace App;
use App\Entity\MyExpirableEntity;
class MyClass
{
// ...
function doWhatever() {
$em = $this->getEntityManager();
$entity = new MyExpirableEntity();
// Let the entity expire in 1 hour from now.
$entity->setExpiresIn('1h');
$em->persist($entity);
$em->flush();
}
}