Add SMS bulk delay configuration and validate coupon phone function

This commit is contained in:
Mekan1206
2026-06-03 20:57:54 +05:00
parent 275ee63ffb
commit c74330cfaf
18 changed files with 1637 additions and 0 deletions

View File

@@ -0,0 +1,65 @@
<?php
namespace App\Services;
class SmsMessageAnalyzer
{
private const GSM_SINGLE_LIMIT = 160;
private const GSM_MULTI_LIMIT = 153;
private const UCS2_SINGLE_LIMIT = 70;
private const UCS2_MULTI_LIMIT = 67;
public function characterCount(string $message): int
{
return mb_strlen($message);
}
public function isGsm7(string $message): bool
{
if ($message === '') {
return true;
}
return ! preg_match('/[^\x00-\x7F]/', $message);
}
public function estimatedParts(string $message): int
{
$length = $this->characterCount($message);
if ($length === 0) {
return 0;
}
if ($this->isGsm7($message)) {
if ($length <= self::GSM_SINGLE_LIMIT) {
return 1;
}
return (int) ceil($length / self::GSM_MULTI_LIMIT);
}
if ($length <= self::UCS2_SINGLE_LIMIT) {
return 1;
}
return (int) ceil($length / self::UCS2_MULTI_LIMIT);
}
public function summary(string $message): string
{
$characters = $this->characterCount($message);
$parts = $this->estimatedParts($message);
if ($parts === 0) {
return '0 characters';
}
$partLabel = $parts === 1 ? '1 SMS' : "{$parts} SMS";
return "{$characters} characters · {$partLabel}";
}
}