66 if ($action && mb_strpos($action,
'::'))
68 $actionOriginal = $action;
69 $action = self::getNamespacePublicClasses() .
'\\' . $action;
70 if (is_callable(explode(
'::', $action)))
72 [$class, $method] = explode(
'::', $action);
74 'action' => $actionOriginal,
77 'params_init' => array(),
78 'params_missing' => array()
81 $reflection = new \ReflectionMethod($class, $method);
82 $static = $reflection->getStaticVariables();
83 $mixedParams = isset($static[
'mixedParams'])
84 ? $static[
'mixedParams']
86 foreach ($reflection->getParameters() as $param)
88 $name = $param->getName();
89 if (isset($data[$name]))
91 if (!in_array($name, $mixedParams))
95 !is_array($data[$name])
98 is_array($data[$name])
102 throw new \Bitrix\Main\ArgumentTypeException(
107 $info[
'params_init'][$name] = $data[$name];
109 elseif ($param->isDefaultValueAvailable())
111 $info[
'params_init'][$name] = $param->getDefaultValue();
115 $info[
'params_missing'][] = $name;
163 if (!is_array($data))
168 if (isset($data[
'scope']))
173 if (!$isRest && (!defined(
'BX_UTF') || BX_UTF !==
true))
176 $data,
'UTF-8', SITE_CHARSET
192 ModuleManager::isModuleInstalled(
'bitrix24') &&
224 elseif (($action = self::getMethodInfo($action, $data)))
226 if (!$isRest && !check_bitrix_sessid())
233 if (!empty($action[
'params_missing']))
238 '#MISSING#' => implode(
', ', $action[
'params_missing'])
242 if (method_exists($action[
'class'],
'init'))
244 $result = call_user_func_array(
245 array($action[
'class'],
'init'),
248 if (!$result->isSuccess())
250 $error->copyError($result->getError());
254 if ($error->isEmpty())
258 $result = call_user_func_array(
259 array($action[
'class'], $action[
'method']),
260 $action[
'params_init']
263 if ($result ===
null)
270 else if ($result->isSuccess())
272 $restResult = $result->getResult();
273 $event = new \Bitrix\Main\Event(
'landing',
'onSuccessRest', [
274 'result' => $restResult,
278 foreach ($event->getResults() as $eventResult)
280 if (($modified = $eventResult->getModified()))
282 if (isset($modified[
'result']))
284 $restResult = $modified[
'result'];
290 'result' => $restResult
295 $error->copyError($result->getError());
298 catch (\TypeError $e)
305 catch (\Exception $e)
316 foreach ($error->getErrors() as $error)
319 'error' => $error->getCode(),
320 'error_description' => $error->getMessage()
326 'sessid' => bitrix_sessid(),
356 $context = \Bitrix\Main\Application::getInstance()->getContext();
357 $request = $context->getRequest();
358 $files = $request->getFileList();
359 $postlist = $context->getRequest()->getPostList();
365 $request->offsetExists(
'batch') &&
366 is_array($request->get(
'batch'))
371 if ($request->offsetExists(
'site_id'))
373 $siteId = $request->get(
'site_id');
375 foreach ($request->get(
'batch') as $key => $batchItem)
378 isset($batchItem[
'action']) &&
379 isset($batchItem[
'data'])
382 $batchItem[
'data'] = (array)$batchItem[
'data'];
385 $batchItem[
'data'][
'siteId'] = $siteId;
389 foreach ($files as $code => $file)
391 $batchItem[
'data'][$code] = $file;
394 $rawData = $postlist->getRaw(
'batch');
397 self::$rawData =
$rawData[$key][
'data'];
399 $result[$key] = self::actionProcessing(
400 $batchItem[
'action'],
410 $request->offsetExists(
'action') &&
411 $request->offsetExists(
'data') &&
412 is_array($request->get(
'data'))
415 $data = $request->get(
'data');
417 if ($request->offsetExists(
'site_id'))
419 $data[
'siteId'] = $request->get(
'site_id');
423 foreach ($files as $code => $file)
425 $data[$code] = $file;
428 $rawData = $postlist->getRaw(
'data');
433 return self::actionProcessing(
434 $request->get(
'action'),
449 static $restMethods = array();
451 if (empty($restMethods))
453 $restMethods[self::REST_SCOPE_DEFAULT] = array();
454 $restMethods[self::REST_SCOPE_CLOUD] = array();
457 self::REST_SCOPE_DEFAULT => array(
458 'block',
'site',
'landing',
'repo',
'template',
459 'demos',
'role',
'syspage',
'chat'
461 self::REST_SCOPE_CLOUD => array(
467 foreach ($classes as $scope => $classList)
469 foreach ($classList as $className)
471 $fullClassName = self::getNamespacePublicClasses() .
'\\' . $className;
472 $class = new \ReflectionClass($fullClassName);
473 $methods = $class->getMethods(\ReflectionMethod::IS_PUBLIC);
474 foreach ($methods as $method)
476 $static = $method->getStaticVariables();
477 if (!isset($static[
'internal']) || !$static[
'internal'])
479 $command = $scope.
'.'.
480 mb_strtolower($className).
'.'.
481 mb_strtolower($method->getName());
482 $restMethods[$scope][$command] = array(
483 __CLASS__,
'restGateway'
492 self::REST_SCOPE_DEFAULT => $restMethods[self::REST_SCOPE_DEFAULT],
493 self::REST_SCOPE_CLOUD => $restMethods[self::REST_SCOPE_CLOUD]
508 self::$restApp = AppTable::getByClientId($server->getClientId());
510 $method = $server->getMethod();
511 $method = mb_substr($method, mb_strpos($method,
'.') + 1);
512 $method = preg_replace(
'/\./',
'\\', $method, substr_count($method,
'.') - 1);
513 $method = str_replace(
'.',
'::', $method);
514 $result = self::actionProcessing(
520 if ($result[
'type'] ==
'error')
522 foreach ($result[
'result'] as $error)
524 throw new \Bitrix\Rest\RestException(
525 $error[
'error_description'],
532 return $result[
'result'];
572 $parameters = $event->getParameters();
574 if ($app = AppTable::getByClientId($parameters[
'ID']))
576 $stat = self::getRestStat(
true);
577 if (isset($stat[self::REST_USAGE_TYPE_BLOCK][$app[
'CODE']]))
579 $eventResult = new \Bitrix\Main\EventResult(
580 \
Bitrix\Main\EventResult::ERROR,
583 'LANDING_EXISTS_BLOCKS'
589 else if (isset($stat[self::REST_USAGE_TYPE_PAGE][$app[
'CODE']]))
591 $eventResult = new \Bitrix\Main\EventResult(
592 \
Bitrix\Main\EventResult::ERROR,
595 'LANDING_EXISTS_PAGES'
611 public static function getRestStat(
bool $humanFormat =
false,
bool $onlyActive =
true, array $additionalFilter = []): array
615 self::REST_USAGE_TYPE_BLOCK => [],
616 self::REST_USAGE_TYPE_PAGE => []
618 $activeValues = $onlyActive ?
'Y' : [
'Y',
'N'];
622 '=PUBLIC' => $activeValues,
623 '=LANDING.ACTIVE' => $activeValues,
624 '=LANDING.SITE.ACTIVE' => $activeValues
627 if (isset($additionalFilter[
'SITE_ID']))
629 $filter[
'LANDING.SITE_ID'] = $additionalFilter[
'SITE_ID'];
635 $res = Internals\BlockTable::getList([
647 while ($row = $res->fetch())
649 $blockCnt[mb_substr($row[
'CODE'], 5)] = $row[
'CNT'];
658 'ID' => array_keys($blockCnt)
661 while ($row = $res->fetch())
663 if (!$row[
'APP_CODE'])
667 if (!isset($fullStat[self::REST_USAGE_TYPE_BLOCK][$row[
'APP_CODE']]))
669 $fullStat[self::REST_USAGE_TYPE_BLOCK][$row[
'APP_CODE']] = 0;
671 $fullStat[self::REST_USAGE_TYPE_BLOCK][$row[
'APP_CODE']] += $blockCnt[$row[
'ID']];
676 $filter[
'!CODE'] = $filter[
'CODE'];
677 unset($filter[
'CODE']);
678 $filter[
'!=INITIATOR_APP_CODE'] =
null;
679 $res = Internals\BlockTable::getList([
681 'INITIATOR_APP_CODE',
'CNT'
691 while ($row = $res->fetch())
693 $appCode = $row[
'INITIATOR_APP_CODE'];
694 if (!isset($fullStat[self::REST_USAGE_TYPE_BLOCK][$appCode]))
696 $fullStat[self::REST_USAGE_TYPE_BLOCK][$appCode] = 0;
698 $fullStat[self::REST_USAGE_TYPE_BLOCK][$appCode] += $row[
'CNT'];
704 '=ACTIVE' => $activeValues,
705 '=SITE.ACTIVE' => $activeValues,
706 '!=INITIATOR_APP_CODE' => null
708 if (isset($additionalFilter[
'SITE_ID']))
710 $filter[
'SITE_ID'] = $additionalFilter[
'SITE_ID'];
714 'INITIATOR_APP_CODE',
'CNT'
724 while ($row = $res->fetch())
726 $appCode = $row[
'INITIATOR_APP_CODE'];
727 if (!isset($fullStat[self::REST_USAGE_TYPE_PAGE][$appCode]))
729 $fullStat[self::REST_USAGE_TYPE_PAGE][$appCode] = 0;
731 $fullStat[self::REST_USAGE_TYPE_PAGE][$appCode] += $row[
'CNT'];
735 if (!$humanFormat && \
Bitrix\Main\Loader::includeModule(
'rest'))
737 $appsCode = array_merge(
738 array_keys($fullStat[self::REST_USAGE_TYPE_BLOCK]),
739 array_keys($fullStat[self::REST_USAGE_TYPE_PAGE])
742 self::REST_USAGE_TYPE_BLOCK => [],
743 self::REST_USAGE_TYPE_PAGE => []
747 $appsCode = array_unique($appsCode);
748 $res = AppTable::getList([
756 while ($row = $res->fetch())
758 foreach ($fullStat as $code => $stat)
760 if (isset($stat[$row[
'CODE']]))
762 $fullStatNew[$code][$row[
'CLIENT_ID']] = $stat[$row[
'CODE']];