Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
loader.php
1<?
2
3namespace Bitrix\Pull;
4
5class Loader
6{
7 public static function register()
8 {
9 if (!static::isAlreadyRegistered())
10 {
11 \spl_autoload_register(array(__CLASS__, "autoLoad"), true);
12 }
13 }
14
15 public static function autoLoad($className)
16 {
17 $className = ltrim($className, "\\"); // fix web env
18 $className = str_replace("\\", '/', $className);
19
20 if (preg_match("#[^\\\\/a-zA-Z0-9_]#", $className))
21 {
22 return;
23 }
24
25 $fileParts = explode("/", $className);
26 if (count($fileParts) < 2)
27 {
28 return;
29 }
30
31 $firstNamespace = mb_strtolower($fileParts[0]);
32 $secondNamespace = mb_strtolower($fileParts[1]);
33
34 if (
35 $firstNamespace === "protobuf" ||
36 $firstNamespace === "google" && $secondNamespace === "protobuf" ||
37 $firstNamespace === "gpbmetadata" && $secondNamespace === "google"
38 )
39 {
40 $documentRoot = $documentRoot = rtrim($_SERVER["DOCUMENT_ROOT"], "/\\");
41 $filePath = $documentRoot."/bitrix/modules/pull/vendor/".implode("/", $fileParts).".php";
42
43 if (file_exists($filePath))
44 {
45 require_once($filePath);
46 }
47 }
48 }
49
50 private static function isAlreadyRegistered()
51 {
52 $autoLoaders = spl_autoload_functions();
53 if (!$autoLoaders)
54 {
55 return false;
56 }
57
58 foreach ($autoLoaders as $autoLoader)
59 {
60 if (!is_array($autoLoader))
61 {
62 continue;
63 }
64
65 list($className, $method) = $autoLoader;
66
67 if ($className === __CLASS__)
68 {
69 return true;
70 }
71 }
72
73 return false;
74 }
75}
static autoLoad($className)
Definition loader.php:15