Skip to content
Snippets Groups Projects
Commit 82b8ba8d authored by Piotr Potrebka's avatar Piotr Potrebka
Browse files

feat: email abstract

parent 4ffdc837
No related branches found
No related tags found
1 merge request!2Devel
Pipeline #150471 passed
This commit is part of merge request !2. Comments created here will be created in the context of that merge request.
......@@ -4,25 +4,52 @@ namespace WPDesk\Library\WPEmail\Abstracts;
use WPDesk\View\Renderer\Renderer;
abstract class EmailGettersAbstract implements EmailGettersInterface, ConditionInterface {
abstract class EmailAbstract implements EmailGettersInterface {
/**
* @var Renderer
* @var array
*/
private $renderer;
private $recipients = [];
/**
* @var array
*/
private $placeholders = [];
/**
* @var string
*/
private $subject = '';
/**
* @var string
*/
private $heading = '';
/**
* @var array
*/
private $attachments = [];
/**
* @var string
*/
private $subject;
private $content = '';
/**
* @var string
*/
private $heading;
private $type = 'text/html';
/**
* @var array
*/
private $headers;
public function __construct( Renderer $renderer, array $recipients ) {
/**
* @var Renderer
*/
private $renderer;
public function __construct( Renderer $renderer ) {
$this->renderer = $renderer;
$this->recipients = $recipients;
}
/**
......@@ -38,27 +65,21 @@ abstract class EmailGettersAbstract implements EmailGettersInterface, ConditionI
* @return string[]
*/
public function get_placeholders(): array {
return [];
return $this->placeholders;
}
/**
* Get email subject.
*
* @return string
* @throws \Exception
*/
public function get_subject(): string {
if ( ! $this->subject ) {
throw new \Exception( 'Empty email subject' );
}
return '';
}
public function set_subject( string $subject ): self {
$this->subject = $subject;
return $this;
return $this->subject;
}
/**
......@@ -67,14 +88,7 @@ abstract class EmailGettersAbstract implements EmailGettersInterface, ConditionI
* @return string
*/
public function get_heading(): string {
return '';
}
public function set_heading( string $heading ): self {
$this->heading = $heading;
return $this;
return $this->heading;
}
/**
......@@ -92,7 +106,7 @@ abstract class EmailGettersAbstract implements EmailGettersInterface, ConditionI
* @return string[]
*/
public function get_headers(): array {
return [];
return $this->headers;
}
/**
......@@ -101,7 +115,7 @@ abstract class EmailGettersAbstract implements EmailGettersInterface, ConditionI
* @return array
*/
public function get_attachments(): array {
return [];
return $this->attachments;
}
/**
......@@ -110,7 +124,7 @@ abstract class EmailGettersAbstract implements EmailGettersInterface, ConditionI
* @return string
*/
public function get_type(): string {
return 'text/html';
return $this->type;
}
/**
......@@ -142,8 +156,4 @@ abstract class EmailGettersAbstract implements EmailGettersInterface, ConditionI
return $this->renderer->render( dirname( __DIR__ ) . '/html/default.php', [ 'content' => $this->get_content(), 'heading' => $this->get_heading(), 'object' => $this->get_object() ] );
}
public function is_valid(): bool {
return true;
}
}
<?php
namespace WPDesk\Library\WPEmail\Emails;
namespace WPDesk\Library\WPEmail;
use WPDesk\Library\WPEmail\Abstracts\ConditionInterface;
use WPDesk\Library\WPEmail\Abstracts\EmailGettersInterface;
class EmailSender {
......@@ -82,15 +81,9 @@ class EmailSender {
public function send() {
foreach ( $this->get_emails() as $email ) {
$this->before_wp_mail();
if( $email instanceof ConditionInterface ) {
if( $email->is_valid() ) {
wp_mail(
$email->get_recipients(), $email->get_subject(), $email->render(), $email->get_headers(), $email->get_attachments()
);
}
}
$this->after_wp_mail();
}
}
......
......@@ -2,9 +2,9 @@
namespace WPDesk\Library\WPEmail\Emails;
use WPDesk\Library\WPEmail\Abstracts\EmailGettersAbstract;
use WPDesk\Library\WPEmail\Abstracts\EmailAbstract;
class Email extends EmailGettersAbstract {
class Email extends EmailAbstract {
const ID = 'email';
......
......@@ -2,6 +2,9 @@
namespace WPDesk\Library\WPEmail\Parser;
use Pelago\Emogrifier\HtmlProcessor\CssToAttributeConverter;
use Pelago\Emogrifier\HtmlProcessor\HtmlPruner;
class HTMLDecorator {
public static function style_inline( $content ) {
......@@ -24,7 +27,7 @@ class HTMLDecorator {
$content = CssToAttributeConverter::fromDomDocument( $dom_document )
->convertCssToVisualAttributes()
->render();
} catch ( Exception $e ) {
} catch ( \Exception $e ) {
$logger = wc_get_logger();
$logger->error( $e->getMessage(), array( 'source' => 'emogrifier' ) );
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment