1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
baseservice.php
См. документацию.
1<?php
2
4
8
9if (!Main\Loader::includeModule('rest'))
10{
11 return;
12}
13
15{
16 protected const ALLOW_HANDLERS = [
17 '\\' . \Sale\Handlers\Delivery\RestHandler::class,
18 '\\' . \Sale\Handlers\Delivery\RestProfile::class,
19 ];
20
21 public static function onRestAppDelete(array $fields): void
22 {
23 if (!Main\Loader::includeModule('rest'))
24 {
25 return;
26 }
27
28 if (empty($fields['APP_ID']) || empty($fields['CLEAN']) || $fields['CLEAN'] !== true)
29 {
30 return;
31 }
32
34 if (!$app)
35 {
36 return;
37 }
38
40 'select' => ['ID', 'CODE'],
41 'filter' => [
42 '=APP_ID' => $app['CLIENT_ID'],
43 ],
44 ]);
45 while ($restHandler = $restHandlerResult->fetch())
46 {
48 'select' => ['ID', 'CONFIG'],
49 'filter' => [
50 '@CLASS_NAME' => self::ALLOW_HANDLERS,
51 ],
52 ]);
53 while ($delivery = $deliveryResult->fetch())
54 {
55 $handlerCode = self::getRestCodeFromConfig($delivery['CONFIG']);
56 if ($handlerCode === $restHandler['CODE'])
57 {
58 Sale\Delivery\Services\Manager::delete($delivery['ID'], false);
59 }
60 }
61
63 }
64 }
65
69 protected static function getIncomingFieldsMap(): array
70 {
71 return [];
72 }
73
77 protected static function getOutcomingFieldsMap(): array
78 {
79 return [];
80 }
81
86
91 protected static function prepareIncomingParams(array $data): array
92 {
93 return self::replaceIncomingKeys($data);
94 }
95
100 protected static function prepareOutcomingFields(array $data): array
101 {
102 return self::replaceOutcomingKeys(
103 static::castOutcomingFieldsData($data)
104 );
105 }
106
107 protected static function castOutcomingFieldsData(array $data): array
108 {
109 return $data;
110 }
111
116 private static function replaceIncomingKeys(array $data): array
117 {
118 return self::replaceKeys($data, static::getIncomingFieldsMap());
119 }
120
125 private static function replaceOutcomingKeys(array $data): array
126 {
127 return self::replaceKeys($data, static::getOutcomingFieldsMap());
128 }
129
135 private static function replaceKeys(array $data, array $map): array
136 {
137 foreach ($map as $key => $newKey)
138 {
139 if (array_key_exists($key, $data))
140 {
141 $data[$newKey] = $data[$key];
142 unset($data[$key]);
143 }
144
145 if (isset($data['FIELDS']) && array_key_exists($key, $data['FIELDS']))
146 {
147 $data['FIELDS'][$newKey] = $data['FIELDS'][$key];
148 unset($data['FIELDS'][$key]);
149 }
150 }
151
152 return $data;
153 }
154
155 protected static function hasAccessToDelivery(array $deliveryData, string $appId = null): bool
156 {
157 $className = $deliveryData['CLASS_NAME'];
158 if (self::isRestHandler($className))
159 {
160 $handlerCode = self::getRestCodeFromConfig($deliveryData['CONFIG']);
161 $handlerData = self::getHandlerData($handlerCode);
162 if ($appId && !empty($handlerData['APP_ID']) && $handlerData['APP_ID'] !== $appId)
163 {
164 return false;
165 }
166 }
167 else
168 {
169 return false;
170 }
171
172 return true;
173 }
174
175 protected static function isRestHandler(string $className): bool
176 {
177 return in_array($className, self::ALLOW_HANDLERS, true);
178 }
179
180 protected static function getRestCodeFromConfig(array $config): string
181 {
182 $handlerCode = '';
183
184 foreach ($config as $configItem)
185 {
186 if (!empty($configItem['REST_CODE']))
187 {
188 $handlerCode = (string)$configItem['REST_CODE'];
189 break;
190 }
191 }
192
193 return $handlerCode;
194 }
195
196 protected static function getHandlerData(string $code): ?array
197 {
198 static $result = [];
199
200 if (!empty($result[$code]))
201 {
202 return $result[$code];
203 }
204
206 'filter' => ['CODE' => $code],
207 'limit' => 1,
208 ])->fetch();
209 if ($handlerData)
210 {
211 $result[$code] = $handlerData;
212 }
213
214 return $result[$code] ?? null;
215 }
216}
static includeModule($moduleName)
Определения loader.php:67
static getList(array $parameters=array())
Определения datamanager.php:431
static delete($primary)
Определения datamanager.php:1644
static getByClientId($clientId)
Определения app.php:967
static onRestAppDelete(array $fields)
Определения baseservice.php:21
static prepareIncomingParams(array $data)
Определения baseservice.php:91
static getHandlerData(string $code)
Определения baseservice.php:196
static hasAccessToDelivery(array $deliveryData, string $appId=null)
Определения baseservice.php:155
static checkDeliveryPermission()
Определения baseservice.php:82
static getRestCodeFromConfig(array $config)
Определения baseservice.php:180
static castOutcomingFieldsData(array $data)
Определения baseservice.php:107
static getIncomingFieldsMap()
Определения baseservice.php:69
static isRestHandler(string $className)
Определения baseservice.php:175
static getOutcomingFieldsMap()
Определения baseservice.php:77
static prepareOutcomingFields(array $data)
Определения baseservice.php:100
static getList(array $params=array())
Определения manager.php:82
static delete($id, bool $checkServiceUsage=true)
Определения manager.php:868
Определения rest.php:896
$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
$result
Определения get_property_values.php:14
$app
Определения proxy.php:8
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
Определения options.php:195
$map
Определения config.php:5
Определения accessexception.php:2
$config
Определения quickway.php:69
if(empty($signedUserToken)) $key
Определения quickway.php:257
$fields
Определения yandex_run.php:501