Upgrade to 3.8.2
This commit is contained in:
@@ -19,20 +19,11 @@ class Body
|
||||
{
|
||||
use Properties;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $html;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $text;
|
||||
protected string|null $html = null;
|
||||
protected string|null $text = null;
|
||||
|
||||
/**
|
||||
* Email body constructor
|
||||
*
|
||||
* @param array $props
|
||||
*/
|
||||
public function __construct(array $props = [])
|
||||
{
|
||||
@@ -41,20 +32,16 @@ class Body
|
||||
|
||||
/**
|
||||
* Returns the HTML content of the email body
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function html()
|
||||
public function html(): string
|
||||
{
|
||||
return $this->html ?? '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the plain text content of the email body
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function text()
|
||||
public function text(): string
|
||||
{
|
||||
return $this->text ?? '';
|
||||
}
|
||||
@@ -62,10 +49,9 @@ class Body
|
||||
/**
|
||||
* Sets the HTML content for the email body
|
||||
*
|
||||
* @param string|null $html
|
||||
* @return $this
|
||||
*/
|
||||
protected function setHtml(string $html = null)
|
||||
protected function setHtml(string|null $html = null): static
|
||||
{
|
||||
$this->html = $html;
|
||||
return $this;
|
||||
@@ -74,10 +60,9 @@ class Body
|
||||
/**
|
||||
* Sets the plain text content for the email body
|
||||
*
|
||||
* @param string|null $text
|
||||
* @return $this
|
||||
*/
|
||||
protected function setText(string $text = null)
|
||||
protected function setText(string|null $text = null): static
|
||||
{
|
||||
$this->text = $text;
|
||||
return $this;
|
||||
|
@@ -24,89 +24,61 @@ class Email
|
||||
/**
|
||||
* If set to `true`, the debug mode is enabled
|
||||
* for all emails
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public static $debug = false;
|
||||
public static bool $debug = false;
|
||||
|
||||
/**
|
||||
* Store for sent emails when `Email::$debug`
|
||||
* is set to `true`
|
||||
*
|
||||
*/
|
||||
public static array $emails = [];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public static $emails = [];
|
||||
protected array|null $attachments = null;
|
||||
|
||||
protected Body|null $body = null;
|
||||
|
||||
/**
|
||||
* @var array|null
|
||||
* @var array
|
||||
*/
|
||||
protected $attachments;
|
||||
protected array|null $bcc = null;
|
||||
|
||||
protected Closure|null $beforeSend = null;
|
||||
|
||||
/**
|
||||
* @var \Kirby\Email\Body|null
|
||||
* @var array
|
||||
*/
|
||||
protected $body;
|
||||
protected array|null $cc = null;
|
||||
|
||||
/**
|
||||
* @var array|null
|
||||
* @var string
|
||||
*/
|
||||
protected $bcc;
|
||||
protected string|null $from = null;
|
||||
protected string|null $fromName = null;
|
||||
|
||||
protected bool $isSent = false;
|
||||
|
||||
/**
|
||||
* @var \Closure|null
|
||||
* @var string
|
||||
*/
|
||||
protected $beforeSend;
|
||||
protected string|null $replyTo = null;
|
||||
protected string|null $replyToName = null;
|
||||
|
||||
/**
|
||||
* @var array|null
|
||||
* @var string
|
||||
*/
|
||||
protected $cc;
|
||||
protected string|null $subject = null;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
* @var array
|
||||
*/
|
||||
protected $from;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
protected $fromName;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
protected $replyTo;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
protected $replyToName;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $isSent = false;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
protected $subject;
|
||||
|
||||
/**
|
||||
* @var array|null
|
||||
*/
|
||||
protected $to;
|
||||
|
||||
/**
|
||||
* @var array|null
|
||||
*/
|
||||
protected $transport;
|
||||
protected array|null $to = null;
|
||||
protected array|null $transport = null;
|
||||
|
||||
/**
|
||||
* Email constructor
|
||||
*
|
||||
* @param array $props
|
||||
* @param bool $debug
|
||||
*/
|
||||
public function __construct(array $props = [], bool $debug = false)
|
||||
{
|
||||
@@ -123,8 +95,6 @@ class Email
|
||||
|
||||
/**
|
||||
* Returns the email attachments
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function attachments(): array
|
||||
{
|
||||
@@ -133,18 +103,14 @@ class Email
|
||||
|
||||
/**
|
||||
* Returns the email body
|
||||
*
|
||||
* @return \Kirby\Email\Body|null
|
||||
*/
|
||||
public function body()
|
||||
public function body(): Body|null
|
||||
{
|
||||
return $this->body;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns "bcc" recipients
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function bcc(): array
|
||||
{
|
||||
@@ -154,8 +120,6 @@ class Email
|
||||
/**
|
||||
* Returns the beforeSend callback closure,
|
||||
* which has access to the PHPMailer instance
|
||||
*
|
||||
* @return \Closure|null
|
||||
*/
|
||||
public function beforeSend(): Closure|null
|
||||
{
|
||||
@@ -164,8 +128,6 @@ class Email
|
||||
|
||||
/**
|
||||
* Returns "cc" recipients
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function cc(): array
|
||||
{
|
||||
@@ -174,8 +136,6 @@ class Email
|
||||
|
||||
/**
|
||||
* Returns default transport settings
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function defaultTransport(): array
|
||||
{
|
||||
@@ -186,8 +146,6 @@ class Email
|
||||
|
||||
/**
|
||||
* Returns the "from" email address
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function from(): string
|
||||
{
|
||||
@@ -196,8 +154,6 @@ class Email
|
||||
|
||||
/**
|
||||
* Returns the "from" name
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function fromName(): string|null
|
||||
{
|
||||
@@ -206,18 +162,14 @@ class Email
|
||||
|
||||
/**
|
||||
* Checks if the email has an HTML body
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isHtml()
|
||||
public function isHtml(): bool
|
||||
{
|
||||
return empty($this->body()->html()) === false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the email has been sent successfully
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isSent(): bool
|
||||
{
|
||||
@@ -226,8 +178,6 @@ class Email
|
||||
|
||||
/**
|
||||
* Returns the "reply to" email address
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function replyTo(): string
|
||||
{
|
||||
@@ -236,8 +186,6 @@ class Email
|
||||
|
||||
/**
|
||||
* Returns the "reply to" name
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function replyToName(): string|null
|
||||
{
|
||||
@@ -247,13 +195,12 @@ class Email
|
||||
/**
|
||||
* Converts single or multiple email addresses to a sanitized format
|
||||
*
|
||||
* @param string|array|null $email
|
||||
* @param bool $multiple
|
||||
* @return array|mixed|string
|
||||
* @throws \Exception
|
||||
*/
|
||||
protected function resolveEmail($email = null, bool $multiple = true)
|
||||
{
|
||||
protected function resolveEmail(
|
||||
string|array|null $email = null,
|
||||
bool $multiple = true
|
||||
): array|string {
|
||||
if ($email === null) {
|
||||
return $multiple === true ? [] : '';
|
||||
}
|
||||
@@ -284,8 +231,6 @@ class Email
|
||||
|
||||
/**
|
||||
* Sends the email
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function send(): bool
|
||||
{
|
||||
@@ -295,10 +240,9 @@ class Email
|
||||
/**
|
||||
* Sets the email attachments
|
||||
*
|
||||
* @param array|null $attachments
|
||||
* @return $this
|
||||
*/
|
||||
protected function setAttachments($attachments = null)
|
||||
protected function setAttachments(array|null $attachments = null): static
|
||||
{
|
||||
$this->attachments = $attachments ?? [];
|
||||
return $this;
|
||||
@@ -307,10 +251,9 @@ class Email
|
||||
/**
|
||||
* Sets the email body
|
||||
*
|
||||
* @param string|array $body
|
||||
* @return $this
|
||||
*/
|
||||
protected function setBody($body)
|
||||
protected function setBody(string|array $body): static
|
||||
{
|
||||
if (is_string($body) === true) {
|
||||
$body = ['text' => $body];
|
||||
@@ -323,10 +266,9 @@ class Email
|
||||
/**
|
||||
* Sets "bcc" recipients
|
||||
*
|
||||
* @param string|array|null $bcc
|
||||
* @return $this
|
||||
*/
|
||||
protected function setBcc($bcc = null)
|
||||
protected function setBcc(string|array|null $bcc = null): static
|
||||
{
|
||||
$this->bcc = $this->resolveEmail($bcc);
|
||||
return $this;
|
||||
@@ -335,10 +277,9 @@ class Email
|
||||
/**
|
||||
* Sets the "beforeSend" callback
|
||||
*
|
||||
* @param \Closure|null $beforeSend
|
||||
* @return $this
|
||||
*/
|
||||
protected function setBeforeSend(Closure|null $beforeSend = null)
|
||||
protected function setBeforeSend(Closure|null $beforeSend = null): static
|
||||
{
|
||||
$this->beforeSend = $beforeSend;
|
||||
return $this;
|
||||
@@ -347,10 +288,9 @@ class Email
|
||||
/**
|
||||
* Sets "cc" recipients
|
||||
*
|
||||
* @param string|array|null $cc
|
||||
* @return $this
|
||||
*/
|
||||
protected function setCc($cc = null)
|
||||
protected function setCc(string|array|null $cc = null): static
|
||||
{
|
||||
$this->cc = $this->resolveEmail($cc);
|
||||
return $this;
|
||||
@@ -359,10 +299,9 @@ class Email
|
||||
/**
|
||||
* Sets the "from" email address
|
||||
*
|
||||
* @param string $from
|
||||
* @return $this
|
||||
*/
|
||||
protected function setFrom(string $from)
|
||||
protected function setFrom(string $from): static
|
||||
{
|
||||
$this->from = $this->resolveEmail($from, false);
|
||||
return $this;
|
||||
@@ -371,10 +310,9 @@ class Email
|
||||
/**
|
||||
* Sets the "from" name
|
||||
*
|
||||
* @param string|null $fromName
|
||||
* @return $this
|
||||
*/
|
||||
protected function setFromName(string $fromName = null)
|
||||
protected function setFromName(string|null $fromName = null): static
|
||||
{
|
||||
$this->fromName = $fromName;
|
||||
return $this;
|
||||
@@ -383,10 +321,9 @@ class Email
|
||||
/**
|
||||
* Sets the "reply to" email address
|
||||
*
|
||||
* @param string|null $replyTo
|
||||
* @return $this
|
||||
*/
|
||||
protected function setReplyTo(string $replyTo = null)
|
||||
protected function setReplyTo(string|null $replyTo = null): static
|
||||
{
|
||||
$this->replyTo = $this->resolveEmail($replyTo, false);
|
||||
return $this;
|
||||
@@ -395,10 +332,9 @@ class Email
|
||||
/**
|
||||
* Sets the "reply to" name
|
||||
*
|
||||
* @param string|null $replyToName
|
||||
* @return $this
|
||||
*/
|
||||
protected function setReplyToName(string $replyToName = null)
|
||||
protected function setReplyToName(string|null $replyToName = null): static
|
||||
{
|
||||
$this->replyToName = $replyToName;
|
||||
return $this;
|
||||
@@ -407,10 +343,9 @@ class Email
|
||||
/**
|
||||
* Sets the email subject
|
||||
*
|
||||
* @param string $subject
|
||||
* @return $this
|
||||
*/
|
||||
protected function setSubject(string $subject)
|
||||
protected function setSubject(string $subject): static
|
||||
{
|
||||
$this->subject = $subject;
|
||||
return $this;
|
||||
@@ -419,10 +354,9 @@ class Email
|
||||
/**
|
||||
* Sets the recipients of the email
|
||||
*
|
||||
* @param string|array $to
|
||||
* @return $this
|
||||
*/
|
||||
protected function setTo($to)
|
||||
protected function setTo(string|array $to): static
|
||||
{
|
||||
$this->to = $this->resolveEmail($to);
|
||||
return $this;
|
||||
@@ -431,10 +365,9 @@ class Email
|
||||
/**
|
||||
* Sets the email transport settings
|
||||
*
|
||||
* @param array|null $transport
|
||||
* @return $this
|
||||
*/
|
||||
protected function setTransport($transport = null)
|
||||
protected function setTransport(array|null $transport = null): static
|
||||
{
|
||||
$this->transport = $transport;
|
||||
return $this;
|
||||
@@ -442,8 +375,6 @@ class Email
|
||||
|
||||
/**
|
||||
* Returns the email subject
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function subject(): string
|
||||
{
|
||||
@@ -452,8 +383,6 @@ class Email
|
||||
|
||||
/**
|
||||
* Returns the email recipients
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function to(): array
|
||||
{
|
||||
@@ -462,8 +391,6 @@ class Email
|
||||
|
||||
/**
|
||||
* Returns the email transports settings
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function transport(): array
|
||||
{
|
||||
|
@@ -21,8 +21,6 @@ class PHPMailer extends Email
|
||||
/**
|
||||
* Sends email via PHPMailer library
|
||||
*
|
||||
* @param bool $debug
|
||||
* @return bool
|
||||
* @throws \Kirby\Exception\InvalidArgumentException
|
||||
*/
|
||||
public function send(bool $debug = false): bool
|
||||
|
Reference in New Issue
Block a user