Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
message.php
1<?php
8namespace Bitrix\Main\Sms;
9
11
13{
14 protected $sender;
15 protected $receiver;
16 protected $text;
17 protected $template;
18
19 public function __construct()
20 {
21 }
22
23 public static function createFromTemplate(Template $template, array $fields)
24 {
25 $message = new static();
26 $message->template = $template;
27
28 if(!isset($fields["SITE_NAME"]))
29 {
30 $fields["SITE_NAME"] = $template->getSites()->getAll()[0]->getSiteName();
31 if($fields["SITE_NAME"] == '')
32 {
33 $fields["SITE_NAME"] = Config\Option::get("main", "site_name");
34 }
35 }
36 if(!isset($fields["SERVER_NAME"]))
37 {
38 $fields["SERVER_NAME"] = $template->getSites()->getAll()[0]->getServerName();
39 if($fields["SERVER_NAME"] == '')
40 {
41 $fields["SERVER_NAME"] = Config\Option::get("main", "server_name");
42 }
43 }
44 if(!isset($fields["DEFAULT_SENDER"]))
45 {
46 $fields["DEFAULT_SENDER"] = Config\Option::get("main", "sms_default_sender");
47 }
48
49 $message
50 ->setSender(static::compile($template->getSender(), $fields))
51 ->setReceiver(static::compile($template->getReceiver(), $fields))
52 ->setText(static::compile($template->getMessage(), $fields));
53
54 return $message;
55 }
56
57 protected static function compile($string, array $fields)
58 {
59 foreach($fields as $field => $value)
60 {
61 $string = str_replace("#".$field."#", $value, $string);
62 }
63 return $string;
64 }
65
66 public function getSender()
67 {
68 return $this->sender;
69 }
70
71 public function getReceiver()
72 {
73 return $this->receiver;
74 }
75
76 public function getText()
77 {
78 return $this->text;
79 }
80
85 public function setSender($sender)
86 {
87 $this->sender = $sender;
88 return $this;
89 }
90
95 public function setReceiver($receiver)
96 {
97 $this->receiver = $receiver;
98 return $this;
99 }
100
105 public function setText($text)
106 {
107 $this->text = $text;
108 return $this;
109 }
110
114 public function getTemplate(): ?Template
115 {
116 return $this->template;
117 }
118}
setReceiver($receiver)
Definition message.php:95
static createFromTemplate(Template $template, array $fields)
Definition message.php:23
static compile($string, array $fields)
Definition message.php:57