Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
config.php
1<?php
3
7
13class Config
14{
15 const SIGHT_SALT = 'main_mail_callback';
16
18 protected $moduleId;
19
21 protected $entityType;
22
24 protected $entityId;
25
27 protected $id;
28
30 protected $host;
31
37 public function getModuleId()
38 {
39 return $this->moduleId;
40 }
41
49 public function setModuleId($moduleId)
50 {
51 if (empty($moduleId))
52 {
53 throw new ArgumentException('Parameters `$moduleId` required.');
54 }
55
56 $this->id = null;
57 $this->moduleId = $moduleId;
58 return $this;
59 }
60
66 public function getEntityType()
67 {
68 return $this->entityType;
69 }
70
79 public function setEntityType($entityType)
80 {
81 $this->id = null;
82 $this->entityType = $entityType ?: null;
83 return $this;
84 }
85
93 public function getEntityId()
94 {
95 return $this->entityId;
96 }
97
105 public function setEntityId($entityId)
106 {
107 if (empty($entityId))
108 {
109 throw new ArgumentException('Parameters `$entityId` required.');
110 }
111
112 $this->id = null;
113 $this->entityId = $entityId;
114 return $this;
115 }
116
123 public function setHost($host)
124 {
125 $this->host = $host;
126 return $this;
127 }
128
134 public function getHost()
135 {
136 return $this->host;
137 }
138
139
145 public function getId()
146 {
147 if (!$this->id)
148 {
149 $this->id = self::generateId(
150 $this->getModuleId(),
151 $this->getEntityType(),
152 $this->getEntityId()
153 );
154 }
155
156 return $this->id;
157 }
158
164 public function getSignature()
165 {
166 try
167 {
168 return (new Signer())->getSignature($this->getSignedString(), self::SIGHT_SALT);
169 }
170 catch (ArgumentTypeException $exception)
171 {
172 return null;
173 }
174 }
175
182 public function verifySignature($signature)
183 {
184 return (new Signer())->validate(
185 $this->getSignedString(),
186 $signature,
187 self::SIGHT_SALT
188 );
189 }
190
191 protected function getSignedString()
192 {
193 return $this->getId();
194 }
195
205 public static function generateId($moduleId, $entityType = null, $entityId)
206 {
207 $entityType = $entityType ?: '';
208 return base64_encode("$moduleId/$entityType/$entityId");
209 }
210
218 public function unpackId($id)
219 {
220 $id = base64_decode($id);
221 $list = explode('/', $id);
222 $this->setModuleId($list[0]);
223 $this->setEntityType($list[1]);
224 $this->setEntityId($list[2]);
225
226 return $this;
227 }
228}
static generateId($moduleId, $entityType=null, $entityId)
Definition config.php:205