13 lines
702 B
PHP
13 lines
702 B
PHP
<?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];
|
|||
|
|
}
|
|||
|
|
}
|