'PLA Base', 'petg' => 'PET(G) Base', 'abs' => 'ABS Base', 'asa' => 'ASA Base', 'pa' => 'PA Base', 'pc' => 'PC Base', 'tpu' => 'TPU Base', 'peba' => 'PEBA Base', 'other' => 'Other', ]; private const APPLICATION_OPTIONS = [ 'plus' => 'Plus Series', 'basic' => 'Basic Series', 'high_speed' => 'High Speed Series', 'flexible' => 'Flexible Series', 'high_elasticity' => 'High Elasticity Series', 'recycled' => 'Recycled Series', 'matte' => 'Matte Series', 'silk' => 'Silk Series', 'luminous' => 'Luminous Series', 'sparkle' => 'Sparkle Series', 'bionic' => 'Bionic Series', 'color_change' => 'Color Change Series', 'transparent' => 'Transparent Series', 'carbon_fiber' => 'Carbon Fiber', 'glass_fiber' => 'Glass Fiber', 'lightweight' => 'Lightweight', 'antistatic' => 'Antistatic', 'conductive' => 'Conductive', 'heat_resistant' => 'Heat Resistant', 'flame_retardant' => 'Flame Retardant', 'support' => 'Support Material', 'general_engineering' => 'General Engineering', 'special_engineering' => 'Special Engineering', 'other' => 'Other Series', ]; public function cleanName(string $name): string { $name = (string) preg_replace('/[\x{00A0}\x{2000}-\x{200B}\x{202F}\x{205F}\x{3000}]/u', ' ', $name); return trim((string) preg_replace('/\s+/u', ' ', $name)); } /** * @return array{base: string, applications: string[]} */ public function classify(string $rawName): array { $name = $this->cleanName($rawName); $base = $this->detectBase($name); $applications = []; $this->addWhen($applications, 'plus', str_contains($name, '+')); $this->addWhen($applications, 'basic', (bool) preg_match('/Basic|PLA-SS|PLA-Lite/i', $name)); $this->addWhen($applications, 'high_speed', (bool) preg_match('/(?:^|[-+ ])(?:HS|HF)(?:$|[-+ (])/i', $name)); $this->addWhen($applications, 'flexible', in_array($base, ['tpu', 'peba'], true) || (bool) preg_match('/TPE|Flex/i', $name)); $this->addWhen($applications, 'high_elasticity', $base === 'peba' || (bool) preg_match('/^4D(?:-|$)/i', $name)); $this->addWhen($applications, 'recycled', (bool) preg_match('/Revive/i', $name)); $this->addWhen($applications, 'matte', (bool) preg_match('/Matte|^Mate$/i', $name)); $this->addWhen($applications, 'silk', (bool) preg_match('/Silk/i', $name)); $this->addWhen($applications, 'luminous', (bool) preg_match('/Luminous/i', $name)); $this->addWhen($applications, 'sparkle', (bool) preg_match('/Twinkling|Stars/i', $name)); $this->addWhen($applications, 'bionic', (bool) preg_match('/Rock|Marble|Wood|Coffee|Nature/i', $name)); $this->addWhen($applications, 'color_change', (bool) preg_match('/Color Change|Chameleon/i', $name)); $this->addWhen($applications, 'transparent', (bool) preg_match('/Clear|Transparent/i', $name)); $this->addWhen($applications, 'carbon_fiber', (bool) preg_match('/(?:^|[-+])CF(?:$|[-+ ])/i', $name)); $this->addWhen($applications, 'glass_fiber', (bool) preg_match('/(?:^|[-+])(?:GF|GK)(?:$|[-+ ])/i', $name)); $this->addWhen($applications, 'lightweight', (bool) preg_match('/(?:^|-)LW(?:$|\()/i', $name)); $this->addWhen($applications, 'antistatic', (bool) preg_match('/(?:^|-)ESD(?:$|-)/i', $name)); $this->addWhen($applications, 'conductive', (bool) preg_match('/Conduct/i', $name)); $this->addWhen($applications, 'heat_resistant', (bool) preg_match('/(?:^|-)HT(?:$|-)|PEEK|PPS/i', $name)); $this->addWhen($applications, 'flame_retardant', (bool) preg_match('/(?:^|-)FR(?:$|-)/i', $name)); $this->addWhen($applications, 'support', (bool) preg_match('/PVA|HIPS|^Clean$/i', $name)); $this->addWhen($applications, 'general_engineering', in_array($base, ['petg', 'abs', 'asa', 'pa', 'pc'], true)); $this->addWhen($applications, 'special_engineering', (bool) preg_match('/PEEK|PPS/i', $name)); if (!$applications) { $applications[] = 'other'; } return ['base' => $base, 'applications' => $applications]; } public function getBaseOptions(): array { return self::BASE_OPTIONS; } public function getApplicationOptions(): array { return self::APPLICATION_OPTIONS; } private function detectBase(string $name): string { if (preg_match('/PLA/i', $name)) { return 'pla'; } if (preg_match('/PETG|(?:^|[^A-Z])PET(?:[^A-Z]|$)/i', $name)) { return 'petg'; } if (preg_match('/ABS/i', $name)) { return 'abs'; } if (preg_match('/ASA/i', $name)) { return 'asa'; } if (preg_match('/(?:^|[^A-Z])PA(?:12|HT)?(?:[^A-Z]|$)/i', $name)) { return 'pa'; } if (preg_match('/(?:^|[^A-Z])PC(?:[^A-Z]|$)/i', $name)) { return 'pc'; } if (preg_match('/TPU/i', $name)) { return 'tpu'; } if (preg_match('/PEBA/i', $name)) { return 'peba'; } return 'other'; } private function addWhen(array &$applications, string $value, bool $condition): void { if ($condition) { $applications[] = $value; } } }