{"id":338711,"date":"2022-09-24T21:00:17","date_gmt":"2022-09-24T21:00:17","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=338711"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=338711","title":{"rendered":"<span>\u0420\u0430\u0441\u0441\u044b\u043b\u043a\u0430 \u043f\u0438\u0441\u0435\u043c \u0447\u0435\u0440\u0435\u0437 Unione (php, Yii2)<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0412 \u0441\u0442\u0430\u0442\u044c\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u043a\u043e\u0434 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0438\u0439 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u043e\u043d\u043d\u044b\u0435 \u043f\u0438\u0441\u044c\u043c\u0430 \u0447\u0435\u0440\u0435\u0437 \u0441\u0435\u0440\u0432\u0438\u0441 unione, \u0434\u0435\u043b\u0430\u0442\u044c HTTP \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043a REST \u0430\u043f\u0438, \u0430 \u0442\u0430\u043a \u0436\u0435 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u043e\u0431\u044b\u0447\u043d\u044b\u0435 email \u043f\u043e smtp \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043e\u0431\u0449\u0438\u0439 \u043a\u043b\u0430\u0441\u0441 \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u0435\u043b\u044c \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439.<\/p>\n<p>\u0412 \u043d\u0430\u0448\u0435\u0439 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 (<a href=\"https:\/\/habr.com\/ru\/post\/688090\/\" rel=\"noopener noreferrer nofollow\">\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u041e\u041e\u041f \u043f\u043e\u0434\u0445\u043e\u0434\u0430 \u0434\u043b\u044f \u0440\u0430\u0441\u0441\u044b\u043b\u043a\u0438 \u043f\u0438\u0441\u0435\u043c \u0447\u0435\u0440\u0435\u0437 Unione (php, Yii2)<\/a>) \u043c\u044b \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043b\u0438 \u0431\u0430\u0437\u043e\u0432\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 Message \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u044f\u0441\u044c \u043e\u0442 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u0438\u0441\u044c\u043c\u043e \u0434\u043b\u044f \u0440\u0430\u0441\u0441\u044b\u043b\u043a\u0438 \u0447\u0435\u0440\u0435\u0437 \u0441\u0435\u0440\u0432\u0438\u0441 unione \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0432 \u0432 \u043d\u0430\u0441\u043b\u0435\u0434\u043d\u0438\u043a\u0430\u0445 \u043c\u0435\u0442\u043e\u0434\u044b \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043f\u043e\u0434\u0441\u0442\u0430\u043d\u043e\u0432\u043e\u043a \u0432 \u0448\u0430\u0431\u043b\u043e\u043d\u044b \u043f\u0438\u0441\u0435\u043c. \u0414\u043b\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u043f\u0438\u0441\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0441\u044f \u043c\u0435\u0442\u043e\u0434 Message::send \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c\u044b\u0439 \u043d\u0430 \u043e\u0431\u044a\u0435\u043a\u0442\u0435 \u043a\u043b\u0430\u0441\u0441\u0430 \u043d\u0430\u0441\u043b\u0435\u0434\u043d\u0438\u043a\u0430. \u0422\u0430\u043a\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u0441 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u043e\u0439 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0447\u0435\u0440\u0435\u0437 \u0441\u0430\u043c \u043a\u043b\u0430\u0441\u0441 \u043f\u0438\u0441\u044c\u043c\u0430 \u0432\u044b\u0437\u0432\u0430\u043b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u0443\u044e \u043a\u0440\u0438\u0442\u0438\u043a\u0443. <\/p>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043a\u043b\u0430\u0441\u0441 Message \u043f\u0435\u0440\u0435\u0440\u0430\u0431\u043e\u0442\u0430\u043d \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u043f\u0438\u0441\u044c\u043c\u043e \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0447\u0435\u0440\u0435\u0437 \u043e\u0431\u0449\u0438\u0439 \u043a\u043b\u0430\u0441\u0441 \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u0435\u043b\u044f. \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e \u043f\u0440\u0438\u0432\u0435\u0434\u0451\u043d \u043a\u043e\u0434 \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e  \u044d\u0442\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c email \u043f\u043e smtp, \u0430 \u0442\u0430\u043a \u0436\u0435 HTTP \u0437\u0430\u043f\u0440\u043e\u0441 \u043a REST \u0430\u043f\u0438.<\/p>\n<p>\u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 \u043f\u0438\u0441\u044c\u043c\u0430 \u0447\u0435\u0440\u0435\u0437 \u0441\u0435\u0440\u0432\u0438\u0441 unione \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u043e\u0439 HTTP \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043a REST \u0430\u043f\u0438 \u0441\u0435\u0440\u0432\u0438\u0441\u0430, \u0442\u043e \u0432 \u043d\u0430\u0447\u0430\u043b\u0435 \u0438\u043c\u0435\u0435\u0442 \u0441\u043c\u044b\u0441\u043b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0443 \u043b\u044e\u0431\u044b\u0445 HTTP \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432. \u0414\u043b\u044f \u0438\u0445 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043a\u043b\u0430\u0441\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0440\u0430\u0441\u0448\u0438\u0440\u0438\u0442 \u043a\u043b\u0430\u0441\u0441 yii\\httpclient\\Request \u0438 \u0438\u043c\u043f\u043b\u0435\u043c\u0435\u043d\u0442\u0438\u0440\u0443\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439 \u043d\u0430\u043c\u0438 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 app\\interfaces\\MessageInterface. <\/p>\n<pre><code class=\"php\">&lt;?php  namespace app\\models\\Email;  use app\\interfaces\\MessageInterface; use yii\\httpclient\\Client; use yii\\httpclient\\Request;  class RestMessage extends Request implements MessageInterface {     public function __construct(         Client $client,         $config = []     )     {         parent::__construct($config);         $this->client = $client;     }      public function composeMessage()     {         return $this->getData();     }      \/**      * {@inheritdoc}      *\/     public function setData($data)     {         $this->data = $data;         $data = $this->composeMessage();          return parent::setData($data);     } } <\/code><\/pre>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u043a\u043b\u0430\u0441\u0441\u0435 \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u0431\u0430\u0437\u043e\u0432\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 Request::setData \u0442\u0430\u043a \u0447\u0442\u043e\u0431\u044b \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u043b\u0438\u0441\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u0435\u0442\u043e\u0434\u0430 RestMessage::composeMessage. \u0422\u043e\u0433\u0434\u0430 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 HTTP GET \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043e\u0431\u0449\u0435\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u0435\u043b\u044f \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"php\">&lt;?php  $client = new RestClient(); $client->baseUrl = 'https:\/\/habr.com\/';  $restRequest = new RestMessage($client); $restRequest     ->setUrl('ru\/post\/688090\/');  $sender = new Sender($client); $res = $sender->send($restRequest);<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043d\u0430 \u0431\u0430\u0437\u043e\u0432\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 UnioneRestMessage \u0434\u043b\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u043f\u0438\u0441\u0435\u043c \u0447\u0435\u0440\u0435\u0437 \u0441\u0435\u0440\u0432\u0438\u0441 unione. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0443\u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u043c \u0435\u0433\u043e \u043e\u0442 RestMessage. \u0412\u043e\u0442 \u0435\u0433\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f:<\/p>\n<pre><code class=\"php\">&lt;?php  namespace app\\models\\Email;  use yii\\helpers\\ArrayHelper; use yii\\httpclient\\Client; use yii\\web\\View;  abstract class UnioneRestMessage extends RestMessage {     protected array  $data;     protected $template;     protected $templatePath;     protected $email;     protected $subject;     protected $from;     protected $sender;     protected $formatter;     protected $useTemplate;     protected $baseUrl;      \/**      * Determines properties to be extracted from input objects      * @return array      *\/     abstract public function getProperties(): array;      \/**      * Determines substitution array for unione message body      * @return array      *\/     abstract public function getSubstitutions(): array;     abstract public function getEmailOptions(): array;      \/**      * Constructor      *\/     public function __construct(         Client $client,         bool $useTemplate = false     )     {         parent::__construct($client);          $this->useTemplate  = $useTemplate;     }      public function composeMessage()     {         $this->prepareData($this->data);         $message = [             \"message\" => [                 \"recipients\"            => $this->recipients,                 \"subject\"               => $this->subject,                 \"from_email\"            => $this->from,                 \"from_name\"             => $this->sender,                 'global_substitutions'  => $this->getGlobalSubstitutions(),                 'options'               => $this->getOptions(),             ]         ];         if ($this->useTemplate) {             $message['message']['template_id'] = $this->template;          } else {             $message['message']['body'] = [                 \"html\"  => $this->render($this->templatePath)             ];         }         return $message;     }      \/**      * Prepares data to be input into a message      * @param $data      *\/     public function prepareData($data): void     {         $sub = ArrayHelper::toArray($data, $this->properties);         foreach ($sub as $el) {             foreach ($el as $key => $value) {                 $this->data[$key] = $value;             }         }     }      \/**      * Gets value from prepared data by the key      *\/     public function getSubstitution(string $name, string $email = null)     {         return $this->data[$name];     }      public function getGlobalSubstitution(array &amp;$data, string $name)     {         return $data[$name];     }      public function getRecipients(): array     {         $recipients = [             [                 \"email\"          => $this->email,                 \"substitutions\"  => $this->substitutions             ]         ];         return $recipients;     }      public function render(string  $path)     {         $view = new View();         return $view->renderFile($path, $this->getRenderVariables());     }      public function getGlobalSubstitutions(): array     {         return [];     }      public function prepareGlobalData(array $data): array     {         $sub = ArrayHelper::toArray($data, $this->globalProperties);         $subData = [];         foreach ($sub as $el) {             foreach ($el as $key => $value) {                 $subData[$key] = $value;             }         }         return $subData;     }      public function getRenderVariables(): array     {         return $this->getGlobalSubstitutions();     }      public function getBaseUrl()     {         return $this->baseUrl;     }      \/**      * @param mixed|string $templatePath      *\/     public function setTemplatePath($templatePath)     {         $this->templatePath = $templatePath;         return $this;     }      \/**      * @param mixed $email      *\/     public function setEmail($email)     {         $this->email = $email;         return $this;     }      \/**      * @param mixed $subject      *\/     public function setSubject($subject)     {         $this->subject = $subject;         return $this;     }      \/**      * @param mixed|string $from      *\/     public function setFrom($from)     {         $this->from = $from;         return $this;     }      \/**      * @param mixed|string $sender      *\/     public function setSender($sender)     {         $this->sender = $sender;         return $this;     }      \/**      * @param mixed|string $formatter      *\/     public function setFormatter($formatter)     {         $this->formatter = $formatter;         return $this;     }      \/**      * @param mixed|string $apiKey      *\/     public function setApiKey($apiKey)     {         $this->getHeaders()->set('X-API-KEY', \"{$apiKey}\");         return $this;     } }<\/code><\/pre>\n<p>\u0412 \u044d\u0442\u043e\u043c \u043a\u043b\u0430\u0441\u0441\u0435 \u043a\u0430\u043a \u043c\u044b \u0432\u0438\u0434\u0438\u043c \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u043c\u0435\u0442\u043e\u0434 RestMessage::composeMessage \u0442\u0430\u043a \u0447\u0442\u043e\u0431\u044b \u0432 \u043e\u0431\u0449\u0435\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0442\u0435\u043b\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043a \u0430\u043f\u0438 \u0441\u0435\u0440\u0432\u0438\u0441\u0430, \u0430 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432\u044b\u043d\u0435\u0441\u0435\u043d\u043e \u0432 \u043a\u043b\u0430\u0441\u0441\u044b \u043d\u0430\u0441\u043b\u0435\u0434\u043d\u0438\u043a\u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u0435 \u0441\u043e\u0431\u043e\u0439 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0435 \u0442\u0438\u043f\u044b \u043f\u0438\u0441\u0435\u043c, \u0447\u0435\u0440\u0435\u0437 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u043d\u044b\u0435 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u044b\u043c\u0438 \u043c\u0435\u0442\u043e\u0434\u044b UnioneRestMessage::getProperties \u0438 UnioneRestMessage::getSubstitutions. \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u043f\u043e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044e \u0441 \u043a\u043b\u0430\u0441\u0441\u043e\u043c Message \u0442\u0443\u0442 \u0442\u0430\u043a\u0436\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u044b \u043c\u0435\u0442\u043e\u0434\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0440\u0430\u043d\u044c\u0448\u0435 \u0431\u044b\u043b\u0438 \u0432 UniOneService \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a setSubject, setFrom, setSender \u0438 \u0442.\u0434.<\/p>\n<p>\u0414\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u0431\u044b\u043b\u043e \u043f\u043e\u043d\u044f\u0442\u043d\u043e \u043a\u0430\u043a \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u0430\u043d\u043d\u044b\u043c \u0431\u0430\u0437\u043e\u0432\u044b\u043c \u043a\u043b\u0430\u0441\u0441\u043e\u043c \u0445\u043e\u0442\u0438\u043c \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u043f\u0438\u0441\u044c\u043c\u0430 \u043e\u0431 \u0443\u0441\u043f\u0435\u0448\u043d\u043e\u0439 \u0438\u043d\u0432\u0435\u0441\u0442\u0438\u0446\u0438\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0432 \u043f\u0440\u043e\u0435\u043a\u0442.<\/p>\n<pre><code class=\"php\">&lt;?php  namespace app\\models\\Email;  use app\\models\\Investment\\InvestmentReserve; use app\\models\\User\\User; use Yii;  class NewReserveMailRestMessage extends UnioneRestMessage {      \/**      * @inheritDoc      *\/     public function getProperties(): array     {         return [             User::class => [                 'fullname' => function (User $user) {                     return $user->fullName;                 },                 'user_funds' => function (User $user) {                     $reserved = array_reduce($user->activeInvestmentReserves, function (int $sum, InvestmentReserve $reserve) {                         return $sum + $reserve->amount;                     }, 0);                     return $this->formatter->asDecimal(($user->userFunds->amount - $reserved)\/100, 2);                 }             ],             InvestmentReserve::class => [                 'amount' => function (InvestmentReserve $reserve) {                     return $this->formatter->asDecimal($reserve->amount \/ 100, 2);                 },                 'id_label' => function (InvestmentReserve $reserve) {                     return $reserve->project->id_label;                 },                 'country' => function (InvestmentReserve $reserve) {                     return $reserve->project->country->country;                 },                 'target' => function (InvestmentReserve $reserve) {                     return $this->formatter->asDecimal($reserve->project->amount, 2);                 },                 'loan' => function (InvestmentReserve $reserve) {                     return $reserve->project->loan_period;                 },                 'rate' => function (InvestmentReserve $reserve) {                     return $reserve->project->profitability;                 },                 'image' => function (InvestmentReserve $reserve) {                     $base = Yii::$app->params['api_url'];                     return $base . $reserve->project->image;                 },                 'left' => function (InvestmentReserve $reserve) {                     return $this->formatter->asDecimal($reserve->project->availableAmount->available_amount, 2);                 },                 'name' => function (InvestmentReserve $reserve) {                     return $reserve->project->name;                 },                 'label' => function (InvestmentReserve $reserve) {                     return $reserve->project->id_label;                 }             ]         ];     }      \/**      * @inheritDoc      *\/     public function getSubstitutions(): array     {         $baseUrl = Yii::$app->params['front_url'];         $apiBaseUrl = Yii::$app->params['api_url'];         return [             \"Name\"               => $this->getSubstitution('fullname'),             \"Invested_amount\"    => $this->getSubstitution('amount'),             \"P1_label\"           => $this->getSubstitution('id_label'),             \"P1_name\"            => $this->getSubstitution('name'),             \"P1_where\"           => $this->getSubstitution('country'),             \"P1_left\"            => $this->getSubstitution('left'),             \"P1_target\"          => $this->getSubstitution('target'),             \"P1_loan_period\"     => $this->getSubstitution('loan'),             \"P1_interest_rate\"   => $this->getSubstitution('rate'),             \"P1_link_img\"        => $this->getSubstitution('image'),             \"Account_balance\"    => $this->getSubstitution('user_funds'),             'api_url'            => $apiBaseUrl,             'front_url'          => $baseUrl,             'P1_link'            => $baseUrl . '\/projects\/project\/' . $this->getSubstitution('id_label'),             'logo'               => $baseUrl . '\/images\/Maclear.svg'         ];     }      public function getEmailOptions(): array     {         return [];     } }<\/code><\/pre>\n<p>\u041c\u0435\u0442\u043e\u0434 $this->getSubstitution \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u044f \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u0432 \u043c\u0435\u0442\u043e\u0434\u0435 getProperties.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u044d\u0442\u043e \u043f\u0438\u0441\u044c\u043c\u043e \u0447\u0435\u0440\u0435\u0437 \u0441\u0435\u0440\u0432\u0438\u0441 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"php\">&lt;?php  $investment = InvestmentReserve::findOne(102); $project    = $investment->project; $user       = $investment->user;  $subject = \"You invested in the Project \\\"$project->name\\\" $project->id_label\";  $client = new RestClient(); $client->baseUrl = 'https:\/\/eu1.unione.io\/en\/transactional\/api\/v1\/'; $newReserveMail = new NewReserveMailRestMessage($client); $newReserveMail     ->setMethod('POST')     ->setUrl('email\/send.json')     ->setFormat(Client::FORMAT_JSON)     ->setApiKey('secret')     ->setFormatter(Yii::$app->formatter)     ->setSender('Company name')     ->setFrom('email@address.com')     ->setSubject($subject)     ->setEmail($user->email)     ->setTemplatePath('\/app\/mail\/unione\/user\/letter_reserve.php')     ->setData([$user, $investment])    $sender = new Sender($client);   $res = $sender->send($newReserveMail);<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u043c\u0435\u0442\u043e\u0434\u044b setMethod, setUrl \u0438 setFormat \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u044e\u0442\u0441\u044f \u043e\u0442 yii\\httpclient\\Request, setData \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d \u0432 RestMessage, \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0432 UnioneRestMessage.<\/p>\n<p>\u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043b\u0430\u0441\u0441\u0430 UnioneRestMessage \u043c\u043e\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043f\u0438\u0441\u044c\u043c\u0430 \u0434\u043b\u044f \u0440\u0430\u0441\u0441\u044b\u043b\u043a\u0438 \u0447\u0435\u0440\u0435\u0437 \u0441\u0435\u0440\u0432\u0438\u0441 \u0440\u0430\u0441\u0441\u044b\u043b\u043e\u043a unione \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u044f\u0441\u044c \u043e\u0442 \u043d\u0435\u0433\u043e \u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044f \u043c\u0435\u0442\u043e\u0434\u044b getProperties \u0438 getSubstitutions \u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0438\u0445 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043e\u0431\u0449\u0435\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u0435\u043b\u044f Sender \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u0430 \u043b\u043e\u0433\u0438\u043a\u0430 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 HTTP \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 (\u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432). \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u044d\u0442\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 Sender \u043c\u043e\u0436\u043d\u043e \u0442\u0430\u043a\u0436\u0435 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0438 email \u043f\u043e smtp. \u0412\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440 \u043a\u0430\u043a \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c:<\/p>\n<pre><code class=\"php\">&lt;?php  $client = Yii::$app->mailer;  $emailMessage = new MailMessage(); $emailMessage     ->setFrom('from@email.ru')     ->setTo('to@email.ru')     ->setSubject('Hi there')     ->setTextBody('Test message');  $sender = new Sender($client); $res = $sender->send($emailMessage);<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c MailMessage \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u0431\u0451\u0440\u0442\u043a\u0430 \u043d\u0430\u0434 yii\\swiftmailer\\Message \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0449\u0430\u044f \u043d\u0430\u0448 app\\interfaces\\MessageInterface<\/p>\n<pre><code class=\"php\">&lt;?php &lt;?php  namespace app\\models\\Email;  class MailMessage extends \\yii\\swiftmailer\\Message implements \\app\\interfaces\\MessageInterface {  }<\/code><\/pre>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043b\u0430\u0441\u0441\u0430 Sender \u043c\u044b \u0441\u043c\u043e\u0433\u043b\u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0438 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u043a http \u0440\u0435\u0441\u0443\u0440\u0441\u0443, \u0438 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043b\u0435\u043d\u043d\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u043a \u0441\u0435\u0440\u0432\u0438\u0441\u0443 unione, \u0438 email \u043f\u043e smtp. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0432 \u0437\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0435\u0433\u043e \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u0443\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0434\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u0438\u043c\u0435\u0440 \u0441 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u043e\u0439 \u043f\u0438\u0441\u0435\u043c \u0447\u0435\u0440\u0435\u0437 unione \u0431\u044b\u043b \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0440\u0430\u0431\u043e\u0447\u0438\u043c. <\/p>\n<pre><code class=\"php\">&lt;?php  namespace app\\services\\backend\\email;  use app\\interfaces\\MessageInterface; use app\\interfaces\\RestSenderInterface; use app\\models\\Email\\MailMessage; use app\\models\\Email\\RestMessage; use app\\models\\Email\\UnioneRestMessage; use app\\services\\backend\\infrastructure\\ClientInterface; use yii\\httpclient\\Client;  class Sender implements RestSenderInterface {     \/** @var Client $client *\/     private $client;      public function __construct(ClientInterface $client)     {          $this->client = $client;     }      public function send(MessageInterface $message)     {         \/** @var RestMessage|UnioneRestMessage|MailMessage $message *\/         return $this->client->send($message);     } }<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u0442\u0441\u044f \u043e\u0431\u044a\u0435\u043a\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0449\u0438\u0439 \u043d\u0430\u0448 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \\app\\services\\backend\\infrastructure\\ClientInterface, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0434\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u043b\u0438 \u0434\u043b\u044f \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430 Yii2 \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0438\u0445 yii\\httpclient\\Client \u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u043c\u0435\u0439\u043b\u0435\u0440\u0430 \u0442\u0430\u043a \u0447\u0442\u043e\u0431\u044b \u043e\u043d\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u043b\u0438 \u044d\u0442\u043e\u0442 ClientInterface \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c.<\/p>\n<pre><code class=\"php\">\/\/ http client &lt;?php  namespace app\\services\\backend\\infrastructure;  use yii\\httpclient\\Client;  class RestClient extends Client implements ClientInterface {  } \/\/ email client &lt;?php  namespace app\\services\\backend\\email;  use app\\services\\backend\\infrastructure\\ClientInterface; use yii\\swiftmailer\\Mailer;  class MailSender extends Mailer implements ClientInterface {     public function send($message)     {         $this->sendMessage($message);     } }<\/code><\/pre>\n<p>\u0410 \u0434\u043b\u044f \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 \u043c\u0435\u0439\u043b\u0435\u0440\u0430 \u0435\u0449\u0451 \u0438 \u043f\u043e\u0434\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 \u043c\u0435\u0439\u043b\u0435\u0440\u0430 \u0432 \u043a\u043e\u043d\u0444\u0438\u0433\u0435.<\/p>\n<pre><code class=\"php\">&lt;?php  use app\\services\\backend\\email\\MailSender; \/\/ \u041a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f ... 'mailer' => [         'class'            => MailSender::class, \/\/        'class'            => 'yii\\swiftmailer\\Mailer',         'useFileTransport' => false,         'htmlLayout'       => 'layouts\/html',         'transport'        => [...],     ],<\/code><\/pre>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/689968\/\"> https:\/\/habr.com\/ru\/post\/689968\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0412 \u0441\u0442\u0430\u0442\u044c\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u043a\u043e\u0434 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0438\u0439 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u043e\u043d\u043d\u044b\u0435 \u043f\u0438\u0441\u044c\u043c\u0430 \u0447\u0435\u0440\u0435\u0437 \u0441\u0435\u0440\u0432\u0438\u0441 unione, \u0434\u0435\u043b\u0430\u0442\u044c HTTP \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043a REST \u0430\u043f\u0438, \u0430 \u0442\u0430\u043a \u0436\u0435 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u043e\u0431\u044b\u0447\u043d\u044b\u0435 email \u043f\u043e smtp \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043e\u0431\u0449\u0438\u0439 \u043a\u043b\u0430\u0441\u0441 \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u0435\u043b\u044c \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439.<\/p>\n<p>\u0412 \u043d\u0430\u0448\u0435\u0439 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 (<a href=\"https:\/\/habr.com\/ru\/post\/688090\/\" rel=\"noopener noreferrer nofollow\">\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u041e\u041e\u041f \u043f\u043e\u0434\u0445\u043e\u0434\u0430 \u0434\u043b\u044f \u0440\u0430\u0441\u0441\u044b\u043b\u043a\u0438 \u043f\u0438\u0441\u0435\u043c \u0447\u0435\u0440\u0435\u0437 Unione (php, Yii2)<\/a>) \u043c\u044b \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043b\u0438 \u0431\u0430\u0437\u043e\u0432\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 Message \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u044f\u0441\u044c \u043e\u0442 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u0438\u0441\u044c\u043c\u043e \u0434\u043b\u044f \u0440\u0430\u0441\u0441\u044b\u043b\u043a\u0438 \u0447\u0435\u0440\u0435\u0437 \u0441\u0435\u0440\u0432\u0438\u0441 unione \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0432 \u0432 \u043d\u0430\u0441\u043b\u0435\u0434\u043d\u0438\u043a\u0430\u0445 \u043c\u0435\u0442\u043e\u0434\u044b \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043f\u043e\u0434\u0441\u0442\u0430\u043d\u043e\u0432\u043e\u043a \u0432 \u0448\u0430\u0431\u043b\u043e\u043d\u044b \u043f\u0438\u0441\u0435\u043c. \u0414\u043b\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u043f\u0438\u0441\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0441\u044f \u043c\u0435\u0442\u043e\u0434 Message::send \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c\u044b\u0439 \u043d\u0430 \u043e\u0431\u044a\u0435\u043a\u0442\u0435 \u043a\u043b\u0430\u0441\u0441\u0430 \u043d\u0430\u0441\u043b\u0435\u0434\u043d\u0438\u043a\u0430. \u0422\u0430\u043a\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u0441 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u043e\u0439 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0447\u0435\u0440\u0435\u0437 \u0441\u0430\u043c \u043a\u043b\u0430\u0441\u0441 \u043f\u0438\u0441\u044c\u043c\u0430 \u0432\u044b\u0437\u0432\u0430\u043b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u0443\u044e \u043a\u0440\u0438\u0442\u0438\u043a\u0443. <\/p>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043a\u043b\u0430\u0441\u0441 Message \u043f\u0435\u0440\u0435\u0440\u0430\u0431\u043e\u0442\u0430\u043d \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u043f\u0438\u0441\u044c\u043c\u043e \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0447\u0435\u0440\u0435\u0437 \u043e\u0431\u0449\u0438\u0439 \u043a\u043b\u0430\u0441\u0441 \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u0435\u043b\u044f. \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e \u043f\u0440\u0438\u0432\u0435\u0434\u0451\u043d \u043a\u043e\u0434 \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e  \u044d\u0442\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c email \u043f\u043e smtp, \u0430 \u0442\u0430\u043a \u0436\u0435 HTTP \u0437\u0430\u043f\u0440\u043e\u0441 \u043a REST \u0430\u043f\u0438.<\/p>\n<p>\u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 \u043f\u0438\u0441\u044c\u043c\u0430 \u0447\u0435\u0440\u0435\u0437 \u0441\u0435\u0440\u0432\u0438\u0441 unione \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u043e\u0439 HTTP \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043a REST \u0430\u043f\u0438 \u0441\u0435\u0440\u0432\u0438\u0441\u0430, \u0442\u043e \u0432 \u043d\u0430\u0447\u0430\u043b\u0435 \u0438\u043c\u0435\u0435\u0442 \u0441\u043c\u044b\u0441\u043b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0443 \u043b\u044e\u0431\u044b\u0445 HTTP \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432. \u0414\u043b\u044f \u0438\u0445 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043a\u043b\u0430\u0441\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0440\u0430\u0441\u0448\u0438\u0440\u0438\u0442 \u043a\u043b\u0430\u0441\u0441 yii\\httpclient\\Request \u0438 \u0438\u043c\u043f\u043b\u0435\u043c\u0435\u043d\u0442\u0438\u0440\u0443\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439 \u043d\u0430\u043c\u0438 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 app\\interfaces\\MessageInterface. <\/p>\n<pre><code class=\"php\">&lt;?php  namespace app\\models\\Email;  use app\\interfaces\\MessageInterface; use yii\\httpclient\\Client; use yii\\httpclient\\Request;  class RestMessage extends Request implements MessageInterface {     public function __construct(         Client $client,         $config = []     )     {         parent::__construct($config);         $this->client = $client;     }      public function composeMessage()     {         return $this->getData();     }      \/**      * {@inheritdoc}      *\/     public function setData($data)     {         $this->data = $data;         $data = $this->composeMessage();          return parent::setData($data);     } } <\/code><\/pre>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u043a\u043b\u0430\u0441\u0441\u0435 \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u0431\u0430\u0437\u043e\u0432\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 Request::setData \u0442\u0430\u043a \u0447\u0442\u043e\u0431\u044b \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u043b\u0438\u0441\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u0435\u0442\u043e\u0434\u0430 RestMessage::composeMessage. \u0422\u043e\u0433\u0434\u0430 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 HTTP GET \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043e\u0431\u0449\u0435\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u0435\u043b\u044f \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"php\">&lt;?php  $client = new RestClient(); $client->baseUrl = 'https:\/\/habr.com\/';  $restRequest = new RestMessage($client); $restRequest     ->setUrl('ru\/post\/688090\/');  $sender = new Sender($client); $res = $sender->send($restRequest);<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043d\u0430 \u0431\u0430\u0437\u043e\u0432\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 UnioneRestMessage \u0434\u043b\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u043f\u0438\u0441\u0435\u043c \u0447\u0435\u0440\u0435\u0437 \u0441\u0435\u0440\u0432\u0438\u0441 unione. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0443\u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u043c \u0435\u0433\u043e \u043e\u0442 RestMessage. \u0412\u043e\u0442 \u0435\u0433\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f:<\/p>\n<pre><code class=\"php\">&lt;?php  namespace app\\models\\Email;  use yii\\helpers\\ArrayHelper; use yii\\httpclient\\Client; use yii\\web\\View;  abstract class UnioneRestMessage extends RestMessage {     protected array  $data;     protected $template;     protected $templatePath;     protected $email;     protected $subject;     protected $from;     protected $sender;     protected $formatter;     protected $useTemplate;     protected $baseUrl;      \/**      * Determines properties to be extracted from input objects      * @return array      *\/     abstract public function getProperties(): array;      \/**      * Determines substitution array for unione message body      * @return array      *\/     abstract public function getSubstitutions(): array;     abstract public function getEmailOptions(): array;      \/**      * Constructor      *\/     public function __construct(         Client $client,         bool $useTemplate = false     )     {         parent::__construct($client);          $this->useTemplate  = $useTemplate;     }      public function composeMessage()     {         $this->prepareData($this->data);         $message = [             \"message\" => [                 \"recipients\"            => $this->recipients,                 \"subject\"               => $this->subject,                 \"from_email\"            => $this->from,                 \"from_name\"             => $this->sender,                 'global_substitutions'  => $this->getGlobalSubstitutions(),                 'options'               => $this->getOptions(),             ]         ];         if ($this->useTemplate) {             $message['message']['template_id'] = $this->template;          } else {             $message['message']['body'] = [                 \"html\"  => $this->render($this->templatePath)             ];         }         return $message;     }      \/**      * Prepares data to be input into a message      * @param $data      *\/     public function prepareData($data): void     {         $sub = ArrayHelper::toArray($data, $this->properties);         foreach ($sub as $el) {             foreach ($el as $key => $value) {                 $this->data[$key] = $value;             }         }     }      \/**      * Gets value from prepared data by the key      *\/     public function getSubstitution(string $name, string $email = null)     {         return $this->data[$name];     }      public function getGlobalSubstitution(array &amp;$data, string $name)     {         return $data[$name];     }      public function getRecipients(): array     {         $recipients = [             [                 \"email\"          => $this->email,                 \"substitutions\"  => $this->substitutions             ]         ];         return $recipients;     }      public function render(string  $path)     {         $view = new View();         return $view->renderFile($path, $this->getRenderVariables());     }      public function getGlobalSubstitutions(): array     {         return [];     }      public function prepareGlobalData(array $data): array     {         $sub = ArrayHelper::toArray($data, $this->globalProperties);         $subData = [];         foreach ($sub as $el) {             foreach ($el as $key => $value) {                 $subData[$key] = $value;             }         }         return $subData;     }      public function getRenderVariables(): array     {         return $this->getGlobalSubstitutions();     }      public function getBaseUrl()     {         return $this->baseUrl;     }      \/**      * @param mixed|string $templatePath      *\/     public function setTemplatePath($templatePath)     {         $this->templatePath = $templatePath;         return $this;     }      \/**      * @param mixed $email      *\/     public function setEmail($email)     {         $this->email = $email;         return $this;     }      \/**      * @param mixed $subject      *\/     public function setSubject($subject)     {         $this->subject = $subject;         return $this;     }      \/**      * @param mixed|string $from      *\/     public function setFrom($from)     {         $this->from = $from;         return $this;     }      \/**      * @param mixed|string $sender      *\/     public function setSender($sender)     {         $this->sender = $sender;         return $this;     }      \/**      * @param mixed|string $formatter      *\/     public function setFormatter($formatter)     {         $this->formatter = $formatter;         return $this;     }      \/**      * @param mixed|string $apiKey      *\/     public function setApiKey($apiKey)     {         $this->getHeaders()->set('X-API-KEY', \"{$apiKey}\");         return $this;     } }<\/code><\/pre>\n<p>\u0412 \u044d\u0442\u043e\u043c \u043a\u043b\u0430\u0441\u0441\u0435 \u043a\u0430\u043a \u043c\u044b \u0432\u0438\u0434\u0438\u043c \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u043c\u0435\u0442\u043e\u0434 RestMessage::composeMessage \u0442\u0430\u043a \u0447\u0442\u043e\u0431\u044b \u0432 \u043e\u0431\u0449\u0435\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0442\u0435\u043b\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043a \u0430\u043f\u0438 \u0441\u0435\u0440\u0432\u0438\u0441\u0430, \u0430 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432\u044b\u043d\u0435\u0441\u0435\u043d\u043e \u0432 \u043a\u043b\u0430\u0441\u0441\u044b \u043d\u0430\u0441\u043b\u0435\u0434\u043d\u0438\u043a\u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u0435 \u0441\u043e\u0431\u043e\u0439 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0435 \u0442\u0438\u043f\u044b \u043f\u0438\u0441\u0435\u043c, \u0447\u0435\u0440\u0435\u0437 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u043d\u044b\u0435 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u044b\u043c\u0438 \u043c\u0435\u0442\u043e\u0434\u044b UnioneRestMessage::getProperties \u0438 UnioneRestMessage::getSubstitutions. \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u043f\u043e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044e \u0441 \u043a\u043b\u0430\u0441\u0441\u043e\u043c Message \u0442\u0443\u0442 \u0442\u0430\u043a\u0436\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u044b \u043c\u0435\u0442\u043e\u0434\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0440\u0430\u043d\u044c\u0448\u0435 \u0431\u044b\u043b\u0438 \u0432 UniOneService \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a setSubject, setFrom, setSender \u0438 \u0442.\u0434.<\/p>\n<p>\u0414\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u0431\u044b\u043b\u043e \u043f\u043e\u043d\u044f\u0442\u043d\u043e \u043a\u0430\u043a \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u0430\u043d\u043d\u044b\u043c \u0431\u0430\u0437\u043e\u0432\u044b\u043c \u043a\u043b\u0430\u0441\u0441\u043e\u043c \u0445\u043e\u0442\u0438\u043c \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u043f\u0438\u0441\u044c\u043c\u0430 \u043e\u0431 \u0443\u0441\u043f\u0435\u0448\u043d\u043e\u0439 \u0438\u043d\u0432\u0435\u0441\u0442\u0438\u0446\u0438\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0432 \u043f\u0440\u043e\u0435\u043a\u0442.<\/p>\n<pre><code class=\"php\">&lt;?php  namespace app\\models\\Email;  use app\\models\\Investment\\InvestmentReserve; use app\\models\\User\\User; use Yii;  class NewReserveMailRestMessage extends UnioneRestMessage {      \/**      * @inheritDoc      *\/     public function getProperties(): array     {         return [             User::class => [                 'fullname' => function (User $user) {                     return $user->fullName;                 },                 'user_funds' => function (User $user) {                     $reserved = array_reduce($user->activeInvestmentReserves, function (int $sum, InvestmentReserve $reserve) {                         return $sum + $reserve->amount;                     }, 0);                     return $this->formatter->asDecimal(($user->userFunds->amount - $reserved)\/100, 2);                 }             ],             InvestmentReserve::class => [                 'amount' => function (InvestmentReserve $reserve) {                     return $this->formatter->asDecimal($reserve->amount \/ 100, 2);                 },                 'id_label' => function (InvestmentReserve $reserve) {                     return $reserve->project->id_label;                 },                 'country' => function (InvestmentReserve $reserve) {                     return $reserve->project->country->country;                 },                 'target' => function (InvestmentReserve $reserve) {                     return $this->formatter->asDecimal($reserve->project->amount, 2);                 },                 'loan' => function (InvestmentReserve $reserve) {                     return $reserve->project->loan_period;                 },                 'rate' => function (InvestmentReserve $reserve) {                     return $reserve->project->profitability;                 },                 'image' => function (InvestmentReserve $reserve) {                     $base = Yii::$app->params['api_url'];                     return $base . $reserve->project->image;                 },                 'left' => function (InvestmentReserve $reserve) {                     return $this->formatter->asDecimal($reserve->project->availableAmount->available_amount, 2); <\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-338711","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/338711","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=338711"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/338711\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=338711"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=338711"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=338711"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}