• Модуль: main
  • Путь к файлу: ~/bitrix/modules/main/lib/urlpreview/router.php
  • Класс: BitrixMainUrlPreviewRouter
  • Вызов: Router::init
static function init()
{
	if(static::$initialized)
		return;

	static::$managedCache = Application::getInstance()->getManagedCache();

	if(static::$managedCache->read(static::CACHE_TTL, static::CACHE_ID))
	{
		static::$routeTable = (array)static::$managedCache->get(static::CACHE_ID);
	}
	else
	{
		$queryResult = RouteTable::getList(array(
			'select' => array('*')
		));

		while($routeRecord = $queryResult->fetch())
		{
			$allowSlashes = ($routeRecord['PARAMETERS']['allowSlashes'] ?? 'N') === 'Y';
			$routeRecord['REGEXP'] = static::convertRouteToRegexp($routeRecord['ROUTE'], $allowSlashes);
			static::$routeTable[$routeRecord['ROUTE']] = $routeRecord;
		}

		uksort(static::$routeTable, function($a, $b)
		{
			$lengthOfA = mb_strlen($a);
			$lengthOfB = mb_strlen($b);
			if($lengthOfA > $lengthOfB)
				return -1;
			else if($lengthOfA == $lengthOfB)
				return 0;
			else
				return 1;
		});

		static::$managedCache->set(static::CACHE_ID, static::$routeTable);
	}

	static::$initialized = true;
}