11 private static $instance;
13 private function __construct()
17 private function __clone()
27 if (!isset(self::$instance))
32 return self::$instance;
38 foreach ($this->getNamespaces($module) as $namespace)
40 $actions = array_merge(
42 $this->getActionsFromControllers($namespace)
46 return array_unique($actions);
49 private function getActionsFromControllers($namespace)
52 foreach ($this->getFilesUnderNamespace($namespace) as $className)
56 $reflectionClass = new \ReflectionClass($className);
57 if ($reflectionClass->isAbstract())
62 $classNamespace = mb_strtolower(trim($reflectionClass->getNamespaceName(),
'\\'));
63 $namespace = mb_strtolower(trim($namespace,
'\\'));
65 if (!str_contains($classNamespace, $namespace))
70 if (!$reflectionClass->isSubclassOf(Controller::className()))
75 $controllerName = strtr($reflectionClass->getName(),
'\\',
'.');
76 $controllerName = mb_strtolower($controllerName);
78 $controller = $this->constructController($reflectionClass);
79 foreach ($controller->listNameActions() as $actionName)
81 $actions[] = $controllerName.
'.'.mb_strtolower($actionName);
84 catch (\ReflectionException $exception)
91 private function getFilesUnderNamespace($namespace)
93 $path = ltrim($namespace,
"\\");
96 $documentRoot = Context::getCurrent()->getServer()->getDocumentRoot();
98 if (preg_match(
"#[^\\\\/a-zA-Z0-9_]#",
$path))
104 $pathParts = explode(
"/",
$path);
106 if ($pathParts[0] ===
"bitrix")
108 array_shift($pathParts);
110 if (empty($pathParts))
115 $module = array_shift($pathParts);
116 if ($module ==
null || empty($pathParts))
123 $module1 = array_shift($pathParts);
124 $module2 = array_shift($pathParts);
125 if ($module1 ==
null || $module2 ==
null || empty($pathParts))
130 $module = $module1 .
"." . $module2;
133 $rootFolder =
$documentRoot .
"/bitrix/modules/" . $module .
"/lib/" . implode(
"/", $pathParts);
136 foreach (
new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator($rootFolder)) as $file)
139 if (!$file->isFile())
144 if ($file->getPath() === $rootFolder)
146 $classes[] = $namespace .
'\\' . $file->getBasename(
'.php');
150 $relativeFolder = trim(mb_substr($file->getPath(), mb_strlen($rootFolder)),
'\\/');
151 $classes[] = $namespace .
'\\' . strtr($relativeFolder,
array(
'/' =>
'\\')) .
'\\' . $file->getBasename(
'.php');
157 private function getNamespaces($module)
159 $controllersConfig = Configuration::getInstance($module);
160 if (!$controllersConfig[
'controllers'] || !$controllersConfig[
'controllers'][
'namespaces'])
165 $namespaces =
array();
166 foreach ($controllersConfig[
'controllers'][
'namespaces'] as
$key => $namespace)
170 $namespaces[] =
$key;
174 $namespaces[] = $namespace;
186 private function constructController(\ReflectionClass $reflectionClass)
190 $controller = $reflectionClass->newInstanceArgs();
listActionsByModule($module)
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