mirror of
https://github.com/OpenXE-org/OpenXE.git
synced 2024-12-25 22:20:29 +01:00
75 lines
1.3 KiB
PHP
75 lines
1.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Xentral\Components\Mailer\Data;
|
|
|
|
use JsonSerializable;
|
|
|
|
final class EmailRecipient implements JsonSerializable
|
|
{
|
|
/** @var string $email */
|
|
private $email;
|
|
|
|
/** @var string $name */
|
|
private $name;
|
|
|
|
/**
|
|
* @param string $email
|
|
* @param string|null $name
|
|
*/
|
|
public function __construct(string $email, string $name = null)
|
|
{
|
|
$this->email = $email;
|
|
$this->name = $name;
|
|
}
|
|
|
|
/**
|
|
* @return string
|
|
*/
|
|
public function getEmail():string
|
|
{
|
|
return $this->email;
|
|
}
|
|
|
|
/**
|
|
* @return string
|
|
*/
|
|
public function getName():string
|
|
{
|
|
if ($this->name !== null) {
|
|
return $this->name;
|
|
}
|
|
|
|
return '';
|
|
}
|
|
|
|
/**
|
|
* @param string $name
|
|
*/
|
|
public function setName($name):void
|
|
{
|
|
$this->name = $name;
|
|
}
|
|
|
|
/**
|
|
* @return string
|
|
*/
|
|
public function __toString():string
|
|
{
|
|
if ($this->name === null) {
|
|
return $this->email;
|
|
}
|
|
|
|
return sprintf('%s<%s>', $this->name, $this->email);
|
|
}
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
public function jsonSerialize(): array
|
|
{
|
|
return ['email' => $this->email, 'name' => $this->name];
|
|
}
|
|
}
|