- Модуль: learning
- Путь к файлу: ~/bitrix/modules/learning/classes/general/clearnsharedargmanager.php
- Класс: can
- Вызов: can::ParseOptions
protected function ParseOptions ($arOptions, $arParseParams)
{
if ( ! is_array($arOptions) )
throw new Exception();
$arParsedOptions = array();
foreach ($arParseParams as $paramName => $arParamData)
{
// If option cannot be omitted - check it
if ($arParamData['mandatory'])
{
if ( ! array_key_exists($paramName, $arOptions) )
throw new Exception();
}
else // option can be omitted, so can be default value
{
if ( ! array_key_exists($paramName, $arOptions) )
{
if (array_key_exists('default_value', $arParamData))
$arOptions[$paramName] = $arParamData['default_value'];
}
}
// now, check and cast (if should) type of value in $arOptions[$paramName]
switch ($arParamData['type'])
{
case 'boolean':
if ( ! in_array($arOptions[$paramName], array(true, false), true) )
throw new Exception();
break;
case 'string':
if ( ! is_string($arOptions[$paramName]) )
throw new Exception();
break;
case 'integer':
if ( ! is_int($arOptions[$paramName]) )
throw new Exception();
break;
case 'strictly_castable_to_integer':
if ( ! is_numeric($arOptions[$paramName]) )
throw new Exception();
if ( ! is_int($arOptions[$paramName] + 0) )
throw new Exception();
$arOptions[$paramName] = (int) ($arOptions[$paramName] + 0);
break;
default:
throw new Exception();
break;
}
$arParsedOptions[$paramName] = $arOptions[$paramName];
unset ($arOptions[$paramName]);
}
// Ensure that there is no more options
if (count($arOptions) > 0)
throw new Exception('there is unprocessed options');
return ($arParsedOptions);
}