* @package tao */ class MapHelper { public static function getUriForExtension($extId) { return AccessService::singleton()->makeEMAUri($extId); } public static function getUriForController($controllerClassName) { $extension = self::getExtensionFromController($controllerClassName); $shortName = strpos($controllerClassName, '\\') !== false ? substr($controllerClassName, strrpos($controllerClassName, '\\') + 1) : substr($controllerClassName, strrpos($controllerClassName, '_') + 1) ; return AccessService::singleton()->makeEMAUri($extension, $shortName); } public static function getUriForAction($controllerClassName, $actionName) { $extension = self::getExtensionFromController($controllerClassName); $shortName = strpos($controllerClassName, '\\') !== false ? substr($controllerClassName, strrpos($controllerClassName, '\\') + 1) : substr($controllerClassName, strrpos($controllerClassName, '_') + 1) ; return AccessService::singleton()->makeEMAUri($extension, $shortName, $actionName); } public static function getControllerFromUri($uri) { list($type, $extension, $controller) = explode('_', substr($uri, strpos($uri, '#') + 1)); return FuncHelper::getClassName($extension, $controller); } public static function getActionFromUri($uri) { list($type, $extension, $controller, $action) = explode('_', substr($uri, strpos($uri, '#') + 1)); return $action; } /** * @param $controllerClass * @return mixed * @throws \common_exception_Error */ public static function getExtensionFromController($controllerClass) { if (strpos($controllerClass, '\\') === false) { $parts = explode('_', $controllerClass); if (count($parts) === 3) { return $parts[0]; } else { throw new \common_exception_Error('Unknown controller ' . $controllerClass); } } else { foreach (\common_ext_ExtensionsManager::singleton()->getEnabledExtensions() as $ext) { foreach ($ext->getManifest()->getRoutes() as $routePrefix => $route) { if (is_array($route) && array_key_exists('class', $route)) { $route = $route['class']::getControllerPrefix() ?: $route; } if (is_string($route) && substr($controllerClass, 0, strlen($route)) === $route) { return $ext->getId(); } } } throw new \common_exception_Error('Unknown controller ' . $controllerClass); } } }