Create snippets skeleton

This commit is contained in:
Tim
2023-04-03 23:44:13 +02:00
parent bf83e5aabd
commit 921dcf1e97
15 changed files with 310 additions and 30 deletions

View File

View File

@@ -1,20 +0,0 @@
<?php
namespace App\Entity;
use App\Repository\EmailRepository;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: EmailRepository::class)]
class Email
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
public function getId(): ?int
{
return $this->id;
}
}

View File

@@ -0,0 +1,22 @@
<?php
namespace App\Entity\Helpers;
use Doctrine\ORM\Mapping as ORM;
trait EnableableTrait
{
#[ORM\Column(options: ['default' => true])]
private bool $enabled = true;
public function isEnabled(): bool
{
return $this->enabled;
}
public function setEnabled(bool $enabled): static
{
$this->enabled = $enabled;
return $this;
}
}

View File

@@ -0,0 +1,54 @@
<?php
namespace App\Entity\Helpers;
use App\Entity\User;
use DateTime;
use Doctrine\ORM\Mapping as ORM;
trait TrackedTrait
{
#[ORM\Column]
#[ORM\JoinColumn(nullable: false)]
private ?DateTime $createdAt = null;
#[ORM\ManyToOne]
#[ORM\JoinColumn(nullable: false)]
private ?User $createdBy = null;
public function getCreatedBy(): ?User
{
return $this->createdBy;
}
public function setCreatedBy(?User $createdBy): self
{
$this->createdBy = $createdBy;
return $this;
}
public function getCreatedAt(): ?DateTime
{
return $this->createdAt;
}
public function setCreatedAt(DateTime $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getCode(): string
{
return date_format($this->createdAt, "ymd");
}
public function setCreatedAtTodayNoSeconds(): self
{
$this->setCreatedAt(DateTime::createFromFormat('Y-m-d H:i', date('Y-m-d H:i')));
return $this;
}
}

38
src/Entity/Snip.php Normal file
View File

@@ -0,0 +1,38 @@
<?php
namespace App\Entity;
use App\Entity\Helpers\TrackedTrait;
use App\Repository\SnipRepository;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: SnipRepository::class)]
class Snip
{
use TrackedTrait;
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 255)]
private ?string $name = null;
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
}