1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
providerbase.php
См. документацию.
1
<?php
2
3
namespace
Bitrix\Rest\Configuration\DataProvider;
4
5
use Bitrix\Main\Web\Json;
6
use Bitrix\Rest\Configuration\Helper;
7
use Bitrix\Main\ArgumentException;
8
use Bitrix\Main\SystemException;
9
14
abstract
class
ProviderBase
15
{
16
public
const
ERROR_DECODE_DATA
=
'ERROR_DECODE_DATA'
;
17
public
const
ERROR_DATA_NOT_FOUND
=
'ERROR_DATA_NOT_FOUND'
;
18
private
$errorList = [];
19
private
$contextUser;
20
private
$context;
21
27
public
function
__construct
(
array
$setting)
28
{
29
if
(!empty($setting[
'CONTEXT'
]))
30
{
31
$this->context = $setting[
'CONTEXT'
];
32
}
33
34
if
(!empty($setting[
'CONTEXT_USER'
]))
35
{
36
$this->contextUser = $setting[
'CONTEXT_USER'
];
37
}
38
}
39
45
protected
function
getContext
()
46
{
47
return
$this->context ?? Helper::getInstance()->getContextAction();
48
}
49
55
protected
function
getUserContext
()
56
{
57
return
$this->contextUser ?? Helper::getInstance()->getContextUser(
''
);
58
}
59
69
abstract
public
function
addContent
(
string
$code
,
$content
,
$type
=
false
): bool;
70
77
abstract
public
function
addFiles
(
array
$files
):
array
;
78
87
abstract
public
function
get
(
string
$path
,
int
$step): ?
array
;
88
95
public
function
getContent
(
string
$path
,
int
$step):
array
96
{
97
$result
= [
98
'DATA'
=>
null
,
99
'~DATA'
=>
null
,
100
'FILE_NAME'
=>
null
,
101
'SANITIZE'
=>
false
,
102
'COUNT'
=> 0,
103
];
104
105
try
106
{
107
$content
= $this->
get
($path, $step);
108
if
(!is_null(
$content
[
'DATA'
]))
109
{
110
$result
[
'~DATA'
] = Json::decode(
$content
[
'DATA'
]);
111
if
(!empty(
$result
[
'~DATA'
]))
112
{
113
$result
[
'DATA'
] = Helper::getInstance()->sanitize(
$result
[
'~DATA'
],
$result
[
'SANITIZE'
]);
114
}
115
}
116
else
117
{
118
$result
[
'ERROR_CODE'
] = self::ERROR_DATA_NOT_FOUND;
119
}
120
121
if
(
$content
[
'FILE_NAME'
])
122
{
123
$result
[
'FILE_NAME'
] = preg_replace(
124
'/('
. Helper::CONFIGURATION_FILE_EXTENSION .
')$/i'
,
125
''
,
126
$content
[
'FILE_NAME'
]
127
);
128
}
129
130
if
(!empty(
$content
[
'COUNT'
]) && (
int
)
$content
[
'COUNT'
] > 0)
131
{
132
$result
[
'COUNT'
] = (int)
$content
[
'COUNT'
];
133
}
134
}
135
catch
(
ArgumentException
$exception)
136
{
137
$result
[
'ERROR_CODE'
] = self::ERROR_DECODE_DATA;
138
}
139
catch
(
SystemException
$exception)
140
{
141
$result
[
'ERROR_CODE'
] = self::ERROR_DATA_NOT_FOUND;
142
}
143
144
return
$result
;
145
}
146
153
protected
function
packageContent
(
$content
): ?string
154
{
155
$result
=
null
;
156
if
(is_array(
$content
))
157
{
158
try
159
{
160
$result
= Json::encode(
$content
);
161
}
162
catch
(
ArgumentException
$e)
163
{
164
$result
=
null
;
165
$this->
addError
(
'ERROR_JSON_ENCODE'
,
''
);
166
167
}
168
}
169
elseif
(is_string(
$content
))
170
{
171
$result
=
$content
;
172
}
173
174
return
$result
;
175
}
176
185
protected
function
addError
(
$code
,
$message
): bool
186
{
187
$this->errorList[
$code
] =
$message
;
188
189
return
true
;
190
}
191
197
public
function
listError
():
array
198
{
199
return
$this->errorList;
200
}
201
207
public
function
resetErrors
(): bool
208
{
209
$this->errorList = [];
210
211
return
true
;
212
}
213
}
$path
$path
Определения
access_edit.php:21
$type
$type
Определения
options.php:106
Bitrix\Main\ArgumentException
Определения
ArgumentException.php:9
Bitrix\Main\SystemException
Определения
SystemException.php:9
Bitrix\Rest\Configuration\DataProvider\ProviderBase
Определения
providerbase.php:15
Bitrix\Rest\Configuration\DataProvider\ProviderBase\listError
listError()
Определения
providerbase.php:197
Bitrix\Rest\Configuration\DataProvider\ProviderBase\ERROR_DATA_NOT_FOUND
const ERROR_DATA_NOT_FOUND
Определения
providerbase.php:17
Bitrix\Rest\Configuration\DataProvider\ProviderBase\getUserContext
getUserContext()
Определения
providerbase.php:55
Bitrix\Rest\Configuration\DataProvider\ProviderBase\ERROR_DECODE_DATA
const ERROR_DECODE_DATA
Определения
providerbase.php:16
Bitrix\Rest\Configuration\DataProvider\ProviderBase\addContent
addContent(string $code, $content, $type=false)
Bitrix\Rest\Configuration\DataProvider\ProviderBase\getContext
getContext()
Определения
providerbase.php:45
Bitrix\Rest\Configuration\DataProvider\ProviderBase\__construct
__construct(array $setting)
Определения
providerbase.php:27
Bitrix\Rest\Configuration\DataProvider\ProviderBase\resetErrors
resetErrors()
Определения
providerbase.php:207
Bitrix\Rest\Configuration\DataProvider\ProviderBase\packageContent
packageContent($content)
Определения
providerbase.php:153
Bitrix\Rest\Configuration\DataProvider\ProviderBase\getContent
getContent(string $path, int $step)
Определения
providerbase.php:95
Bitrix\Rest\Configuration\DataProvider\ProviderBase\addFiles
addFiles(array $files)
Bitrix\Rest\Configuration\DataProvider\ProviderBase\addError
addError($code, $message)
Определения
providerbase.php:185
$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
$result
$result
Определения
get_property_values.php:14
$code
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
Определения
options.php:195
Bitrix\Main\$files
$files
Определения
mysql_to_pgsql.php:30
$message
$message
Определения
payment.php:8
elseif
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения
prolog_main_admin.php:393
bitrix
modules
rest
lib
configuration
dataprovider
providerbase.php
Создано системой
1.14.0