<?php namespace WPDesk\Library\WPEmail\Abstracts; use WPDesk\View\Renderer\Renderer; abstract class EmailGettersAbstract implements EmailGettersInterface, EmailSettersInterface { /** * @var Renderer */ private $renderer; /** * @var string */ private $subject; /** * @var string */ private $heading; public function __construct( Renderer $renderer, array $recipients ) { $this->renderer = $renderer; $this->recipients = $recipients; } /** * Define unique email ID. * * @return string */ abstract public function get_id(): string; /** * Get defined placeholders. * * @return string[] */ public function get_placeholders(): array { return []; } /** * Get email subject. * * @return string */ 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; } /** * Get email heading. * * @return string */ public function get_heading(): string { return ''; } public function set_heading( string $heading ): self { $this->heading = $heading; return $this; } /** * Get valid recipients. * * @return string[] */ public function get_recipients(): array { return $this->recipients; } /** * Get email headers. * * @return string[] */ public function get_headers(): array { return []; } /** * Get email attachments. * * @return array */ public function get_attachments(): array { return []; } /** * Get email type. * * @return string */ public function get_type(): string { return 'text/html'; } /** * Get email content. * * @return string */ public function get_content(): string { if ( ! $this->content ) { throw new \Exception( 'Empty email subject' ); } return ''; } /** * @return mixed */ public function get_object() { 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() ] ); } }