• Модуль: rest
  • Путь к файлу: ~/bitrix/modules/rest/lib/api/placement.php
  • Класс: BitrixRestApiPlacement
  • Вызов: Placement::prepareOptions
static function prepareOptions($paramsOptions = [], $placementInfoOptions = []): array
{
	$result = [];
	if (empty($placementInfoOptions))
	{
		return $result;
	}
	$requiredOptions = self::getRequiredOptions($placementInfoOptions);
	$defaultOptions = self::getDefaultOptions($placementInfoOptions);

	if (!is_array($paramsOptions))
	{
		if (!empty($requiredOptions))
		{
			throw new ArgumentTypeException('options', 'array');
		}

		return $defaultOptions;
	}

	self::checkRequiredOptionsInParamsOptions($paramsOptions, $requiredOptions);

	foreach ($placementInfoOptions as $optionName => $optionSetting)
	{
		$optionValue = $paramsOptions[$optionName] ?? $defaultOptions[$optionName] ?? null;
		$optionType = null;

		if (!is_array($optionSetting))
		{
			$optionType = $optionSetting;
		}
		else
		{
			$optionType = $optionSetting['type'];
		}

		switch($optionType)
		{
			case 'int':
				$result[$optionName] = (int)$optionValue;

				break;
			case 'string':
				$result[$optionName] = (string)$optionValue;

				break;
			case 'array':
				if (!is_array($optionValue))
				{
					throw new ArgumentTypeException($optionName, 'array');
				}
				$result[$optionName] = self::prepareCompositeOptions($optionValue, $optionSetting);

				break;
		}
	}

	return $result;
}