1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
settings.php
См. документацию.
1
<?php
2
3
namespace
Bitrix\Translate;
4
5
use Bitrix\Main;
6
use Bitrix\Translate;
7
8
9
class
Settings
10
extends
Translate\IO\File
11
implements \Iterator, \Countable, \ArrayAccess
12
{
13
public
const
FILE_NAME
=
'.settings.php'
;
14
15
public
const
OPTION_LANGUAGES
=
'languages'
;
16
18
protected
$options
;
19
21
protected
$optionsCount
;
22
24
protected
$optionCodes
= [];
25
27
protected
$dataPosition
= 0;
28
29
38
public
static
function
instantiateByPath
(
string
$fullPath): ?self
39
{
40
if
(empty($fullPath))
41
{
42
throw
new
Main\ArgumentException
();
43
}
44
45
$file =
null
;
46
if
(\mb_substr($fullPath, -5) ===
'/lang'
|| \mb_substr($fullPath, -6) ===
'/lang/'
)
47
{
48
$file =
new
static
($fullPath.
'/'
. self::FILE_NAME);
49
}
50
elseif
(preg_match(
"#^(.*?/lang/)([^/]+)/*(.+)#"
.(
Translate
\
Config::isUtfMode
() ?
'u'
:
''
), $fullPath, $parts))
51
{
52
$file =
new
static
($parts[1].
'/'
. self::FILE_NAME);
53
}
54
55
return
$file;
56
}
57
58
59
//region Load & Save
60
69
public
function
getOption
(
string
$langPath,
string
$optionType):
array
70
{
71
$options
= $this->
getOptions
($langPath);
72
if
(!empty(
$options
[$optionType]))
73
{
74
return
$options
[$optionType];
75
}
76
77
return
[];
78
}
79
87
public
function
getOptions
(
string
$langPath =
''
):
array
88
{
89
// lazy load
90
if
($this->options ===
null
&& !$this->
load
())
91
{
92
return
[];
93
}
94
95
if
(empty($langPath))
96
{
97
return
$this->options
;
98
}
99
// for all in lang/
100
if
($langPath ===
'*'
&& isset($this->options[
'*'
]))
101
{
102
return
$this->options[
'*'
];
103
}
104
105
$options
= [];
106
if
(isset($this->options[
'*'
]))
107
{
108
$options
= $this->options[
'*'
];
109
}
110
111
if
(\preg_match(
"#^(.*?/lang/)([^/]+)/+(.+)#"
.(
Translate
\
Config::isUtfMode
() ?
'u'
:
''
), $langPath, $parts))
112
{
113
$langPath = $parts[3];
114
}
115
116
if
(isset($this->options[$langPath]))
117
{
118
$options
= $this->options[$langPath];
119
}
120
else
121
{
122
if
(\mb_strpos($langPath,
'/'
) !==
false
)
123
{
124
$parts = \explode(
'/'
, $langPath);
125
$path
=
''
;
126
foreach
($parts as $part)
127
{
128
$path
.= (
$path
!=
''
?
'/'
:
''
). $part;
129
if
(isset($this->options[
$path
]))
130
{
131
$options
= $this->options[
$path
];
132
}
133
}
134
}
135
}
136
137
return
$options
;
138
}
139
140
//endregion
141
142
143
//region Load & Save
144
150
public
function
load
(): bool
151
{
152
if
(!$this->isExists() || !$this->isFile() || $this->getName() !== self::FILE_NAME)
153
{
154
return
false
;
155
}
156
157
$this->options = [];
158
$this->optionCodes = [];
159
$this->optionsCount = 0;
160
161
$options
= include $this->getPhysicalPath();
162
163
if
(\is_array(
$options
) && \
count
(
$options
) > 0)
164
{
165
$this->options =
$options
;
166
$this->optionCodes = \array_keys(
$options
);
167
$this->optionsCount =
\count
(
$options
);
168
}
169
170
return
true
;
171
}
172
173
180
public
function
save
(): bool
181
{
182
$content
=
''
;
183
if
($this->
count
() > 0)
184
{
185
$content
= \var_export($this->options,
true
);
186
$content
= \preg_replace(
"/^[ ]{6}(.*)/m"
,
"\t\t\t$1"
,
$content
);
187
$content
= \preg_replace(
"/^[ ]{4}(.*)/m"
,
"\t\t$1"
,
$content
);
188
$content
= \preg_replace(
"/^[ ]{2}(.*)/m"
,
"\t$1"
,
$content
);
189
$content
= \str_replace([
"\r\n"
,
"\r"
], [
"\n"
,
''
],
$content
);
190
}
191
192
\set_error_handler(
193
function
($severity,
$message
, $file, $line)
194
{
195
throw
new \ErrorException(
$message
, $severity, $severity, $file, $line);
196
}
197
);
198
199
try
200
{
201
if
(
$content <>
''
)
202
{
203
if
(parent::putContents(
"<"
.
"?php\nreturn "
.
$content
.
"\n?"
.
'>'
) ===
false
)
204
{
205
$filePath = $this->getPath();
206
throw
new
Main\IO\IoException
(
"Couldn't write option file '{$filePath}'"
);
207
}
208
}
209
elseif
($this->isExists())
210
{
211
$this->markWritable();
212
$this->
delete
();
213
}
214
}
215
catch
(\ErrorException $exception)
216
{
217
\restore_error_handler();
218
throw
new
Main\IO\IoException
($exception->getMessage());
219
}
220
221
\restore_error_handler();
222
223
return
true
;
224
}
225
226
//endregion
227
228
//region ArrayAccess
229
235
public
function
offsetExists
(
$code
): bool
236
{
237
return
isset($this->options[
$code
]);
238
}
239
245
#[\ReturnTypeWillChange]
246
public
function
offsetGet
(
$code
)
247
{
248
if
(isset($this->options[
$code
]))
249
{
250
return
$this->options[
$code
];
251
}
252
253
return
null
;
254
}
255
264
public
function
offsetSet
(
$code
, $phrase): void
265
{
266
$this->options[
$code
] = $phrase;
267
}
268
276
public
function
offsetUnset
(
$code
): void
277
{
278
unset($this->options[
$code
]);
279
}
280
281
//endregion
282
283
//region Iterator
284
290
#[\ReturnTypeWillChange]
291
public
function
current
()
292
{
293
$code
= $this->optionCodes[
$this->dataPosition
];
294
295
return
$this->options[
$code
] ?:
null
;
296
}
297
303
public
function
next
(): void
304
{
305
++
$this->dataPosition
;
306
}
307
313
public
function
key
(): ?string
314
{
315
return
$this->optionCodes[
$this->dataPosition
] ?:
null
;
316
}
317
323
public
function
valid
(): bool
324
{
325
$code
= $this->optionCodes[
$this->dataPosition
];
326
return
isset($this->options[
$code
]);
327
}
328
334
public
function
rewind
(): void
335
{
336
$this->dataPosition = 0;
337
$this->optionCodes = \array_keys($this->options);
338
}
339
340
//endregion
341
342
//region Countable
343
351
public
function
count
($allowDirectFileAccess =
false
): int
352
{
353
if
($this->optionsCount ===
null
)
354
{
355
if
($this->options !==
null
&& \
count
($this->options) > 0)
356
{
357
$this->optionsCount =
\count
($this->options);
358
}
359
elseif
($allowDirectFileAccess)
360
{
361
$options
= include $this->getPhysicalPath();
362
363
if
(\is_array(
$options
) && \
count
(
$options
) > 0)
364
{
365
$this->optionsCount =
\count
(
$options
);
366
}
367
}
368
}
369
370
return
$this->optionsCount ?: 0;
371
}
372
373
//endregion
374
}
$path
$path
Определения
access_edit.php:21
Bitrix\Main\Application\isUtfMode
static isUtfMode()
Определения
application.php:726
Bitrix\Main\ArgumentException
Определения
ArgumentException.php:9
Bitrix\Main\IO\IoException
Определения
ioexception.php:9
Bitrix\Translate\Settings
Определения
settings.php:12
Bitrix\Translate\Settings\$options
$options
Определения
settings.php:18
Bitrix\Translate\Settings\count
count($allowDirectFileAccess=false)
Определения
settings.php:351
Bitrix\Translate\Settings\offsetGet
offsetGet($code)
Определения
settings.php:246
Bitrix\Translate\Settings\load
load()
Определения
settings.php:150
Bitrix\Translate\Settings\$dataPosition
$dataPosition
Определения
settings.php:27
Bitrix\Translate\Settings\key
key()
Определения
settings.php:313
Bitrix\Translate\Settings\getOptions
getOptions(string $langPath='')
Определения
settings.php:87
Bitrix\Translate\Settings\offsetExists
offsetExists($code)
Определения
settings.php:235
Bitrix\Translate\Settings\FILE_NAME
const FILE_NAME
Определения
settings.php:13
Bitrix\Translate\Settings\getOption
getOption(string $langPath, string $optionType)
Определения
settings.php:69
Bitrix\Translate\Settings\instantiateByPath
static instantiateByPath(string $fullPath)
Определения
settings.php:38
Bitrix\Translate\Settings\valid
valid()
Определения
settings.php:323
Bitrix\Translate\Settings\offsetUnset
offsetUnset($code)
Определения
settings.php:276
Bitrix\Translate\Settings\offsetSet
offsetSet($code, $phrase)
Определения
settings.php:264
Bitrix\Translate\Settings\next
next()
Определения
settings.php:303
Bitrix\Translate\Settings\OPTION_LANGUAGES
const OPTION_LANGUAGES
Определения
settings.php:15
Bitrix\Translate\Settings\$optionsCount
$optionsCount
Определения
settings.php:21
Bitrix\Translate\Settings\rewind
rewind()
Определения
settings.php:334
Bitrix\Translate\Settings\current
current()
Определения
settings.php:291
Bitrix\Translate\Settings\$optionCodes
$optionCodes
Определения
settings.php:24
Bitrix\Translate\Settings\save
save()
Определения
settings.php:180
$content
$content
Определения
commerceml.php:144
array
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения
file_new.php:804
$code
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
Определения
options.php:195
Bitrix\Main\File
Определения
Image.php:9
Bitrix\Translate
Определения
autoload.php:3
$message
$message
Определения
payment.php:8
elseif
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения
prolog_main_admin.php:393
count
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения
waybill.php:936
bitrix
modules
translate
lib
settings.php
Создано системой
1.14.0