25 $parts = explode(
'.', $action);
26 $actionName = array_pop($parts);
28 $controllerClass = self::buildControllerClassName($vendor, $module, $parts);
29 if (!$controllerClass)
36 $controller = ControllerBuilder::build($controllerClass, [
41 return [$controller, $actionName];
49 private static function buildControllerClassName($vendor, $module, array $actionParts)
51 $controllerName = array_pop($actionParts);
53 if (self::isOldFullQualifiedName($vendor, $module, $actionParts))
55 $actionParts[] = $controllerName;
56 $className = implode(
'\\', $actionParts);
57 if (!self::checkClassUnderAllowedNamespaces($module, $className))
65 $namespaces = self::listAllowedNamespaces($module);
67 $aliases = array_change_key_case($namespaces, CASE_LOWER);
68 $probablyPrefix = mb_strtolower(reset($actionParts));
69 if (isset($aliases[$probablyPrefix]))
71 $alias = $aliases[$probablyPrefix];
72 array_shift($actionParts);
73 array_push($actionParts, $controllerName);
75 return $alias .
'\\' . implode(
'\\', $actionParts);
78 $furtherControllerClassName = self::buildClassNameByAction(
81 array_merge($actionParts, [$controllerName])
83 if (self::checkClassUnderAllowedNamespaces($module, $furtherControllerClassName))
85 return $furtherControllerClassName;
89 if (!$defaultNamespaceByModule)
94 $defaultPath = strtr($defaultNamespaceByModule, [
'\\' =>
'.']);
97 $firstLetter = mb_substr($controllerName, 0, 1);
99 if ($firstLetter === mb_strtolower($firstLetter))
101 $defaultPath = mb_strtolower($defaultPath);
105 array_unshift($actionParts, ...explode(
'.', $defaultPath));
106 array_push($actionParts, $controllerName);
108 return implode(
'\\', $actionParts);
119 $controllersConfig = Configuration::getInstance($module);
120 if (!$controllersConfig[
'controllers'] || !isset($controllersConfig[
'controllers'][
'defaultNamespace']))
125 return $controllersConfig[
'controllers'][
'defaultNamespace'];
137 private static function isOldFullQualifiedName($vendor, $module, array $actionParts)
139 if ($vendor !== self::DEFAULT_VENDOR)
144 if (!isset($actionParts[0]) || !isset($actionParts[1]))
149 return $actionParts[0] === $vendor && $actionParts[1] === $module;
152 private static function listAllowedNamespaces($module)
154 $controllersConfig = Configuration::getInstance($module);
155 if (!$controllersConfig[
'controllers'])
161 if (isset($controllersConfig[
'controllers'][
'namespaces']))
163 foreach ($controllersConfig[
'controllers'][
'namespaces'] as $key => $namespace)
167 $namespaces[] = $namespace;
171 $namespaces[$namespace] = $key;
176 if (isset($controllersConfig[
'controllers'][
'defaultNamespace']))
178 $namespaces[] = $controllersConfig[
'controllers'][
'defaultNamespace'];
184 private static function checkClassUnderAllowedNamespaces($module, $class)
186 $namespaces = self::listAllowedNamespaces($module);
187 foreach ($namespaces as $namespace)
189 if (mb_stripos(trim($class,
'\\'), trim($namespace,
'\\') .
'\\') === 0)
206 private static function buildClassNameByAction($vendor, $module, array $actionParts)
208 if($vendor === self::DEFAULT_VENDOR)
210 $namespace =
"\\Bitrix\\$module";
214 $namespace =
"\\" . strtr($module, [
'.' =>
'\\']);
222 return "{$namespace}\\" . trim(implode(
'\\', $actionParts),
'\\');
236 $parts = explode(
'\\', get_class($controller));
237 $vendor = mb_strtolower(array_shift($parts));
239 $parts[0] = mb_strtolower($parts[0]);
241 return $vendor .
':' . implode(
'.', $parts);
static getDefaultNamespaceByModule($module)
static getNameByController(Controller $controller)
static getControllerAndAction($vendor, $module, $action, $scope=Controller::SCOPE_AJAX)