Files
trafficpumper/app/Services/KeywordPhraseNormalizer.php
T
2026-08-29 15:53:53 +03:00

13 lines
702 B
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace App\Services;
use InvalidArgumentException;
final class KeywordPhraseNormalizer {
public function normalize(string $input):array {
if(preg_match('/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/u',$input)) throw new InvalidArgumentException('Anahtar kelime kontrol karakteri içeremez.');
$phrase=preg_replace('/\s+/u',' ',trim($input))??'';
if($phrase==='') throw new InvalidArgumentException('Anahtar kelime zorunludur.');
if(mb_strlen($phrase,'UTF-8')>190) throw new InvalidArgumentException('Anahtar kelime 190 karakterden uzun olamaz.');
$normalized=mb_strtolower(str_replace(['I','İ'],['ı','i'],$phrase),'UTF-8');
return ['phrase'=>$phrase,'normalized_phrase'=>$normalized];
}
}