<?php
namespace App\Entity;
use App\Utility\DateTimeUtility;
use DateTime;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
*
* @ORM\Table(
* name="locks"
* )
*/
class Lock
{
public function __construct(string $id, DateTime $createdAt, DateTime $validUntil, ?string $info = null)
{
$this->id = $id;
$this->hashedId = md5($id);
$this->createdAt = $createdAt;
$this->validUntil = $validUntil;
$this->info = $info;
}
/**
* @var string
*
* @ORM\Column(name="id", type="string", length=512)
*
* @ORM\Id
*/
protected $id;
public function getId()
{
return $this->id;
}
/**
* It can be hard to manually query for ids in certain cases, thus we add a hashedId that helps with this.
*
* @var string
*
* @ORM\Column(name="hashed_id", type="string", length=32, nullable=true)
*/
protected $hashedId;
/**
* @var DateTime
*
* @ORM\Column(name="created_at", type="datetime", nullable=false)
*/
protected $createdAt;
public function getCreatedAt(): DateTime
{
return $this->createdAt;
}
/**
* @var DateTime
*
* @ORM\Column(name="valid_until", type="datetime", nullable=false)
*/
protected $validUntil;
public function getValidUntil(): DateTime
{
return $this->validUntil;
}
public function isValid(): bool
{
return $this->getValidUntil() > DateTimeUtility::createDateTimeUtc();
}
public function setValidUntil(DateTime $validUntil): void
{
$this->validUntil = $validUntil;
}
/**
* @var ?string
*
* @ORM\Column(name="info", type="text", length=8192, nullable=true)
*/
protected $info;
public function getInfo(): ?string
{
return $this->info;
}
public function setInfo(?string $info): void
{
$this->info = $info;
}
}