Skip to content

Commit ba487f8

Browse files
committed
sms: fixed ttl validation and added foreign_id validation
1 parent 6fba9ef commit ba487f8

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

src/Constant/SmsConstants.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ class SmsConstants {
88
'/[\d]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][\d]|3[0-1]) (2[0-3]|[01][\d]):[0-5][\d]/';
99
public const LABEL_MAX_LENGTH = 100;
1010
public const LABEL_PATTERN = "/[0-9a-z\-@_.]/i";
11+
public const FOREIGN_ID_MAX_LENGTH = 64;
12+
public const FOREIGN_ID_PATTERN = self::LABEL_PATTERN;
1113
public const FROM_ALPHANUMERIC_MAX = 11;
1214
public const FROM_NUMERIC_MAX = 16;
1315
public const FROM_ALLOWED_CHARS =
1416
['/', ' ', '.', '-', '@', '_', '!', '(', ')', '+', '$', ',', '&',];
1517
public const TEXT_MAX_LENGTH = 1520;
16-
public const TTL_MIN = 300000;
17-
public const TTL_MAX = 86400000;
18+
public const TTL_MIN = 1;
19+
public const TTL_MAX = PHP_INT_MAX;
1820
}

src/Validator/SmsValidator.php

+18
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public function validate(): void {
1818
$this->delay();
1919
$this->details();
2020
$this->flash();
21+
$this->foreign_id();
2122
$this->from();
2223
$this->json();
2324
$this->label();
@@ -88,6 +89,23 @@ public function flash(): void {
8889
}
8990
}
9091

92+
/** @throws InvalidOptionalArgumentException */
93+
public function foreign_id(): void {
94+
$label = $this->fallback('foreign_id');
95+
96+
if (null !== $label) {
97+
if (mb_strlen($label) > SmsConstants::FOREIGN_ID_MAX_LENGTH) {
98+
throw new InvalidOptionalArgumentException('foreign_id must not exceed "'
99+
. SmsConstants::LABEL_MAX_LENGTH . '" characters in length.');
100+
}
101+
102+
if (strlen($label) !== preg_match_all(SmsConstants::FOREIGN_ID_PATTERN, $label)) {
103+
throw new InvalidOptionalArgumentException(
104+
'foreign_id must match the regex pattern ' . SmsConstants::LABEL_PATTERN);
105+
}
106+
}
107+
}
108+
91109
/** @throws InvalidOptionalArgumentException */
92110
public function from(): void {
93111
$from = $this->fallback('from');

0 commit comments

Comments
 (0)