Skip to content

Instantly share code, notes, and snippets.

@AndreySkryl
Last active March 22, 2019 10:36
Show Gist options
  • Select an option

  • Save AndreySkryl/ad211f2584182be29d030a47afe36644 to your computer and use it in GitHub Desktop.

Select an option

Save AndreySkryl/ad211f2584182be29d030a47afe36644 to your computer and use it in GitHub Desktop.
(Bitrix24) Класс "Валидатор зависимостей модуля"
<?
/**
* класс "Валидатор зависимостей модуля"
*/
class ModuleDependencyValidator {
/**
* Проверка зависимостей
* @param array $dependencies Массив зависимостей (модулей), необходимых для работы конкретного [класса, ...]
* @return bool $result Результат валидации
*
* @throws \Exception $exception Исключение с сообщением "Модуль (зависимость) '".$dependency."' не найдена."
*/
public static function validate(array $dependencies = ["iblock"]) {
foreach ($dependencies as $dependency) {
$dependency = trim(strtolower($dependency));
if (!\Bitrix\Main\Loader::includeModule($dependency)) {
$message = str_replace(["#FIELD_NAME#"], [$dependency], Loc::getMessage("DEPENDENCY_IS_NOT_FOUND"));
throw new \Exception($message);
}
}
return true;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment