-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f26a981
commit 324ba56
Showing
9 changed files
with
332 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,10 +5,14 @@ | |
use Symfony\Component\Mime\Email; | ||
|
||
/** | ||
* TemplatedEmail allows specification of the email body parts as a rendering of the templates. | ||
* | ||
* @see \yii1tech\mailer\View | ||
* | ||
* @author Paul Klimov <[email protected]> | ||
* @since 1.0 | ||
*/ | ||
class TemplatedEmail extends Email | ||
class TemplatedEmail extends Email implements TemplatedEmailContract | ||
{ | ||
|
||
use TemplatedEmailTrait; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
namespace yii1tech\mailer; | ||
|
||
/** | ||
* TemplatedEmailContract defines the email message, which content, should be rendered from the templates. | ||
* | ||
* This interface should be applied to descendant of {@see \Symfony\Component\Mime\Email}. | ||
* | ||
* @author Paul Klimov <[email protected]> | ||
* @since 1.0 | ||
*/ | ||
interface TemplatedEmailContract | ||
{ | ||
/** | ||
* @return string|null template name for text body. | ||
*/ | ||
public function getTextTemplate(): ?string; | ||
|
||
/** | ||
* @return string|null template name for HTML body. | ||
*/ | ||
public function getHtmlTemplate(): ?string; | ||
|
||
/** | ||
* @return array<string, mixed> template context variables. | ||
*/ | ||
public function getContext(): array; | ||
|
||
/** | ||
* @return string|null locale to be used during template rendering. | ||
*/ | ||
public function getLocale(): ?string; | ||
|
||
/** | ||
* @return bool whether the templates have been already rendered. | ||
*/ | ||
public function isRendered(): bool; | ||
|
||
/** | ||
* Marks this email as already rendered. | ||
*/ | ||
public function markAsRendered(): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
<?php | ||
|
||
namespace yii1tech\mailer; | ||
|
||
/** | ||
* Satisfies {@see \yii1tech\mailer\TemplatedEmailContract} interface. | ||
* | ||
* @mixin \Symfony\Component\Mime\Email | ||
* | ||
* @author Paul Klimov <[email protected]> | ||
* @since 1.0 | ||
*/ | ||
trait TemplatedEmailTrait | ||
{ | ||
private $htmlTemplate = null; | ||
|
||
private $textTemplate = null; | ||
|
||
private $locale = null; | ||
|
||
private $context = []; | ||
|
||
private $isRendered = false; | ||
|
||
/** | ||
* @param string|null $template template name for text body. | ||
* @return static self reference. | ||
*/ | ||
public function textTemplate(?string $template): self | ||
{ | ||
$this->textTemplate = $template; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @param string|null $template template name for HTML body. | ||
* @return static self reference. | ||
*/ | ||
public function htmlTemplate(?string $template): self | ||
{ | ||
$this->htmlTemplate = $template; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @param string|null $locale | ||
* @return static self reference. | ||
*/ | ||
public function locale(?string $locale): self | ||
{ | ||
$this->locale = $locale; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @param array<string, mixed> $context template context variables. | ||
* @return static self reference. | ||
*/ | ||
public function context(array $context): self | ||
{ | ||
$this->context = $context; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @return string|null template name for text body. | ||
*/ | ||
public function getTextTemplate(): ?string | ||
{ | ||
return $this->textTemplate; | ||
} | ||
|
||
/** | ||
* @return string|null template name for HTML body. | ||
*/ | ||
public function getHtmlTemplate(): ?string | ||
{ | ||
return $this->htmlTemplate; | ||
} | ||
|
||
/** | ||
* @return array<string, mixed> template context variables. | ||
*/ | ||
public function getContext(): array | ||
{ | ||
return $this->context; | ||
} | ||
|
||
/** | ||
* @return string|null locale to be used during template rendering. | ||
*/ | ||
public function getLocale(): ?string | ||
{ | ||
return $this->locale; | ||
} | ||
|
||
/** | ||
* @return bool whether the templates have been already rendered. | ||
*/ | ||
public function isRendered(): bool | ||
{ | ||
return $this->isRendered; | ||
} | ||
|
||
/** | ||
* Marks this email as already rendered. | ||
*/ | ||
public function markAsRendered(): void | ||
{ | ||
$this->isRendered = true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.