1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
providerbase.php
См. документацию.
1<?php
2
3namespace Bitrix\Rest\Configuration\DataProvider;
4
5use Bitrix\Main\Web\Json;
6use Bitrix\Rest\Configuration\Helper;
7use Bitrix\Main\ArgumentException;
8use Bitrix\Main\SystemException;
9
14abstract 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 {
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
Определения access_edit.php:21
$type
Определения options.php:106
addContent(string $code, $content, $type=false)
getContent(string $path, int $step)
Определения providerbase.php:95
$content
Определения commerceml.php:144
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
Определения options.php:195
$files
Определения mysql_to_pgsql.php:30
$message
Определения payment.php:8
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393