Files
zyt/server/app/common/service/pharmacy/PharmacyLogisticsValue.php
T
2026-07-22 14:50:34 +08:00

28 lines
741 B
PHP

<?php
declare(strict_types=1);
namespace app\common\service\pharmacy;
use InvalidArgumentException;
final class PharmacyLogisticsValue
{
public static function normalize(mixed $value, int $maxLength, string $label): string
{
$normalized = preg_replace(
'/^[\s\p{Z}\x{200B}\x{2060}\x{FEFF}]+|[\s\p{Z}\x{200B}\x{2060}\x{FEFF}]+$/u',
'',
(string) $value
);
if ($normalized === null) {
throw new InvalidArgumentException($label . '格式无效');
}
if (mb_strlen($normalized) > $maxLength) {
throw new InvalidArgumentException($label . '长度不能超过' . $maxLength . '个字符');
}
return $normalized;
}
}