Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
Error.php
1<?php
2
3namespace Bitrix\Im\V2;
4
6
8{
9 public const NOT_FOUND = 'NOT_FOUND';
10
11 protected string $description = '';
12
13 public function __construct(string $code, ...$args)
14 {
15 $message = null;
16 $description = null;
17 $customData = [];
18
19 if (!empty($args))
20 {
21 $message = isset($args[0]) && is_string($args[0]) ? $args[0] : null;
22 $description = isset($args[1]) && is_string($args[1]) ? $args[1] : null;
23 $inx = count($args) - 1;
24 $customData = isset($args[$inx]) && is_array($args[$inx]) ? $args[$inx] : [];
25 }
26
27 $replacements = [];
28 foreach ($customData as $key => $value)
29 {
30 $replacements["#{$key}#"] = $value;
31 }
32
33 if (!is_string($message))
34 {
35 $message = $this->loadErrorMessage($code, $replacements);
36 }
37
38 if (is_string($message) && mb_strlen($message) > 0 && !is_string($description))
39 {
40 $description = $this->loadErrorDescription($code, $replacements);
41 }
42
43 if (!is_string($message) || mb_strlen($message) === 0)
44 {
46 }
47
48 parent::__construct($message, $code, $customData);
49
50 if (is_string($description))
51 {
52 $this->setDescription($description);
53 }
54 }
55
56 public function getDescription(): string
57 {
58 return $this->description;
59 }
60
61 public function setDescription(string $description): void
62 {
63 $this->description = $description;
64 }
65
66 protected function loadErrorMessage($code, $replacements): string
67 {
68 return Loc::getMessage("ERROR_{$code}", $replacements) ?? '';
69 }
70
71 protected function loadErrorDescription($code, $replacements): string
72 {
73 return Loc::getMessage("ERROR_{$code}_DESC", $replacements) ?? '';
74 }
75}
string $description
Definition Error.php:11
setDescription(string $description)
Definition Error.php:61
const NOT_FOUND
Definition Error.php:9
__construct(string $code,... $args)
Definition Error.php:13
loadErrorMessage($code, $replacements)
Definition Error.php:66
loadErrorDescription($code, $replacements)
Definition Error.php:71
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29