mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-01 05:29:20 +03:00
Cleanup MailSo Validator
Cleanup removed features
This commit is contained in:
parent
8fe8369b2a
commit
1009398d0c
15 changed files with 65 additions and 192 deletions
|
|
@ -17,51 +17,13 @@ namespace MailSo\Base;
|
|||
*/
|
||||
class Validator
|
||||
{
|
||||
|
||||
public static function EmailString(string $sEmail, array $aAllowedInternalDomains = array('localhost')) : bool
|
||||
{
|
||||
$bResult = false;
|
||||
if (\MailSo\Base\Validator::NotEmptyString($sEmail, true))
|
||||
{
|
||||
$bResult = false !== \filter_var($sEmail, FILTER_VALIDATE_EMAIL);
|
||||
if (!$bResult)
|
||||
{
|
||||
$aSplit = \explode("@", $sEmail);
|
||||
$bResult = 2 === \count($aSplit) &&
|
||||
\in_array($aSplit[1], $aAllowedInternalDomains) &&
|
||||
false !== \filter_var(($aSplit[0].'@example.com'), FILTER_VALIDATE_EMAIL);
|
||||
}
|
||||
}
|
||||
|
||||
return $bResult;
|
||||
}
|
||||
|
||||
public static function SimpleEmailString(string $sEmail) : bool
|
||||
{
|
||||
return \MailSo\Base\Validator::NotEmptyString($sEmail, true) &&
|
||||
!!\preg_match('/^[a-zA-Z0-9][a-zA-Z0-9\.\+\-_]*@[a-zA-Z0-9][a-zA-Z0-9\.\+\-_]*$/', $sEmail);
|
||||
}
|
||||
|
||||
public static function NotEmptyString(string $sString, bool $bTrim = false) : bool
|
||||
{
|
||||
return \is_string($sString) &&
|
||||
(0 < \strlen($bTrim ? \trim($sString) : $sString));
|
||||
}
|
||||
|
||||
public static function NotEmptyArray(array $aList) : bool
|
||||
{
|
||||
return \is_array($aList) && 0 < \count($aList);
|
||||
}
|
||||
|
||||
public static function RangeInt(int $iNumber, int $iMin = null, int $iMax = null) : bool
|
||||
{
|
||||
return \is_int($iNumber) &&
|
||||
(null !== $iMin && $iNumber >= $iMin || null === $iMin) &&
|
||||
(null !== $iMax && $iNumber <= $iMax || null === $iMax);
|
||||
return (null === $iMin || $iNumber >= $iMin) && (null === $iMax || $iNumber <= $iMax);
|
||||
}
|
||||
|
||||
public static function PortInt(int $iPort) : bool
|
||||
{
|
||||
return \MailSo\Base\Validator::RangeInt($iPort, 0, 65535);
|
||||
return static::RangeInt($iPort, 0, 65535);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue