Entity Website : - customer (ManyToOne, CASCADE) : client propriétaire - name : nom du site - uuid : UUID v4 auto-généré (unique, 36 chars) - type : vitrine | ecommerce - state : created → install_progress → open → suspended → closed - createdAt / updatedAt (auto sur setState) - isOpen() : vérifie si state === open WebsiteTest (5 tests, 20 assertions) : - testConstructor : valeurs par défaut, uuid 36 chars, type vitrine - testConstructorEcommerce : type ecommerce - testSetters : name, type, updatedAt - testState : transitions created→install_progress→open→suspended→closed - testUuidUnique : 2 sites ont des uuid différents Dépendance : symfony/uid ajouté pour Uuid::v4() Migration : CREATE TABLE website avec FK customer, uuid unique Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
130 lines
2.7 KiB
PHP
130 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace App\Entity;
|
|
|
|
use Doctrine\ORM\Mapping as ORM;
|
|
use Symfony\Component\Uid\Uuid;
|
|
|
|
#[ORM\Entity]
|
|
class Website
|
|
{
|
|
public const TYPE_VITRINE = 'vitrine';
|
|
public const TYPE_ECOMMERCE = 'ecommerce';
|
|
|
|
public const STATE_CREATED = 'created';
|
|
public const STATE_INSTALL_PROGRESS = 'install_progress';
|
|
public const STATE_OPEN = 'open';
|
|
public const STATE_SUSPENDED = 'suspended';
|
|
public const STATE_CLOSED = 'closed';
|
|
|
|
#[ORM\Id]
|
|
#[ORM\GeneratedValue]
|
|
#[ORM\Column]
|
|
private ?int $id = null;
|
|
|
|
#[ORM\ManyToOne(targetEntity: Customer::class)]
|
|
#[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
|
|
private Customer $customer;
|
|
|
|
#[ORM\Column(length: 255)]
|
|
private string $name;
|
|
|
|
#[ORM\Column(length: 36, unique: true)]
|
|
private string $uuid;
|
|
|
|
#[ORM\Column(length: 20)]
|
|
private string $type;
|
|
|
|
#[ORM\Column(length: 20)]
|
|
private string $state = self::STATE_CREATED;
|
|
|
|
#[ORM\Column]
|
|
private \DateTimeImmutable $createdAt;
|
|
|
|
#[ORM\Column(nullable: true)]
|
|
private ?\DateTimeImmutable $updatedAt = null;
|
|
|
|
public function __construct(Customer $customer, string $name, string $type = self::TYPE_VITRINE)
|
|
{
|
|
$this->customer = $customer;
|
|
$this->name = $name;
|
|
$this->type = $type;
|
|
$this->uuid = Uuid::v4()->toRfc4122();
|
|
$this->createdAt = new \DateTimeImmutable();
|
|
}
|
|
|
|
public function getId(): ?int
|
|
{
|
|
return $this->id;
|
|
}
|
|
|
|
public function getCustomer(): Customer
|
|
{
|
|
return $this->customer;
|
|
}
|
|
|
|
public function getName(): string
|
|
{
|
|
return $this->name;
|
|
}
|
|
|
|
public function setName(string $name): static
|
|
{
|
|
$this->name = $name;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getUuid(): string
|
|
{
|
|
return $this->uuid;
|
|
}
|
|
|
|
public function getType(): string
|
|
{
|
|
return $this->type;
|
|
}
|
|
|
|
public function setType(string $type): static
|
|
{
|
|
$this->type = $type;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getState(): string
|
|
{
|
|
return $this->state;
|
|
}
|
|
|
|
public function setState(string $state): static
|
|
{
|
|
$this->state = $state;
|
|
$this->updatedAt = new \DateTimeImmutable();
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function isOpen(): bool
|
|
{
|
|
return self::STATE_OPEN === $this->state;
|
|
}
|
|
|
|
public function getCreatedAt(): \DateTimeImmutable
|
|
{
|
|
return $this->createdAt;
|
|
}
|
|
|
|
public function getUpdatedAt(): ?\DateTimeImmutable
|
|
{
|
|
return $this->updatedAt;
|
|
}
|
|
|
|
public function setUpdatedAt(?\DateTimeImmutable $updatedAt): static
|
|
{
|
|
$this->updatedAt = $updatedAt;
|
|
|
|
return $this;
|
|
}
|
|
}
|