Initial xentral_oss_20.3.c9ffacf
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Xentral\Components\Mailer\Data;
|
||||
|
||||
use SplFileInfo;
|
||||
|
||||
interface EmailAttachmentInterface
|
||||
{
|
||||
/** @var string DISPOSITION_ATTACHMENT */
|
||||
const DISPOSITION_ATTACHMENT = 'attachment';
|
||||
|
||||
/** @var string DISPOSITION_INLINE */
|
||||
const DISPOSITION_INLINE = 'inline';
|
||||
|
||||
/** @var string ENCODING_7BIT */
|
||||
const ENCODING_7BIT = '7bit';
|
||||
|
||||
/** @var string ENCODING_8BIT */
|
||||
const ENCODING_8BIT = '8bit';
|
||||
|
||||
/** @var string ENCODING_BASE64 */
|
||||
const ENCODING_BASE64 = 'base64';
|
||||
|
||||
/** @var string ENCODING_BINARY */
|
||||
const ENCODING_BINARY = 'binary';
|
||||
|
||||
/** @var string ENCODING_QUOTED_PRINTABLE */
|
||||
const ENCODING_QUOTED_PRINTABLE = 'quoted-printable';
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getPath():string;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getType():string;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName():string;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getEncoding():string;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getDisposition():string;
|
||||
}
|
||||
@@ -0,0 +1,318 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Xentral\Components\Mailer\Data;
|
||||
|
||||
final class EmailMessage
|
||||
{
|
||||
/** @var EmailRecipient[] $recipients */
|
||||
private $recipients;
|
||||
|
||||
/** @var string $subject */
|
||||
private $subject;
|
||||
|
||||
/** @var string $body */
|
||||
private $body;
|
||||
|
||||
/** @var EmailRecipient[] $ccRecipients */
|
||||
private $ccRecipients;
|
||||
|
||||
/** @var EmailRecipient[] $bccRecipients */
|
||||
private $bccRecipients;
|
||||
|
||||
/** @var EmailAttachmentInterface[] $attachments */
|
||||
private $attachments;
|
||||
|
||||
/** @var array $headers */
|
||||
private $headers;
|
||||
|
||||
/**
|
||||
* @param string $subject
|
||||
* @param string $body
|
||||
* @param EmailRecipient[]|null $recipients
|
||||
* @param EmailRecipient[]|null $ccRecipients
|
||||
* @param EmailRecipient[]|null $bccRecipients
|
||||
* @param EmailAttachmentInterface[]|null $attachments
|
||||
*/
|
||||
public function __construct(
|
||||
$subject,
|
||||
$body,
|
||||
array $recipients = null,
|
||||
array $ccRecipients = null,
|
||||
array $bccRecipients = null,
|
||||
array $attachments = null
|
||||
) {
|
||||
$this->recipients = [];
|
||||
$this->setRecipients($recipients);
|
||||
$this->subject = $subject;
|
||||
$this->body = $body;
|
||||
$this->setCcRecipients($ccRecipients);
|
||||
$this->setBccRecipients($bccRecipients);
|
||||
$this->setAttachments($attachments);
|
||||
$this->headers = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param EmailRecipient $recipient
|
||||
*
|
||||
* @return EmailMessage
|
||||
*/
|
||||
public function addRecipient(EmailRecipient $recipient): EmailMessage
|
||||
{
|
||||
$this->recipients[] = $recipient;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param EmailRecipient $ccRecipient
|
||||
*
|
||||
* @return EmailMessage
|
||||
*/
|
||||
public function addCcRecipient(EmailRecipient $ccRecipient): EmailMessage
|
||||
{
|
||||
$this->ccRecipients[] = $ccRecipient;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param EmailRecipient $bccRecipient
|
||||
*
|
||||
* @return EmailMessage
|
||||
*/
|
||||
public function addBccRecipient(EmailRecipient $bccRecipient): EmailMessage
|
||||
{
|
||||
$this->bccRecipients[] = $bccRecipient;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param string $value
|
||||
*
|
||||
* @return EmailMessage
|
||||
*/
|
||||
public function addCustomHeader($name, $value): EmailMessage
|
||||
{
|
||||
$this->headers[$name] = $value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param EmailAttachmentInterface $attachment
|
||||
*
|
||||
* @return EmailMessage
|
||||
*/
|
||||
public function addAttachment(EmailAttachmentInterface $attachment): EmailMessage
|
||||
{
|
||||
$this->attachments[] = $attachment;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FileAttachment $attachment
|
||||
*
|
||||
* @return EmailMessage
|
||||
*/
|
||||
public function addFileAttachment(FileAttachment $attachment): EmailMessage
|
||||
{
|
||||
$this->addAttachment($attachment);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ImageAttachment $attachment
|
||||
*
|
||||
* @return EmailMessage
|
||||
*/
|
||||
public function addEmbeddedImage(ImageAttachment $attachment): EmailMessage
|
||||
{
|
||||
$this->addAttachment($attachment);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param StringAttachment $attachment
|
||||
*
|
||||
* @return EmailMessage
|
||||
*/
|
||||
public function addStringAttachment(StringAttachment $attachment): EmailMessage
|
||||
{
|
||||
$this->addAttachment($attachment);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getRecipientsAsString(): string
|
||||
{
|
||||
return implode(';', $this->recipients);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return EmailRecipient[]
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function getRecipients(): array
|
||||
{
|
||||
return $this->recipients;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function getSubject(): string
|
||||
{
|
||||
return $this->subject;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function getBody(): string
|
||||
{
|
||||
return $this->body;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getCcRecipientsAsString(): string
|
||||
{
|
||||
return implode(';', $this->ccRecipients);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return EmailRecipient[]
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function getCcRecipients(): array
|
||||
{
|
||||
return $this->ccRecipients;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getBccRecipientsAsString(): string
|
||||
{
|
||||
return implode(';', $this->bccRecipients);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return EmailRecipient[]
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function getBccRecipients(): array
|
||||
{
|
||||
return $this->bccRecipients;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function getCustomHeaders(): array
|
||||
{
|
||||
return $this->headers;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return FileAttachment[]
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function getAttachments(): array
|
||||
{
|
||||
return $this->attachments;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isHtml(): bool
|
||||
{
|
||||
return $this->body !== strip_tags($this->body);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param EmailRecipient[] $recipients
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function setRecipients(array $recipients = null): void
|
||||
{
|
||||
$this->recipients = [];
|
||||
if ($recipients === null) {
|
||||
return;
|
||||
}
|
||||
foreach ($recipients as $item) {
|
||||
$this->addRecipient($item);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param EmailRecipient[] $ccRecipients
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function setCcRecipients(array $ccRecipients = null): void
|
||||
{
|
||||
$this->ccRecipients = [];
|
||||
if ($ccRecipients === null) {
|
||||
return;
|
||||
}
|
||||
foreach ($ccRecipients as $item) {
|
||||
$this->addCcRecipient($item);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param EmailRecipient[] $bccRecipients
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function setBccRecipients(array $bccRecipients = null): void
|
||||
{
|
||||
$this->bccRecipients = [];
|
||||
if ($bccRecipients === null) {
|
||||
return;
|
||||
}
|
||||
foreach ($bccRecipients as $item) {
|
||||
$this->addBccRecipient($item);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param EmailAttachmentInterface[] $attachments
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function setAttachments(array $attachments = null): void
|
||||
{
|
||||
$this->attachments = [];
|
||||
if ($attachments === null) {
|
||||
return;
|
||||
}
|
||||
foreach ($attachments as $item) {
|
||||
$this->addAttachment($item);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
<?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];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Xentral\Components\Mailer\Data;
|
||||
|
||||
use SplFileInfo;
|
||||
use Xentral\Components\Mailer\Exception\FileNotFoundException;
|
||||
|
||||
final class FileAttachment implements EmailAttachmentInterface
|
||||
{
|
||||
/** @var SplFileInfo $file */
|
||||
private $file;
|
||||
|
||||
/** @var string $name */
|
||||
private $name;
|
||||
|
||||
/** @var string $encoding */
|
||||
private $encoding;
|
||||
|
||||
/** @var string $type */
|
||||
private $type;
|
||||
|
||||
/** @var string $disposition */
|
||||
private $disposition;
|
||||
|
||||
/**
|
||||
* @param string $path
|
||||
* @param string|null $name
|
||||
* @param string $encoding
|
||||
* @param string $type
|
||||
* @param string $disposition
|
||||
*/
|
||||
public function __construct(
|
||||
string $path,
|
||||
string $name = null,
|
||||
string $encoding = self::ENCODING_BASE64,
|
||||
string $type = 'application/octet-stream',
|
||||
string $disposition = self::DISPOSITION_ATTACHMENT
|
||||
)
|
||||
{
|
||||
$this->file = new splFileInfo($path);
|
||||
if (!$this->file->isFile()) {
|
||||
throw new FileNotFoundException(
|
||||
sprintf('Attachment File not found "%s".', $path)
|
||||
);
|
||||
}
|
||||
$this->name = $name === null ? $this->file->getFilename() : $name;
|
||||
$this->encoding = $encoding;
|
||||
$this->type = $type;
|
||||
$this->disposition = $disposition;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getPath():string
|
||||
{
|
||||
return $this->file->getRealPath();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName():string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getEncoding():string
|
||||
{
|
||||
return $this->encoding;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getType():string
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getDisposition(): string
|
||||
{
|
||||
return $this->disposition;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function __toString():string
|
||||
{
|
||||
return (string)$this->file;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Xentral\Components\Mailer\Data;
|
||||
|
||||
use SplFileInfo;
|
||||
use Xentral\Components\Mailer\Exception\FileNotFoundException;
|
||||
|
||||
final class ImageAttachment implements EmailAttachmentInterface
|
||||
{
|
||||
/** @var string TYPE_JPEG */
|
||||
const TYPE_JPEG = 'image/jpeg';
|
||||
|
||||
/** @var string TYPE_PNG */
|
||||
const TYPE_PNG = 'image/png';
|
||||
|
||||
/** @var string TYPE_GIF */
|
||||
const TYPE_GIF = 'image/gif';
|
||||
|
||||
/** @var splFileInfo $file */
|
||||
private $file;
|
||||
|
||||
/** @var string $cid */
|
||||
private $cid;
|
||||
|
||||
/** @var string $name */
|
||||
private $name;
|
||||
|
||||
/** @var string $encoding */
|
||||
private $encoding;
|
||||
|
||||
/** @var string $type */
|
||||
private $type;
|
||||
|
||||
/** @var string $disposition */
|
||||
private $disposition;
|
||||
|
||||
/**
|
||||
* @param string $path
|
||||
* @param string $cid
|
||||
* @param string|null $name
|
||||
* @param string $encoding
|
||||
* @param string $type
|
||||
* @param string $disposition
|
||||
*/
|
||||
public function __construct(
|
||||
string $path,
|
||||
string $cid,
|
||||
string $name = null,
|
||||
string $encoding = self::ENCODING_BASE64,
|
||||
string $type = '',
|
||||
string $disposition = self::DISPOSITION_INLINE
|
||||
) {
|
||||
$this->file = new splFileInfo($path);
|
||||
if (!$this->file->isFile()) {
|
||||
throw new FileNotFoundException(
|
||||
sprintf('Attachment File not found "%s".', $path)
|
||||
);
|
||||
}
|
||||
$this->cid = $cid;
|
||||
$this->name = $name === null ? $this->file->getFilename() : $name;
|
||||
$this->encoding = $encoding;
|
||||
$this->type = $type;
|
||||
$this->disposition = $disposition;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getCid():string
|
||||
{
|
||||
return $this->cid;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getPath(): string
|
||||
{
|
||||
return $this->file->getRealPath();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getType(): string
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName(): string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getEncoding(): string
|
||||
{
|
||||
return $this->encoding;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getDisposition(): string
|
||||
{
|
||||
return $this->disposition;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function __toString():string
|
||||
{
|
||||
return (string)$this->file;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Xentral\Components\Mailer\Data;
|
||||
|
||||
final class StringAttachment implements EmailAttachmentInterface
|
||||
{
|
||||
/** @var string $content*/
|
||||
private $content;
|
||||
|
||||
/** @var string $name*/
|
||||
private $name;
|
||||
|
||||
/** @var string $encoding */
|
||||
private $encoding;
|
||||
|
||||
/** @var string $type */
|
||||
private $type;
|
||||
|
||||
/** @var string $disposition */
|
||||
private $disposition;
|
||||
|
||||
/**
|
||||
* @param string $content
|
||||
* @param string $name
|
||||
* @param string $encoding
|
||||
* @param string $type
|
||||
* @param string $disposition
|
||||
*/
|
||||
public function __construct(
|
||||
string $content,
|
||||
string $name,
|
||||
string $encoding = self::ENCODING_BASE64,
|
||||
string $type = 'application/octet-stream',
|
||||
string $disposition = self::DISPOSITION_ATTACHMENT
|
||||
)
|
||||
{
|
||||
$this->content = $content;
|
||||
$this->name = $name;
|
||||
$this->encoding = $encoding;
|
||||
$this->type = $type;
|
||||
$this->disposition = $disposition;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getContent():string
|
||||
{
|
||||
return $this->content;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getPath(): string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getType(): string
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName(): string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getEncoding(): string
|
||||
{
|
||||
return $this->encoding;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getDisposition(): string
|
||||
{
|
||||
return $this->disposition;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user