first commit
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user