Skip to content

Instantly share code, notes, and snippets.

@BerezhniyDmitro
Created May 27, 2021 09:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BerezhniyDmitro/4c7e623bd94ea3011722825db9b7f308 to your computer and use it in GitHub Desktop.
Save BerezhniyDmitro/4c7e623bd94ea3011722825db9b7f308 to your computer and use it in GitHub Desktop.
<?php
declare(strict_types=1);
namespace App\VO;
use InvalidArgumentException;
/**
* Class Email обьект значение которое инкапсулирует в себе email значение
*/
final class Email
{
/**
* @var string email
*/
private $email;
/**
* Email constructor.
*
* @param string $email
*/
private function __construct(string $email)
{
$this->email = $email;
}
/**
* Метод создает Обьект-значение Email из строки
*
* @param string $email
*
* @return self
*/
public static function createFromString(string $email): Email
{
$email = mb_strtolower($email);
if (! filter_var($email, FILTER_VALIDATE_EMAIL)) {
throw new InvalidArgumentException('Переданное значение должно быть корректным email адресом');
}
return new self($email);
}
/**
* Метод возвращает значение
*
* @return string
*/
public function __toString(): string
{
return $this->email;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment