1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
crawler.php
См. документацию.
1<?php
2
3namespace Bitrix\Main\Engine;
4
5use Bitrix\Main\Config\Configuration;
6use Bitrix\Main\Context;
7
8final class Crawler
9{
11 private static $instance;
12
13 private function __construct()
14 {
15 }
16
17 private function __clone()
18 {
19 }
20
25 public static function getInstance()
26 {
27 if (!isset(self::$instance))
28 {
29 self::$instance = new Crawler;
30 }
31
32 return self::$instance;
33 }
34
35 public function listActionsByModule($module)
36 {
37 $actions = array();
38 foreach ($this->getNamespaces($module) as $namespace)
39 {
40 $actions = array_merge(
41 $actions,
42 $this->getActionsFromControllers($namespace)
43 );
44 }
45
46 return array_unique($actions);
47 }
48
49 private function getActionsFromControllers($namespace)
50 {
51 $actions = array();
52 foreach ($this->getFilesUnderNamespace($namespace) as $className)
53 {
54 try
55 {
56 $reflectionClass = new \ReflectionClass($className);
57 if ($reflectionClass->isAbstract())
58 {
59 continue;
60 }
61
62 $classNamespace = mb_strtolower(trim($reflectionClass->getNamespaceName(), '\\'));
63 $namespace = mb_strtolower(trim($namespace, '\\'));
64
65 if (!str_contains($classNamespace, $namespace))
66 {
67 continue;
68 }
69
70 if (!$reflectionClass->isSubclassOf(Controller::className()))
71 {
72 continue;
73 }
74
75 $controllerName = strtr($reflectionClass->getName(), '\\', '.');
76 $controllerName = mb_strtolower($controllerName);
77
78 $controller = $this->constructController($reflectionClass);
79 foreach ($controller->listNameActions() as $actionName)
80 {
81 $actions[] = $controllerName.'.'.mb_strtolower($actionName);
82 }
83 }
84 catch (\ReflectionException $exception)
85 {}
86 }
87
88 return $actions;
89 }
90
91 private function getFilesUnderNamespace($namespace)
92 {
93 $path = ltrim($namespace, "\\"); // fix web env
94 $path = strtolower($path);
95
96 $documentRoot = Context::getCurrent()->getServer()->getDocumentRoot();
97
98 if (preg_match("#[^\\\\/a-zA-Z0-9_]#", $path))
99 {
100 return array();
101 }
102
103 $path = str_replace('\\', '/', $path);
104 $pathParts = explode("/", $path);
105
106 if ($pathParts[0] === "bitrix")
107 {
108 array_shift($pathParts);
109
110 if (empty($pathParts))
111 {
112 return array();
113 }
114
115 $module = array_shift($pathParts);
116 if ($module == null || empty($pathParts))
117 {
118 return array();
119 }
120 }
121 else
122 {
123 $module1 = array_shift($pathParts);
124 $module2 = array_shift($pathParts);
125 if ($module1 == null || $module2 == null || empty($pathParts))
126 {
127 return array();
128 }
129
130 $module = $module1 . "." . $module2;
131 }
132
133 $rootFolder = $documentRoot . "/bitrix/modules/" . $module . "/lib/" . implode("/", $pathParts);
134
135 $classes = array();
136 foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($rootFolder)) as $file)
137 {
139 if (!$file->isFile())
140 {
141 continue;
142 }
143
144 if ($file->getPath() === $rootFolder)
145 {
146 $classes[] = $namespace . '\\' . $file->getBasename('.php');
147 continue;
148 }
149
150 $relativeFolder = trim(mb_substr($file->getPath(), mb_strlen($rootFolder)), '\\/');
151 $classes[] = $namespace . '\\' . strtr($relativeFolder, array('/' => '\\')) . '\\' . $file->getBasename('.php');
152 }
153
154 return $classes;
155 }
156
157 private function getNamespaces($module)
158 {
159 $controllersConfig = Configuration::getInstance($module);
160 if (!$controllersConfig['controllers'] || !$controllersConfig['controllers']['namespaces'])
161 {
162 return array();
163 }
164
165 $namespaces = array();
166 foreach ($controllersConfig['controllers']['namespaces'] as $key => $namespace)
167 {
168 if (is_string($key))
169 {
170 $namespaces[] = $key;
171 }
172 else
173 {
174 $namespaces[] = $namespace;
175 }
176 }
177
178 return $namespaces;
179 }
180
186 private function constructController(\ReflectionClass $reflectionClass)
187 {
190 $controller = $reflectionClass->newInstanceArgs();
191
192 return $controller;
193 }
194}
$path
Определения access_edit.php:21
listActionsByModule($module)
Определения crawler.php:35
static getInstance()
Определения crawler.php:25
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
foreach(['Bitrix\\Main'=> '/lib', 'Psr\\Container'=> '/vendor/psr/container/src', 'Psr\\Log'=> '/vendor/psr/log/src', 'Psr\\Http\\Message'=> '/vendor/psr/http-message/src', 'Psr\\Http\\Client'=> '/vendor/psr/http-client/src', 'Http\\Promise'=> '/vendor/php-http/promise/src', 'PHPMailer\\PHPMailer'=> '/vendor/phpmailer/phpmailer/src', 'GeoIp2'=> '/vendor/geoip2/geoip2/src', 'MaxMind\\Db'=> '/vendor/maxmind-db/reader/src/MaxMind/Db', 'PhpParser'=> '/vendor/nikic/php-parser/lib/PhpParser', 'Recurr'=> '/vendor/simshaun/recurr/src/Recurr',] as $namespace=> $namespacePath) $documentRoot
Определения autoload.php:27
if(empty($signedUserToken)) $key
Определения quickway.php:257