-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from yondifon/add_camtel_support
Camtel Support fixes #2
- Loading branch information
Showing
2 changed files
with
59 additions
and
32 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 |
---|---|---|
|
@@ -2,37 +2,40 @@ | |
|
||
/** | ||
* @author Malico <[email protected]> | ||
* | ||
*/ | ||
|
||
namespace Malico\MobileCM; | ||
|
||
/** | ||
* Network | ||
* Network. | ||
*/ | ||
class Network | ||
{ | ||
/** | ||
* Country Prefix | ||
* Country Prefix. | ||
*/ | ||
const PREFIX = '237'; | ||
|
||
/** | ||
* Operator Prefixes | ||
* Operator Prefixes. | ||
*/ | ||
const OPERATOR_PREFIXES = [ | ||
'mtn' => [ | ||
67, 650, 651, 652, 653, 654, 680, 681, 682, 683 | ||
67, 650, 651, 652, 653, 654, 680, 681, 682, 683, | ||
], | ||
'orange' => [ | ||
69, 655, 656, 657, 658, 659 | ||
69, 655, 656, 657, 658, 659, | ||
], | ||
'nexttel' => [ | ||
66 | ||
] | ||
66, | ||
], | ||
'camtel' => [ | ||
'233', '222', '242', '243', | ||
], | ||
]; | ||
|
||
/** | ||
* Check if phone is valid length | ||
* Check if phone is valid length. | ||
* | ||
* @param string|int $tel | ||
* | ||
|
@@ -42,81 +45,95 @@ protected static function validLength($tel) : bool | |
{ | ||
$len = strlen($tel); | ||
|
||
if ($len == 9 || $len == 12 || $len = 13 || $len == 14) { | ||
if ($len == 9 || $len == 12 || $len = 13 || $len == 14) { | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
/** | ||
* Match Tel to Prefix | ||
* Match Tel to Prefix. | ||
* | ||
* @param string|int $tel | ||
* @param string $key | ||
* | ||
* @return bool | ||
*/ | ||
protected static function checkNumber($tel, $key) | ||
protected static function checkNumber(string | int $tel, $key) | ||
{ | ||
if (!self::validLength($tel)) { | ||
$tel = \str_replace(' ', '', (string) $tel); | ||
|
||
if (! self::validLength($tel)) { | ||
return false; | ||
} | ||
|
||
$operator_prefixes = trim( | ||
join("|", self::OPERATOR_PREFIXES[$key]), | ||
"|" | ||
implode('|', self::OPERATOR_PREFIXES[$key]), | ||
'|' | ||
); | ||
$expression = "/^((\+|(0{2}))?". self::PREFIX . ")?((". $operator_prefixes . ")([0-9]{6,7}))$/"; | ||
|
||
$expression = "/^((\+|(0{2}))?" . self::PREFIX . ')?((' . $operator_prefixes . ')([0-9]{6,7}))$/'; | ||
|
||
return preg_match($expression, $tel) ? true : false; | ||
} | ||
|
||
/** | ||
* Check if Number is Orange | ||
* Check if Number is Orange. | ||
* | ||
* @param string | int $tel | ||
* | ||
* @return bool | ||
*/ | ||
public static function isOrange($tel) : bool | ||
public static function isOrange(string | int $tel) : bool | ||
{ | ||
return self::checkNumber($tel, 'orange'); | ||
} | ||
|
||
/** | ||
* Check if Number is MTN | ||
* Check if Number is MTN. | ||
* | ||
* @param string | int $tel | ||
* | ||
* @return bool | ||
*/ | ||
public static function isMTN($tel) : bool | ||
public static function isMTN(string | int $tel) : bool | ||
{ | ||
return self::checkNumber($tel, 'mtn'); | ||
} | ||
|
||
/** | ||
* Check if Number is Nexttel | ||
* Check if Number is Nexttel. | ||
* | ||
* @param string | int $tel | ||
* | ||
* @return bool | ||
*/ | ||
public static function isNexttel($tel) : bool | ||
public static function isNexttel(string | int $tel) : bool | ||
{ | ||
return self::checkNumber($tel, 'nexttel'); | ||
} | ||
|
||
/** | ||
* Match Number to Operator | ||
* Check if Number is Camtel. | ||
* | ||
* @param string | int $tel | ||
* | ||
* @return bool | ||
*/ | ||
public static function isCamtel(string | int $tel) : bool | ||
{ | ||
return self::checkNumber($tel, 'camtel'); | ||
} | ||
|
||
/** | ||
* Match Number to Operator. | ||
* | ||
* @param string | int $tel | ||
* | ||
* @return bool | ||
*/ | ||
public static function check($tel) | ||
public static function check($tel) : string | null | ||
{ | ||
foreach (self::OPERATOR_PREFIXES as $key => $value) { | ||
if (self::checkNumber($tel, $key)) { | ||
|