lockedAt = new \DateTime(); $this->expiresAt = new \DateTime('+30 minutes'); // Verrou expire après 30 minutes } public function getId(): ?int { return $this->id; } public function getEntityType(): ?string { return $this->entityType; } public function setEntityType(string $entityType): static { $this->entityType = $entityType; return $this; } public function getEntityId(): ?int { return $this->entityId; } public function setEntityId(int $entityId): static { $this->entityId = $entityId; return $this; } public function getUserId(): ?string { return $this->userId; } public function setUserId(string $userId): static { $this->userId = $userId; return $this; } public function getSessionId(): ?string { return $this->sessionId; } public function setSessionId(string $sessionId): static { $this->sessionId = $sessionId; return $this; } public function getLockedAt(): ?\DateTimeInterface { return $this->lockedAt; } public function setLockedAt(\DateTimeInterface $lockedAt): static { $this->lockedAt = $lockedAt; return $this; } public function getExpiresAt(): ?\DateTimeInterface { return $this->expiresAt; } public function setExpiresAt(\DateTimeInterface $expiresAt): static { $this->expiresAt = $expiresAt; return $this; } public function getUserAgent(): ?string { return $this->userAgent; } public function setUserAgent(?string $userAgent): static { $this->userAgent = $userAgent; return $this; } public function getIpAddress(): ?string { return $this->ipAddress; } public function setIpAddress(?string $ipAddress): static { $this->ipAddress = $ipAddress; return $this; } /** * Vérifie si le verrou est encore valide */ public function isValid(): bool { return $this->expiresAt > new \DateTime(); } /** * Vérifie si le verrou appartient à l'utilisateur */ public function belongsToUser(string $userId, string $sessionId): bool { return $this->userId === $userId && $this->sessionId === $sessionId; } /** * Prolonge le verrou */ public function extend(): static { $this->expiresAt = new \DateTime('+30 minutes'); return $this; } /** * Génère une clé unique pour l'entité */ public function getEntityKey(): string { return $this->entityType . '_' . $this->entityId; } public function __toString(): string { return sprintf( 'Verrou: %s #%d par %s', $this->entityType, $this->entityId, $this->userId ); } }