mirror of
https://github.com/anthonyaxenov/atol-online.git
synced 2024-11-22 17:24:33 +00:00
Улучшен trait HasEmail
* valid_strlen() * Constraints::MAX_LENGTH_EMAIL * phpdoc
This commit is contained in:
parent
5424726a97
commit
1061914a5f
@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
namespace AtolOnline\Traits;
|
namespace AtolOnline\Traits;
|
||||||
|
|
||||||
use AtolOnline\{Exceptions\AtolEmailTooLongException, Exceptions\AtolEmailValidateException};
|
use AtolOnline\{Constants\Constraints, Exceptions\AtolEmailTooLongException, Exceptions\AtolEmailValidateException};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Добавляет объекту функционал для работы с email
|
* Добавляет объекту функционал для работы с email
|
||||||
@ -38,16 +38,15 @@ trait HasEmail
|
|||||||
*
|
*
|
||||||
* @param string $email
|
* @param string $email
|
||||||
* @return $this
|
* @return $this
|
||||||
* @throws AtolEmailTooLongException
|
* @throws \AtolOnline\Exceptions\AtolEmailTooLongException Слишком длинный email
|
||||||
* @throws AtolEmailValidateException
|
* @throws \AtolOnline\Exceptions\AtolEmailValidateException Невалидный email
|
||||||
*/
|
*/
|
||||||
public function setEmail(string $email)
|
public function setEmail(string $email)
|
||||||
{
|
{
|
||||||
$email = trim($email);
|
$email = trim($email);
|
||||||
if ((function_exists('mb_strlen') ? mb_strlen($email) : strlen($email)) > 64) {
|
if (valid_strlen($email) > Constraints::MAX_LENGTH_EMAIL) {
|
||||||
throw new AtolEmailTooLongException($email, 64);
|
throw new AtolEmailTooLongException($email, Constraints::MAX_LENGTH_EMAIL);
|
||||||
}
|
} elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
||||||
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
|
||||||
throw new AtolEmailValidateException($email);
|
throw new AtolEmailValidateException($email);
|
||||||
}
|
}
|
||||||
$this->email = $email;
|
$this->email = $email;
|
||||||
|
Loading…
Reference in New Issue
Block a user