-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add the ability to set a custom mobile validation class in configs
- Loading branch information
1 parent
084ea99
commit 9ca5de5
Showing
6 changed files
with
100 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,42 @@ | ||
<?php | ||
|
||
use Salehhashemi\OtpManager\Validators\DefaultMobileValidator; | ||
|
||
return [ | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| OTP Waiting Time | ||
|-------------------------------------------------------------------------- | ||
| | ||
| This option defines the number of seconds a user has to wait before | ||
| being allowed to request a new OTP. Set it to a reasonable value | ||
| to prevent abuse. | ||
| | ||
*/ | ||
'waiting_time' => 120, | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| OTP Code Range | ||
|-------------------------------------------------------------------------- | ||
| | ||
| These options define the minimum and maximum range for the generated | ||
| OTP codes. Adjust these values as per your security requirements. | ||
| | ||
*/ | ||
'code_min' => 111111, | ||
'code_max' => 999999, | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Mobile Validation Class | ||
|-------------------------------------------------------------------------- | ||
| | ||
| This option defines the class responsible for validating mobile numbers. | ||
| If you want to use your own validation logic, you can create your | ||
| own class and replace the class name here. | ||
| | ||
*/ | ||
'mobile_validation_class' => DefaultMobileValidator::class, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
namespace Salehhashemi\OtpManager\Contracts; | ||
|
||
interface MobileValidatorInterface | ||
{ | ||
/** | ||
* Validates the provided mobile number. | ||
* | ||
* @param string $mobile The mobile number to validate. | ||
* @return void | ||
* | ||
* @throws \InvalidArgumentException If the mobile number is empty. | ||
*/ | ||
public function validate(string $mobile): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace Salehhashemi\OtpManager\Validators; | ||
|
||
use Salehhashemi\OtpManager\Contracts\MobileValidatorInterface; | ||
|
||
class DefaultMobileValidator implements MobileValidatorInterface | ||
{ | ||
/** | ||
* @inheritdoc | ||
*/ | ||
public function validate(string $mobile): void | ||
{ | ||
if (empty($mobile)) { | ||
throw new \InvalidArgumentException('Mobile number cannot be empty.'); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters