71 if (!is_string($moduleName) || $moduleName ==
"")
75 if (preg_match(
"#[^a-zA-Z0-9._]#", $moduleName))
77 throw new LoaderException(sprintf(
"Module name '%s' is not correct", $moduleName));
80 $moduleName = strtolower($moduleName);
84 if (!isset(self::$safeModeModules[$moduleName]))
90 if (isset(self::$loadedModules[$moduleName]))
92 return self::$loadedModules[$moduleName];
95 if (isset(self::$semiloadedModules[$moduleName]))
97 trigger_error(
"Module '".$moduleName.
"' is in loading progress", E_USER_WARNING);
101 if (!isset($arInstalledModules[$moduleName]))
103 return (self::$loadedModules[$moduleName] =
false);
109 $pathToInclude = $documentRoot.
"/".$moduleHolder.
"/modules/".$moduleName;
110 if (!file_exists($pathToInclude))
113 $pathToInclude = $documentRoot.
"/".$moduleHolder.
"/modules/".$moduleName;
114 if (!file_exists($pathToInclude))
116 return (self::$loadedModules[$moduleName] =
false);
121 if (strpos($moduleName,
".") !==
false)
124 $baseName = str_replace(
".",
"\\", ucwords($moduleName,
"."));
129 $baseName =
"Bitrix\\".ucfirst($moduleName);
133 self::$modulesHolders[$moduleName] = $moduleHolder;
135 if (class_exists(
'\Dev\Main\Migrator\ModuleUpdater'))
137 \Dev\Main\Migrator\ModuleUpdater::checkUpdates($moduleName, $pathToInclude);
141 if (file_exists($pathToInclude.
"/include.php"))
144 self::$semiloadedModules[$moduleName] =
true;
146 $res = self::includeModuleInternal($pathToInclude.
"/include.php");
148 unset(self::$semiloadedModules[$moduleName]);
151 self::$loadedModules[$moduleName] = ($res !==
false);
153 if (!self::$loadedModules[$moduleName])
160 ServiceLocator::getInstance()->registerByModuleSettings($moduleName);
163 return self::$loadedModules[$moduleName];
204 if (isset(self::$sharewareModules[$moduleName]))
206 return self::$sharewareModules[$moduleName];
209 $module = str_replace(
".",
"_", $moduleName);
211 if (self::includeModule($moduleName))
213 if (defined($module.
"_DEMO") && constant($module.
"_DEMO") ==
"Y")
222 return self::$sharewareModules[$moduleName];
225 if (defined($module.
"_DEMO") && constant($module.
"_DEMO") ==
"Y")
227 return (self::$sharewareModules[$moduleName] = self::MODULE_DEMO_EXPIRED);
230 return (self::$sharewareModules[$moduleName] = self::MODULE_NOT_FOUND);
305 $namespace = trim($namespace,
"\\").
"\\";
306 $namespace = strtolower($namespace);
308 $path = rtrim($path,
"/\\");
309 $depth = substr_count(rtrim($namespace,
"\\"),
"\\");
311 self::$namespaces[$namespace][] = [
347 $className = ltrim($className,
"\\");
349 $classLower = strtolower($className);
351 static $documentRoot =
null;
352 if ($documentRoot ===
null)
358 if (isset(self::$autoLoadClasses[$classLower]))
360 $pathInfo = self::$autoLoadClasses[$classLower];
361 if ($pathInfo[
"module"] !=
"")
363 $module = $pathInfo[
"module"];
368 :
"{$documentRoot}/{$holder}/modules";
370 $filePath .=
'/'.$module.
"/".$pathInfo[
"file"];
372 require_once($filePath);
376 require_once($documentRoot.$pathInfo[
"file"]);
381 if (preg_match(
"#[^\\\\/a-zA-Z0-9_]#", $className))
387 "real" => $className,
388 "lower" => $classLower,
391 if (substr($classLower, -5) ==
"table")
395 "real" => substr($className, 0, -5),
396 "lower" => substr($classLower, 0, -5),
400 foreach ($tryFiles as $classInfo)
402 $classParts = explode(
"\\", $classInfo[
"lower"]);
405 array_pop($classParts);
407 while (!empty($classParts))
410 $namespace = implode(
"\\", $classParts).
"\\";
412 if (isset(self::$namespaces[$namespace]))
415 foreach (self::$namespaces[$namespace] as $namespaceLocation)
417 $depth = $namespaceLocation[
"depth"];
418 $path = $namespaceLocation[
"path"];
420 $fileParts = explode(
"\\", $classInfo[
"real"]);
422 for ($i=0; $i <= $depth; $i++)
424 array_shift($fileParts);
427 $classPath = implode(
"/", $fileParts);
429 $classPathLower = strtolower($classPath);
432 $filePath = $path.
'/'.$classPathLower.
".php";
434 if (file_exists($filePath))
436 require_once($filePath);
441 $filePath = $path.
'/'.$classPath.
".php";
443 if (file_exists($filePath))
445 require_once($filePath);
452 array_pop($classParts);
464 $file = ltrim($className,
"\\");
465 $file = strtolower($file);
467 if (preg_match(
"#[^\\\\/a-zA-Z0-9_]#", $file))
472 if (substr($file, -5) ==
"table")
475 $tryFiles[] = substr($file, 0, -5);
478 foreach ($tryFiles as $file)
480 $file = str_replace(
'\\',
'/', $file);
481 $arFile = explode(
"/", $file);
483 if ($arFile[0] ===
"bitrix")
485 array_shift($arFile);
492 $module = array_shift($arFile);
493 if ($module ==
null || empty($arFile))
500 $module1 = array_shift($arFile);
501 $module2 = array_shift($arFile);
503 if ($module1 ==
null || $module2 ==
null || empty($arFile))
508 $module = $module1.
".".$module2;
511 if (!self::includeModule($module))
514 "There is no `%s` class, module `%s` is unavailable", $className, $module