<?php
namespace App\Entity\Embeddable;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
#[ORM\Embeddable]
class Email
{
#[ORM\Column(type: Types::STRING, length: 150, nullable: true, options: ['default' => 'no-reply@localhost.com'])]
#[Gedmo\Versioned]
private ?string $from = 'no-reply@localhost.com';
#[ORM\Column(type: Types::STRING, length: 150, options: ['default' => 'errors@localhost.com'])]
#[Gedmo\Versioned]
private string $toError = 'errors@localhost.com';
#[ORM\Column(type: Types::STRING, length: 200, options: ['default' => 'smtp.localhost.com'])]
#[Gedmo\Versioned]
private string $host = 'smtp.localhost.com';
#[ORM\Column(type: Types::SMALLINT, options: ['default' => 25])]
#[Gedmo\Versioned]
private int $port = 25;
#[ORM\Column(type: Types::STRING, length: 200, options: ['default' => 'user@localhost.com'])]
#[Gedmo\Versioned]
private string $user = 'user@localhost';
#[ORM\Column(type: Types::STRING, length: 255, options: ['default' => 'password'])]
#[Gedmo\Versioned]
private string $password = 'password';
public function toDsn(): string
{
return \sprintf(
'smtp://%s:%s@%s:%d',
\urlencode(!empty($this->user) ? $this->user : 'user@localhost.com'),
\urlencode(!empty($this->password) ? $this->password : 'password'),
\urlencode(!empty($this->host) ? $this->host : 'stmp.localhost.com'),
$this->port && $this->port >= 25 ? $this->port : 25
);
}
public function getFrom(): ?string
{
return $this->from;
}
public function setFrom(?string $from): self
{
$this->from = $from;
return $this;
}
public function getToError(): ?string
{
return $this->toError;
}
public function setToError(string $toError): self
{
$this->toError = $toError;
return $this;
}
public function getHost(): ?string
{
return $this->host;
}
public function setHost(string $host): self
{
$this->host = $host;
return $this;
}
public function getPort(): ?int
{
return $this->port;
}
public function setPort(int $port): self
{
$this->port = $port;
return $this;
}
public function getUser(): ?string
{
return $this->user;
}
public function setUser(string $user): self
{
$this->user = $user;
return $this;
}
public function getPassword(): ?string
{
return $this->password;
}
public function setPassword(string $password): self
{
$this->password = $password;
return $this;
}
}