createdAt = new \DateTimeImmutable(); $this->relevance = Confidence::medium(); } // Getters public function getId(): ?int { return $this->id; } public function getEntityId(): int { return $this->entityId; } public function getTaxonomyTermId(): int { return $this->taxonomyTermId; } public function getRelevance(): Confidence { return $this->relevance; } public function isValidated(): bool { return $this->validated; } public function getCreatedAt(): \DateTimeImmutable { return $this->createdAt; } public function getUpdatedAt(): ?\DateTimeImmutable { return $this->updatedAt; } // Setters public function setId(int $id): self { $this->id = $id; return $this; } public function setEntityId(int $entityId): self { $this->entityId = $entityId; return $this; } public function setTaxonomyTermId(int $taxonomyTermId): self { $this->taxonomyTermId = $taxonomyTermId; return $this; } public function setRelevance(Confidence $relevance): self { $this->relevance = $relevance; $this->touch(); return $this; } public function setRelevanceFromFloat(float $value): self { $this->relevance = Confidence::fromFloat($value); $this->touch(); return $this; } public function setValidated(bool $validated): self { $this->validated = $validated; $this->touch(); return $this; } public function setCreatedAt(\DateTimeImmutable $createdAt): self { $this->createdAt = $createdAt; return $this; } public function setUpdatedAt(?\DateTimeImmutable $updatedAt): self { $this->updatedAt = $updatedAt; return $this; } // Domain Methods public function validate(): self { $this->validated = true; $this->touch(); return $this; } public function invalidate(): self { $this->validated = false; $this->touch(); return $this; } private function touch(): void { $this->updatedAt = new \DateTimeImmutable(); } public function toArray(): array { return [ 'id' => $this->id, 'entity_id' => $this->entityId, 'taxonomy_term_id' => $this->taxonomyTermId, 'relevance' => $this->relevance->value(), 'validated' => $this->validated ? 1 : 0, 'created_at' => $this->createdAt->format('Y-m-d H:i:s'), 'updated_at' => $this->updatedAt?->format('Y-m-d H:i:s'), ]; } public static function fromArray(array $data): self { $mapping = new self(); if (isset($data['id'])) { $mapping->setId((int) $data['id']); } if (isset($data['entity_id'])) { $mapping->setEntityId((int) $data['entity_id']); } if (isset($data['taxonomy_term_id'])) { $mapping->setTaxonomyTermId((int) $data['taxonomy_term_id']); } if (isset($data['relevance'])) { $mapping->relevance = Confidence::fromFloat((float) $data['relevance']); } if (isset($data['validated'])) { $mapping->validated = (bool) $data['validated']; } if (isset($data['created_at'])) { $mapping->setCreatedAt(new \DateTimeImmutable($data['created_at'])); } if (isset($data['updated_at']) && $data['updated_at'] !== null) { $mapping->setUpdatedAt(new \DateTimeImmutable($data['updated_at'])); } return $mapping; } }