Skip to content
Snippets Groups Projects

Devel

Merged Piotr Potrebka requested to merge devel into main
Compare and Show latest version
5 files
+ 216
104
Compare changes
  • Side-by-side
  • Inline

Files

+ 121
30
@@ -2,55 +2,49 @@
namespace WPDesk\Library\WPEmail\Abstracts;
use WPDesk\View\Renderer\Renderer;
use Exception;
abstract class EmailAbstract implements EmailGettersInterface {
abstract class EmailAbstract implements EmailInterface {
/**
* @var array
*/
private $recipients = [];
protected $recipients = [];
/**
* @var array
*/
private $placeholders = [];
protected $placeholders = [];
/**
* @var string
*/
private $subject = '';
protected $subject = '';
/**
* @var string
*/
private $heading = '';
protected $heading = '';
/**
* @var array
*/
private $attachments = [];
protected $attachments = [];
/**
* @var string
*/
private $content = '';
protected $content = '';
/**
* @var string
*/
private $type = 'text/html';
protected $type = 'text/html';
/**
* @var array
*/
private $headers;
/**
* @var Renderer
*/
private $renderer;
public function __construct( Renderer $renderer ) {
$this->renderer = $renderer;
}
protected $headers;
/**
* Define unique email ID.
@@ -59,6 +53,19 @@ abstract class EmailAbstract implements EmailGettersInterface {
*/
abstract public function get_id(): string;
/**
* Set placeholders.
*
* @param array $placeholders
*
* @return self
*/
public function set_placeholders( array $placeholders = [] ): self {
$this->placeholders = array_merge( $this->placeholders, $placeholders );
return $this;
}
/**
* Get defined placeholders.
*
@@ -68,20 +75,46 @@ abstract class EmailAbstract implements EmailGettersInterface {
return $this->placeholders;
}
/**
* Get email subject.
*
* @param string $subject
*
* @return self
*/
public function set_subject( string $subject ): self {
$this->subject = $subject;
return $this;
}
/**
* Get email subject.
*
* @return string
* @throws \Exception
* @throws Exception
*/
public function get_subject(): string {
if ( ! $this->subject ) {
throw new \Exception( 'Empty email subject' );
throw new Exception( 'Empty email subject' );
}
return $this->subject;
}
/**
* Set email heading.
*
* @param string $heading
*
* @return self
*/
public function set_heading( string $heading ): self {
$this->heading = $heading;
return $this;
}
/**
* Get email heading.
*
@@ -91,6 +124,19 @@ abstract class EmailAbstract implements EmailGettersInterface {
return $this->heading;
}
/**
* Get valid recipients.
*
* @param array $recipients
*
* @return self
*/
public function set_recipients( array $recipients = [] ): self {
$this->recipients = $recipients;
return $this;
}
/**
* Get valid recipients.
*
@@ -100,6 +146,19 @@ abstract class EmailAbstract implements EmailGettersInterface {
return $this->recipients;
}
/**
* Get email headers.
*
* @param array $headers
*
* @return self
*/
public function set_headers( array $headers = [] ): self {
$this->headers = $headers;
return $this;
}
/**
* Get email headers.
*
@@ -109,6 +168,19 @@ abstract class EmailAbstract implements EmailGettersInterface {
return $this->headers;
}
/**
* Set attachments.
*
* @param array $attachments
*
* @return self
*/
public function set_attachments( array $attachments ): self {
$this->attachments = $attachments;
return $this;
}
/**
* Get email attachments.
*
@@ -118,6 +190,19 @@ abstract class EmailAbstract implements EmailGettersInterface {
return $this->attachments;
}
/**
* Set email type.
*
* @param string $type
*
* @return self
*/
public function set_type( string $type = 'text/html' ): self {
$this->type = $type;
return $this;
}
/**
* Get email type.
*
@@ -127,14 +212,28 @@ abstract class EmailAbstract implements EmailGettersInterface {
return $this->type;
}
/**
* Get email content.
*
* @param string $content
*
* @return self
*/
public function set_content( string $content ): self {
$this->content = $content;
return $this;
}
/**
* Get email content.
*
* @return string
* @throws Exception
*/
public function get_content(): string {
if ( ! $this->content ) {
throw new \Exception( 'Empty email subject' );
throw new Exception( 'Empty email content' );
}
return '';
@@ -147,13 +246,5 @@ abstract class EmailAbstract implements EmailGettersInterface {
return '';
}
/**
* Get email content.
*
* @return string
*/
public function render(): string {
return $this->renderer->render( dirname( __DIR__ ) . '/html/default.php', [ 'content' => $this->get_content(), 'heading' => $this->get_heading(), 'object' => $this->get_object() ] );
}
}
Loading