input = $this->normalize($input); $this->identifierType = $identifierType; $this->brand = $this->normalize($brand); $this->manufacturer = $this->normalize($manufacturer); $this->categoryHints = array_values(array_filter(array_map([$this, 'normalize'], $categoryHints))); } public static function fromContext(DomainContext $context, string $identifierType): self { $metadata = $context->getMetadata(); $categories = $metadata['category_hints'] ?? $metadata['categories'] ?? $metadata['category'] ?? []; return new self( $context->getInput(), $identifierType, (string) ($metadata['brand'] ?? ''), (string) ($metadata['manufacturer'] ?? ''), is_array($categories) ? $categories : [(string) $categories] ); } public function getInput(): string { return $this->input; } public function getIdentifierType(): string { return $this->identifierType; } public function getBrand(): string { return $this->brand; } public function getManufacturer(): string { return $this->manufacturer; } public function getCategoryHints(): array { return $this->categoryHints; } private function normalize(string $value): string { $normalized = strtolower(trim($value)); return preg_replace('/\s+/', ' ', $normalized) ?? $normalized; } }