13 private static $instance;
15 private function __construct()
19 private function __clone()
29 if (!isset(self::$instance))
34 return self::$instance;
40 foreach ($this->getNamespaces($module) as $namespace)
42 $actions = array_merge(
44 $this->getActionsFromControllers($namespace)
48 return array_unique($actions);
51 private function getActionsFromControllers($namespace)
54 foreach ($this->getFilesUnderNamespace($namespace) as $className)
58 $reflectionClass = new \ReflectionClass($className);
59 if ($reflectionClass->isAbstract())
64 $classNamespace = mb_strtolower(trim($reflectionClass->getNamespaceName(),
'\\'));
65 $namespace = mb_strtolower(trim($namespace,
'\\'));
67 if (strpos($classNamespace, $namespace) ===
false)
77 $controllerName = strtr($reflectionClass->getName(),
'\\',
'.');
78 $controllerName = mb_strtolower($controllerName);
80 $controller = $this->constructController($reflectionClass);
81 foreach ($controller->listNameActions() as $actionName)
83 $actions[] = $controllerName.
'.'.mb_strtolower($actionName);
86 catch (\ReflectionException $exception)
93 private function getFilesUnderNamespace($namespace)
95 $path = ltrim($namespace,
"\\");
96 $path = strtolower($path);
100 if (preg_match(
"#[^\\\\/a-zA-Z0-9_]#", $path))
105 $path = str_replace(
'\\',
'/', $path);
106 $pathParts = explode(
"/", $path);
108 if ($pathParts[0] ===
"bitrix")
110 array_shift($pathParts);
112 if (empty($pathParts))
117 $module = array_shift($pathParts);
118 if ($module ==
null || empty($pathParts))
125 $module1 = array_shift($pathParts);
126 $module2 = array_shift($pathParts);
127 if ($module1 ==
null || $module2 ==
null || empty($pathParts))
132 $module = $module1 .
"." . $module2;
135 $rootFolder = $documentRoot .
"/bitrix/modules/" . $module .
"/lib/" . implode(
"/", $pathParts);
138 foreach (
new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator($rootFolder)) as $file)
141 if (!$file->isFile())
146 if ($file->getPath() === $rootFolder)
148 $classes[] = $namespace .
'\\' . $file->getBasename(
'.php');
152 $relativeFolder = trim(mb_substr($file->getPath(), mb_strlen($rootFolder)),
'\\/');
153 $classes[] = $namespace .
'\\' . strtr($relativeFolder, array(
'/' =>
'\\')) .
'\\' . $file->getBasename(
'.php');
159 private function getNamespaces($module)
161 $controllersConfig = Configuration::getInstance($module);
162 if (!$controllersConfig[
'controllers'] || !$controllersConfig[
'controllers'][
'namespaces'])
167 $namespaces = array();
168 foreach ($controllersConfig[
'controllers'][
'namespaces'] as $key => $namespace)
172 $namespaces[] = $key;
176 $namespaces[] = $namespace;
188 private function constructController(\ReflectionClass $reflectionClass)
192 $controller = $reflectionClass->newInstanceArgs();
listActionsByModule($module)