Skip to content
Snippets Groups Projects

Devel

Merged Piotr Potrebka requested to merge devel into main
10 files
+ 229
60
Compare changes
  • Side-by-side
  • Inline
Files
10
@@ -2,8 +2,20 @@
@@ -2,8 +2,20 @@
namespace WPDesk\Library\WPEmail\Abstracts;
namespace WPDesk\Library\WPEmail\Abstracts;
 
use WPDesk\View\Renderer\Renderer;
 
abstract class EmailAbstract implements EmailInterface {
abstract class EmailAbstract implements EmailInterface {
 
/**
 
* @var Renderer
 
*/
 
private $renderer;
 
 
public function __construct( Renderer $renderer, array $recipients ) {
 
$this->renderer = $renderer;
 
$this->recipients = $recipients;
 
}
 
/**
/**
* Define unique email ID.
* Define unique email ID.
*
*
@@ -14,10 +26,10 @@ abstract class EmailAbstract implements EmailInterface {
@@ -14,10 +26,10 @@ abstract class EmailAbstract implements EmailInterface {
/**
/**
* Get defined placeholders.
* Get defined placeholders.
*
*
* @return array
* @return string[]
*/
*/
public function get_placeholders(): array {
public function get_placeholders(): array {
return [];
}
}
/**
/**
@@ -26,7 +38,11 @@ abstract class EmailAbstract implements EmailInterface {
@@ -26,7 +38,11 @@ abstract class EmailAbstract implements EmailInterface {
* @return string
* @return string
*/
*/
public function get_subject(): string {
public function get_subject(): string {
 
if ( ! $this->subject ) {
 
throw new \Exception( 'Empty email subject' );
 
}
 
return '';
}
}
/**
/**
@@ -35,25 +51,25 @@ abstract class EmailAbstract implements EmailInterface {
@@ -35,25 +51,25 @@ abstract class EmailAbstract implements EmailInterface {
* @return string
* @return string
*/
*/
public function get_heading(): string {
public function get_heading(): string {
return '';
}
}
/**
/**
* Get valid recipients.
* Get valid recipients.
*
*
* @return array
* @return string[]
*/
*/
public function get_recipients(): array {
public function get_recipients(): array {
return $this->recipients;
}
}
/**
/**
* Get email headers.
* Get email headers.
*
*
* @return string
* @return string[]
*/
*/
public function get_headers(): string {
public function get_headers(): array {
return [];
}
}
/**
/**
@@ -62,7 +78,7 @@ abstract class EmailAbstract implements EmailInterface {
@@ -62,7 +78,7 @@ abstract class EmailAbstract implements EmailInterface {
* @return array
* @return array
*/
*/
public function get_attachments(): array {
public function get_attachments(): array {
return [];
}
}
/**
/**
@@ -71,7 +87,7 @@ abstract class EmailAbstract implements EmailInterface {
@@ -71,7 +87,7 @@ abstract class EmailAbstract implements EmailInterface {
* @return string
* @return string
*/
*/
public function get_type(): string {
public function get_type(): string {
return 'text/html';
}
}
/**
/**
@@ -80,18 +96,27 @@ abstract class EmailAbstract implements EmailInterface {
@@ -80,18 +96,27 @@ abstract class EmailAbstract implements EmailInterface {
* @return string
* @return string
*/
*/
public function get_content(): string {
public function get_content(): string {
 
if ( ! $this->content ) {
 
throw new \Exception( 'Empty email subject' );
 
}
 
 
return '';
 
}
 
/**
 
* @return mixed
 
*/
 
public function get_object() {
 
return '';
}
}
/**
/**
* Send email.
* Get email content.
*
*
* @return void
* @return string
*/
*/
public function send(): void {
public function render(): string {
wp_mail(
return $this->renderer->render( dirname( __DIR__ ) . '/html/default.php', [ 'content' => $this->get_content(), 'heading' => $this->get_heading(), 'object' => $this->get_object() ] );
$this->get_recipients(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments()
);
}
}
}
}
Loading