26 lines
566 B
PHP
26 lines
566 B
PHP
<?php
|
|
|
|
namespace app\common\service\doctor;
|
|
|
|
use Overtrue\Pinyin\Pinyin;
|
|
|
|
/**
|
|
* 药材名称 → 拼音首字母连写(小写),供列表检索;未安装 overtrue/pinyin 时返回空字符串。
|
|
*/
|
|
class MedicineNameAbbrService
|
|
{
|
|
public static function build(string $name): string
|
|
{
|
|
$name = trim($name);
|
|
if ($name === '') {
|
|
return '';
|
|
}
|
|
if (!class_exists(Pinyin::class)) {
|
|
return '';
|
|
}
|
|
$abbr = (string) Pinyin::abbr($name)->join('');
|
|
|
|
return strtolower($abbr);
|
|
}
|
|
}
|