• Модуль: tasks
  • Путь к файлу: ~/bitrix/modules/tasks/classes/general/restservice.php
  • Класс: CTaskRestService
  • Вызов: CTaskRestService::__callStatic
static function __callStatic($transitMethodName, $args)
{
	global $APPLICATION;
	$APPLICATION->resetException();

	if (!self::$inited)
	{
		self::_init();
	}

	$arFuncNameParts = explode(self::delimiter, $transitMethodName, 2);
	$className = $arFuncNameParts[0];
	$methodName = $arFuncNameParts[1];

	$returnValue = null;
	$errors  = [];
	$parsedReturnValue = null;
	$withoutExceptions = false;

	try
	{
		if (
			!isset(self::$allowedSpecialClasses[$className])
			&& !in_array($className, self::$arAllowedClasses, true)
		)
		{
			throw new Exception('Unknown REST-method signature given');
		}

		$methodArgs = [];
		foreach ($args[0] as $value)
		{
			$methodArgs[] = $value;
		}

		[$returnValue, $dbResult] = $className::runRestMethod(
			User::getId(),
			$methodName,
			$methodArgs,
			self::getNavData($args[1]),
			$args[2] //instance of CRestServer
		);

		$parsedReturnValue = self::_parseReturnValue($className, $methodName, $returnValue, ['SERVER' => $args[2]]);
		if ($dbResult !== null)
		{
			$parsedReturnValue = self::setNavData($parsedReturnValue, $dbResult);
		}

		$withoutExceptions = true;
	}
	catch (CTaskAssertException $e)
	{
		$errors[] = [
			'id' => 'TASKS_ERROR_ASSERT_EXCEPTION',
			'text' => 'TASKS_ERROR_ASSERT_EXCEPTION',
		];
	}
	catch (TasksException $e)
	{
		$code = $e->getCode();
		$message = $e->getMessage();

		if ($e->GetCode() & TasksException::TE_FLAG_SERIALIZED_ERRORS_IN_MESSAGE)
		{
			$errors = unserialize($message, ['allowed_classes' => false]);
			if (!$errors)
			{
				$errors = [['text' => $message]];
			}
		}
		else
		{
			$errors[] = [
				'id' => "TASKS_ERROR_EXCEPTION_#{$code}",
				'text' => "TASKS_ERROR_EXCEPTION_#{$code}; {$message}; " . TasksException::renderErrorCode($e),
			];
		}
	}
	catch (Exception $e)
	{
		if ($e->getMessage() !== '')
		{
			$errors[] = [
				'id' => 'TASKS_ERROR',
				'text' => $e->getMessage(),
			];
		}
	}

	if ($withoutExceptions)
	{
		return $parsedReturnValue;
	}

	self::_emitError($errors);
	throw new Exception();
}