Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
classconstant.php
1<?php
9
12
13Loc::loadMessages(__FILE__);
14
20{
27 public static function getName($id)
28 {
29 static $integration = [];
30 $integration[static::class] ??= null;
31
32 if ($integration[static::class] === null)
33 {
34 $integration[static::class] = Integration\EventHandler::onConstantList(get_called_class());
35 }
36
37 foreach ($integration[static::class] as $item)
38 {
39 if ($item['id'] === $id)
40 {
41 return $item['name'];
42 }
43 }
44
45 return static::getCode($id);
46 }
47
53 protected static function getConstants()
54 {
55 static $constants = [];
56 $constants[static::class] ??= null;
57
58 if ($constants[static::class] === null)
59 {
60 $class = new \ReflectionClass(get_called_class());
61 $list = $class->getConstants();
62
63 $integration = Integration\EventHandler::onConstantList(get_called_class());
64 foreach ($integration as $item)
65 {
66 $list[$item['code']] = $item['id'];
67 }
68
69 $constants[static::class] = $list;
70 }
71
72 return $constants[static::class];
73 }
74
80 public static function getList()
81 {
82 $result = array();
83 $constants = static::getConstants();
84 foreach ($constants as $code => $id)
85 {
86 $result[] = $id;
87 }
88 return $result;
89 }
90
96 public static function getCodes()
97 {
98 $result = array();
99 $constants = static::getConstants();
100 foreach ($constants as $code => $id)
101 {
102 $result[] = $code;
103 }
104 return $result;
105 }
106
112 public static function getNamedList()
113 {
114 $result = array();
115 $constants = static::getConstants();
116 foreach ($constants as $code => $id)
117 {
118 $result[$id] = static::getName($id);
119 }
120 return $result;
121 }
122
128 public static function getNamedCodes()
129 {
130 $result = array();
131 $constants = static::getConstants();
132 foreach ($constants as $code => $id)
133 {
134 $result[$code] = static::getName($id);
135 }
136 return $result;
137 }
138
145 public static function getId($code)
146 {
147 $constants = static::getConstants();
148 return isset($constants[$code]) ? $constants[$code] : null;
149 }
150
157 public static function getCode($id)
158 {
159 $constants = static::getConstants();
160 foreach ($constants as $constantCode => $constantId)
161 {
162 if ($constantId != $id)
163 {
164 continue;
165 }
166
167 return $constantCode;
168 }
169
170 return null;
171 }
172}
static loadMessages($file)
Definition loc.php:64