1
0
mirror of synced 2024-11-25 23:06:08 +03:00
bitrix-module/intaro.retailcrm/classes/general/RetailcrmDependencyLoader.php
2020-12-15 12:39:38 +03:00

99 lines
2.3 KiB
PHP

<?php
/**
* PHP version 5.3
*
* RetailcrmDependencyLoader class
*
* @category RetailCRM
* @package RetailCRM
*/
IncludeModuleLangFile(__FILE__);
/**
* PHP version 5.3
*
* RetailcrmDependencyLoader class
*
* @category RetailCRM
* @package RetailCRM
*/
class RetailcrmDependencyLoader
{
/** @var int */
const LEGACY_LOADER = 0;
/** @var int */
const D7_LOADER = 1;
/** @var int $loader */
private static $loader = self::D7_LOADER;
/**
* Loads dependencies
*
* @return bool
*/
public static function loadDependencies()
{
foreach (self::getDependencies() as $dependency) {
if (self::LEGACY_LOADER == self::$loader) {
if (!CModule::IncludeModule($dependency)) {
RCrmActions::eventLog(
__CLASS__ . '::' . __METHOD__,
$dependency,
'module not found'
);
return false;
}
} else {
try {
if (!\Bitrix\Main\Loader::includeModule($dependency)) {
RCrmActions::eventLog(
__CLASS__ . '::' . __METHOD__,
$dependency,
'module not found'
);
return false;
}
} catch (\Bitrix\Main\LoaderException $exception) {
RCrmActions::eventLog(
__CLASS__ . '::' . __METHOD__,
$dependency,
sprintf('error while trying to load module: %s', $exception->getMessage())
);
return false;
}
}
}
return true;
}
/**
* Set loader mode. Use RetailcrmDependencyLoader::LEGACY_LOADER or RetailcrmDependencyLoader::D7_LOADER
*
* @param $loader
*/
public static function setLoader($loader)
{
if (in_array($loader, array(self::LEGACY_LOADER, self::D7_LOADER))) {
self::$loader = $loader;
}
}
/**
* Returns array of required modules names
*
* @return array<string>
*/
public static function getDependencies()
{
return array("iblock", "sale", "catalog");
}
}