12 public static function createController(
string $controllerName, array $options = []): ?
UploaderController
16 if (!is_string($className))
21 if (is_string($moduleId) && self::canIncludeModule($moduleId))
23 Loader::includeModule($moduleId);
28 $controllerClass = new \ReflectionClass($className);
29 if ($controllerClass->isAbstract())
34 if (!$controllerClass->isSubclassOf(UploaderController::class))
40 $controller = $controllerClass->newInstance($options);
51 if (!$controller->isAvailable())
58 catch (\ReflectionException $exception)
60 $application = HttpApplication::getInstance();
61 $exceptionHandler = $application->getExceptionHandler();
62 $exceptionHandler->writeToLog($exception);
68 public static function resolveName(
string $controllerName): array
70 $controllerName = trim($controllerName);
71 if (mb_strlen($controllerName) < 1)
76 [$vendor, $controllerName] = self::resolveVendor($controllerName);
77 [$moduleId, $className] = self::resolveModuleAndClass($controllerName);
78 $moduleId = self::refineModuleName($vendor, $moduleId);
80 $className = self::buildClassName($vendor, $moduleId, $className);
82 return [$moduleId, $className];
87 $parts = explode(
'\\', get_class($controller));
88 $vendor = mb_strtolower(array_shift($parts));
89 $moduleId = mb_strtolower(array_shift($parts));
93 return lcfirst($part);
98 if ($vendor === self::DEFAULT_VENDOR)
100 return $moduleId .
'.' . implode(
'.', $parts);
104 return $vendor .
':' . $moduleId .
'.' . implode(
'.', $parts);
108 private static function buildClassName(
string $vendor,
string $moduleId,
string $className): string
110 if ($vendor === self::DEFAULT_VENDOR)
112 $moduleId = ucfirst($moduleId);
113 $namespace =
"\\Bitrix\\{$moduleId}";
117 $moduleParts = explode(
'.', $moduleId);
118 $moduleParts = array_map(
120 return ucfirst(trim(trim($part),
'\\'));
125 $namespace =
"\\" . join(
'\\', $moduleParts);
128 $classNameParts = explode(
'.', $className);
129 $classNameParts = array_map(
131 return ucfirst(trim(trim($part),
'\\'));
136 if (!$classNameParts)
141 return "{$namespace}\\" . join(
'\\', $classNameParts);
144 private static function resolveModuleAndClass(
string $controllerName): array
146 $parts = explode(
'.', $controllerName);
147 $moduleId = array_shift($parts);
148 $className = implode(
'.', $parts);
150 return [$moduleId, $className];
153 private static function resolveVendor(
string $controllerName): array
155 [$vendor, $controllerName] = explode(
':', $controllerName) + [
null,
null];
157 if (!$controllerName)
159 $controllerName = $vendor;
163 return [$vendor, $controllerName];
166 private static function refineModuleName($vendor, $moduleId): string
168 if ($vendor === self::DEFAULT_VENDOR)
170 return mb_strtolower($moduleId);
173 return mb_strtolower($vendor .
'.' . $moduleId);
176 private static function canIncludeModule(
string $moduleId): bool
178 $settings = \Bitrix\Main\Config\Configuration::getInstance($moduleId)->get(
'ui.uploader');
179 if (empty($settings) || !is_array($settings))
184 return isset($settings[
'allowUseControllers']) && $settings[
'allowUseControllers'] ===
true;