• Модуль: main
  • Путь к файлу: ~/bitrix/modules/main/lib/service/geoip/manager.php
  • Класс: BitrixMainServiceGeoIpManager
  • Вызов: Manager::initHandlers
static function initHandlers()
{
	if(self::$handlers !== null)
		return;

	self::$handlers = array();
	$handlersList = array();
	$buildInHandlers = array(
		'BitrixMainServiceGeoIpGeoIP2' => 'lib/service/geoip/geoip2.php',
		'BitrixMainServiceGeoIpMaxMind' => 'lib/service/geoip/maxmind.php',
		'BitrixMainServiceGeoIpExtension' => 'lib/service/geoip/extension.php',
		'BitrixMainServiceGeoIpSypexGeo' => 'lib/service/geoip/sypexgeo.php'
	);

	Loader::registerAutoLoadClasses('main', $buildInHandlers);

	$handlersFields = array();
	$res = HandlerTable::getList(['cache' => ['ttl' => static::getCacheTtl()]]);

	while($row = $res->fetch())
		$handlersFields[$row['CLASS_NAME']] = $row;

	foreach($buildInHandlers as $class => $file)
	{
		if(self::isHandlerClassValid($class))
		{
			$fields = $handlersFields[$class] ?? [];
			$handlersList[$class] = new $class($fields);
			$handlersSort[$class] = $handlersList[$class]->getSort();
		}
	}

	$event = new Event('main', 'onMainGeoIpHandlersBuildList');
	$event->send();
	$resultList = $event->getResults();

	if (is_array($resultList) && !empty($resultList))
	{
		$customClasses = array();

		foreach ($resultList as $eventResult)
		{
			if ($eventResult->getType() != EventResult::SUCCESS)
				continue;

			$params = $eventResult->getParameters();

			if(!empty($params) && is_array($params))
				$customClasses = array_merge($customClasses, $params);
		}

		if(!empty($customClasses))
		{
			Loader::registerAutoLoadClasses(null, $customClasses);

			foreach($customClasses as $class => $file)
			{
				if(!File::isFileExists(Application::getDocumentRoot().'/'.$file))
				{
					continue;
				}

				if(self::isHandlerClassValid($class))
				{
					$fields = $handlersFields[$class] ?? [];
					$handlersList[$class] = new $class($fields);
					$handlersSort[$class] = $handlersList[$class]->getSort();
				}
			}
		}
	}

	asort($handlersSort, SORT_NUMERIC);

	foreach($handlersSort as $class => $sort)
		self::$handlers[$class] = $handlersList[$class];
}