mirror of
https://github.com/elyby/accounts.git
synced 2025-05-31 14:11:46 +05:30
Обновлена версия Email Renderer
Добавлен компонент для настройки Email Renderer Добавлен роут в nginx для отображения картинок из Email Renderer
This commit is contained in:
71
common/components/EmailRenderer.php
Normal file
71
common/components/EmailRenderer.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
namespace common\components;
|
||||
|
||||
use Ely\Email\Renderer;
|
||||
use Ely\Email\TemplateBuilder;
|
||||
use Yii;
|
||||
use yii\base\Component;
|
||||
use yii\base\InvalidConfigException;
|
||||
|
||||
class EmailRenderer extends Component {
|
||||
|
||||
/**
|
||||
* @var string базовый путь после хоста. Должен начинаться слешем и заканчиваться без него.
|
||||
* Например "/email-images"
|
||||
*/
|
||||
public $basePath = '';
|
||||
|
||||
/**
|
||||
* @var Renderer
|
||||
*/
|
||||
private $renderer;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $_baseDomain;
|
||||
|
||||
public function __construct(array $config = []) {
|
||||
parent::__construct($config);
|
||||
|
||||
if ($this->_baseDomain === null) {
|
||||
$this->_baseDomain = Yii::$app->request->getHostInfo();
|
||||
if ($this->_baseDomain === null) {
|
||||
throw new InvalidConfigException('Cannot automatically obtain base domain');
|
||||
}
|
||||
}
|
||||
|
||||
$this->renderer = new Renderer($this->buildBasePath());
|
||||
}
|
||||
|
||||
public function setBaseDomain(string $baseDomain) {
|
||||
$this->_baseDomain = $baseDomain;
|
||||
$this->renderer->setBaseDomain($this->buildBasePath());
|
||||
}
|
||||
|
||||
public function getBaseDomain() : string {
|
||||
return $this->_baseDomain;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $templateName
|
||||
* @return TemplateBuilder
|
||||
*/
|
||||
public function getTemplate(string $templateName) : TemplateBuilder {
|
||||
return $this->renderer->getTemplate($templateName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TemplateBuilder $template
|
||||
* @throws \Ely\Email\RendererException
|
||||
* @return string
|
||||
*/
|
||||
public function render(TemplateBuilder $template) : string {
|
||||
return $this->renderer->render($template);
|
||||
}
|
||||
|
||||
private function buildBasePath() : string {
|
||||
return $this->_baseDomain . $this->basePath;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user