- Модуль: main
- Путь к файлу: ~/bitrix/modules/main/lib/loader.php
- Класс: BitrixMainwhich
- Вызов: which::autoLoad
static function autoLoad($className)
{
// fix web env
$className = ltrim($className, "\");
$classLower = strtolower($className);
static $documentRoot = null;
if ($documentRoot === null)
{
$documentRoot = self::getDocumentRoot();
}
//optimization via direct paths
if (isset(self::$autoLoadClasses[$classLower]))
{
$pathInfo = self::$autoLoadClasses[$classLower];
if ($pathInfo["module"] != "")
{
$module = $pathInfo["module"];
$holder = (self::$modulesHolders[$module] ?? self::BITRIX_HOLDER);
$filePath = (defined('REPOSITORY_ROOT'))
? REPOSITORY_ROOT
: "{$documentRoot}/{$holder}/modules";
$filePath .= '/'.$module."/".$pathInfo["file"];
require_once($filePath);
}
else
{
require_once($documentRoot.$pathInfo["file"]);
}
return;
}
if (preg_match("#[^\\/a-zA-Z0-9_]#", $className))
{
return;
}
$tryFiles = [[
"real" => $className,
"lower" => $classLower,
]];
if (substr($classLower, -5) == "table")
{
// old *Table stored in reserved files
$tryFiles[] = [
"real" => substr($className, 0, -5),
"lower" => substr($classLower, 0, -5),
];
}
foreach ($tryFiles as $classInfo)
{
$classParts = explode("\", $classInfo["lower"]);
//remove class name
array_pop($classParts);
while (!empty($classParts))
{
//go from the end
$namespace = implode("\", $classParts)."\";
if (isset(self::$namespaces[$namespace]))
{
//found
foreach (self::$namespaces[$namespace] as $namespaceLocation)
{
$depth = $namespaceLocation["depth"];
$path = $namespaceLocation["path"];
$fileParts = explode("\", $classInfo["real"]);
for ($i=0; $i <= $depth; $i++)
{
array_shift($fileParts);
}
$classPath = implode("/", $fileParts);
$classPathLower = strtolower($classPath);
// final path lower case
$filePath = $path.'/'.$classPathLower.".php";
if (file_exists($filePath))
{
require_once($filePath);
break 3;
}
// final path original case
$filePath = $path.'/'.$classPath.".php";
if (file_exists($filePath))
{
require_once($filePath);
break 3;
}
}
}
//try the shorter namespace
array_pop($classParts);
}
}
}