1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
configuration.php
См. документацию.
1<?php
2
4
7
8final class Configuration implements \ArrayAccess, \Iterator, \Countable
9{
10 const CONFIGURATION_FILE = '.settings.php';
11 const CONFIGURATION_FILE_EXTRA = '.settings_extra.php';
13 const CONFIGURATION_FILE_PATH = '/bitrix/' . self::CONFIGURATION_FILE;
14
18 private static array $instances = [];
19 private ?string $moduleId = null;
20 private ?array $storedData = null;
21 private array $data = [];
22 private bool $isLoaded = false;
23
24 public static function getValue($name)
25 {
26 $configuration = Configuration::getInstance();
27 return $configuration->get($name);
28 }
29
30 public static function setValue($name, $value): void
31 {
32 $configuration = Configuration::getInstance();
33 $configuration->add($name, $value);
34 $configuration->saveConfiguration();
35 }
36
37 private function __construct($moduleId = null)
38 {
39 if ($moduleId !== null)
40 {
41 $this->moduleId = preg_replace("/[^a-zA-Z0-9_.]+/i", "", trim($moduleId));
42 }
43 }
44
45 public static function getInstance($moduleId = null): self
46 {
47 if (!isset(self::$instances[$moduleId]))
48 {
49 self::$instances[$moduleId] = new self($moduleId);
50 }
51
52 return self::$instances[$moduleId];
53 }
54
55 private static function getPathConfigForModule($moduleId): ?string
56 {
58 {
59 return null;
60 }
61
62 $moduleConfigPath = Loader::getLocal("modules/{$moduleId}/.settings.php");
63 if ($moduleConfigPath === false)
64 {
65 return null;
66 }
67
68 return $moduleConfigPath;
69 }
70
71 private function loadConfiguration(): void
72 {
73 $this->isLoaded = false;
74
75 if ($this->moduleId)
76 {
77 $path = self::getPathConfigForModule($this->moduleId);
78 if ($path !== null && file_exists($path))
79 {
80 $dataTmp = include $path;
81 if (is_array($dataTmp))
82 {
83 $this->data = $dataTmp;
84 }
85 }
86 }
87 else
88 {
89 if (($path = Loader::getLocal(self::CONFIGURATION_FILE)) !== false)
90 {
91 $dataTmp = include $path;
92 if (is_array($dataTmp))
93 {
94 $this->data = $dataTmp;
95 }
96 }
97
98 if (($pathExtra = Loader::getLocal(self::CONFIGURATION_FILE_EXTRA)) !== false)
99 {
100 $dataTmp = include $pathExtra;
101 if (is_array($dataTmp) && !empty($dataTmp))
102 {
103 $this->storedData = $this->data;
104 foreach ($dataTmp as $k => $v)
105 {
106 $this->data[$k] = $v;
107 }
108 }
109 }
110 }
111
112 $this->isLoaded = true;
113 }
114
115 public function saveConfiguration(): void
116 {
117 if (!$this->isLoaded)
118 {
119 $this->loadConfiguration();
120 }
121
122 if ($this->moduleId)
123 {
124 throw new Main\InvalidOperationException('There is no support to rewrite .settings.php in module');
125 }
126 else
127 {
128 $path = Loader::getLocal(self::CONFIGURATION_FILE);
129 }
130
131 $data = ($this->storedData !== null) ? $this->storedData : $this->data;
132 $data = var_export($data, true);
133
134 if (!is_writable($path))
135 {
136 @chmod($path, 0644);
137 }
138 file_put_contents($path, "<" . "?php\nreturn " . $data . ";\n");
139 }
140
141 public function add($name, $value): void
142 {
143 if (!$this->isLoaded)
144 {
145 $this->loadConfiguration();
146 }
147
148 if (!isset($this->data[$name]) || !$this->data[$name]["readonly"])
149 {
150 $this->data[$name] = ["value" => $value, "readonly" => false];
151 }
152 if (($this->storedData !== null) && (!isset($this->storedData[$name]) || !$this->storedData[$name]["readonly"]))
153 {
154 $this->storedData[$name] = ["value" => $value, "readonly" => false];
155 }
156 }
157
166 public function addReadonly($name, $value): void
167 {
168 if (!$this->isLoaded)
169 {
170 $this->loadConfiguration();
171 }
172
173 $this->data[$name] = ["value" => $value, "readonly" => true];
174 if ($this->storedData !== null)
175 {
176 $this->storedData[$name] = ["value" => $value, "readonly" => true];
177 }
178 }
179
180 public function delete($name): void
181 {
182 if (!$this->isLoaded)
183 {
184 $this->loadConfiguration();
185 }
186
187 if (isset($this->data[$name]) && !$this->data[$name]["readonly"])
188 {
189 unset($this->data[$name]);
190 }
191 if (($this->storedData !== null) && isset($this->storedData[$name]) && !$this->storedData[$name]["readonly"])
192 {
193 unset($this->storedData[$name]);
194 }
195 }
196
197 public function get($name)
198 {
199 if (!$this->isLoaded)
200 {
201 $this->loadConfiguration();
202 }
203
204 if (isset($this->data[$name]['value']))
205 {
206 return $this->data[$name]['value'];
207 }
208
209 return null;
210 }
211
212 public function offsetExists($offset): bool
213 {
214 if (!$this->isLoaded)
215 {
216 $this->loadConfiguration();
217 }
218
219 return isset($this->data[$offset]);
220 }
221
222 public function offsetGet($offset): mixed
223 {
224 return $this->get($offset);
225 }
226
227 public function offsetSet($offset, $value): void
228 {
229 $this->add($offset, $value);
230 }
231
232 public function offsetUnset($offset): void
233 {
234 $this->delete($offset);
235 }
236
237 public function current(): mixed
238 {
239 if (!$this->isLoaded)
240 {
241 $this->loadConfiguration();
242 }
243
244 $c = current($this->data);
245
246 return $c === false ? false : $c["value"];
247 }
248
249 public function next(): void
250 {
251 if (!$this->isLoaded)
252 {
253 $this->loadConfiguration();
254 }
255
256 next($this->data);
257 }
258
259 public function key(): mixed
260 {
261 if (!$this->isLoaded)
262 {
263 $this->loadConfiguration();
264 }
265
266 return key($this->data);
267 }
268
269 public function valid(): bool
270 {
271 if (!$this->isLoaded)
272 {
273 $this->loadConfiguration();
274 }
275
276 $key = $this->key();
277 return isset($this->data[$key]);
278 }
279
280 public function rewind(): void
281 {
282 if (!$this->isLoaded)
283 {
284 $this->loadConfiguration();
285 }
286
287 reset($this->data);
288 }
289
290 public function count(): int
291 {
292 if (!$this->isLoaded)
293 {
294 $this->loadConfiguration();
295 }
296
297 return count($this->data);
298 }
299
300 public static function wnc(): void
301 {
303 }
304}
$path
Определения access_edit.php:21
offsetExists($offset)
Определения configuration.php:212
add($name, $value)
Определения configuration.php:141
static getInstance($moduleId=null)
Определения configuration.php:45
static setValue($name, $value)
Определения configuration.php:30
const CONFIGURATION_FILE_PATH
Определения configuration.php:13
const CONFIGURATION_FILE_EXTRA
Определения configuration.php:11
static getValue($name)
Определения configuration.php:24
addReadonly($name, $value)
Определения configuration.php:166
offsetSet($offset, $value)
Определения configuration.php:227
static wnc()
Определения migrator.php:13
Определения loader.php:13
static getLocal($path, $root=null)
Определения loader.php:572
static isModuleInstalled($moduleName)
Определения modulemanager.php:125
$data['IS_AVAILABLE']
Определения .description.php:13
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$moduleId
$name
Определения menu_edit.php:35
return false
Определения prolog_main_admin.php:185
if(empty($signedUserToken)) $key
Определения quickway.php:257
$k
Определения template_pdf.php:567