add SMSpanel
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\SmsBilling;
|
||||
|
||||
class SmsSegmentCalculator
|
||||
{
|
||||
private const PERSIAN_LIMITS = [70, 64, 67];
|
||||
|
||||
public function countParts(string $text): int
|
||||
{
|
||||
$length = mb_strlen(trim($text), 'UTF-8');
|
||||
|
||||
if ($length <= 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
$first = self::PERSIAN_LIMITS[0];
|
||||
$second = self::PERSIAN_LIMITS[1];
|
||||
$rest = self::PERSIAN_LIMITS[2];
|
||||
|
||||
if ($length <= $first) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ($length <= $first + $second) {
|
||||
return 2;
|
||||
}
|
||||
|
||||
$thirdThreshold = $first + $second + $rest;
|
||||
|
||||
if ($length <= $thirdThreshold) {
|
||||
return 3;
|
||||
}
|
||||
|
||||
return 3 + (int) ceil(($length - $thirdThreshold) / $rest);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user