Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 29 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 1 |
| MapHelper | |
0.00% |
0 / 29 |
|
0.00% |
0 / 6 |
306 | |
0.00% |
0 / 1 |
| getUriForExtension | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getUriForController | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
6 | |||
| getUriForAction | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
6 | |||
| getControllerFromUri | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| getActionFromUri | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| getExtensionFromController | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
110 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; under version 2 |
| 7 | * of the License (non-upgradable). |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 | * |
| 18 | * Copyright (c) 2008-2010 (original work) Deutsche Institut für Internationale Pädagogische Forschung |
| 19 | * (under the project TAO-TRANSFER); |
| 20 | * 2009-2012 (update and modification) Public Research Centre Henri Tudor |
| 21 | * (under the project TAO-SUSTAIN & TAO-DEV); |
| 22 | */ |
| 23 | |
| 24 | namespace oat\funcAcl\helpers; |
| 25 | |
| 26 | use common_exception_Error; |
| 27 | use common_ext_ExtensionsManager; |
| 28 | use oat\funcAcl\models\AccessService; |
| 29 | use oat\tao\model\accessControl\func\FuncHelper; |
| 30 | |
| 31 | /** |
| 32 | * Helper to map URIs to controllers |
| 33 | * |
| 34 | * @access public |
| 35 | * |
| 36 | * @author Joel Bout <joel@taotesting.com> |
| 37 | * |
| 38 | * @package tao |
| 39 | */ |
| 40 | class MapHelper |
| 41 | { |
| 42 | public static function getUriForExtension($extId) |
| 43 | { |
| 44 | return AccessService::singleton()->makeEMAUri($extId); |
| 45 | } |
| 46 | |
| 47 | public static function getUriForController($controllerClassName) |
| 48 | { |
| 49 | $extension = self::getExtensionFromController($controllerClassName); |
| 50 | $shortName = strpos($controllerClassName, '\\') !== false |
| 51 | ? substr($controllerClassName, strrpos($controllerClassName, '\\') + 1) |
| 52 | : substr($controllerClassName, strrpos($controllerClassName, '_') + 1) |
| 53 | ; |
| 54 | |
| 55 | return AccessService::singleton()->makeEMAUri($extension, $shortName); |
| 56 | } |
| 57 | |
| 58 | public static function getUriForAction($controllerClassName, $actionName) |
| 59 | { |
| 60 | $extension = self::getExtensionFromController($controllerClassName); |
| 61 | $shortName = strpos($controllerClassName, '\\') !== false |
| 62 | ? substr($controllerClassName, strrpos($controllerClassName, '\\') + 1) |
| 63 | : substr($controllerClassName, strrpos($controllerClassName, '_') + 1) |
| 64 | ; |
| 65 | |
| 66 | return AccessService::singleton()->makeEMAUri($extension, $shortName, $actionName); |
| 67 | } |
| 68 | |
| 69 | public static function getControllerFromUri($uri) |
| 70 | { |
| 71 | list($type, $extension, $controller) = explode('_', substr($uri, strpos($uri, '#') + 1)); |
| 72 | |
| 73 | return FuncHelper::getClassName($extension, $controller); |
| 74 | } |
| 75 | |
| 76 | public static function getActionFromUri($uri) |
| 77 | { |
| 78 | list($type, $extension, $controller, $action) = explode('_', substr($uri, strpos($uri, '#') + 1)); |
| 79 | |
| 80 | return $action; |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * @param $controllerClass |
| 85 | * |
| 86 | * @throws common_exception_Error |
| 87 | * |
| 88 | * @return mixed |
| 89 | */ |
| 90 | public static function getExtensionFromController($controllerClass) |
| 91 | { |
| 92 | if (strpos($controllerClass, '\\') === false) { |
| 93 | $parts = explode('_', $controllerClass); |
| 94 | |
| 95 | if (count($parts) === 3) { |
| 96 | return $parts[0]; |
| 97 | } |
| 98 | |
| 99 | throw new common_exception_Error('Unknown controller ' . $controllerClass); |
| 100 | } else { |
| 101 | foreach (common_ext_ExtensionsManager::singleton()->getEnabledExtensions() as $ext) { |
| 102 | foreach ($ext->getManifest()->getRoutes() as $routePrefix => $route) { |
| 103 | if (is_array($route) && array_key_exists('class', $route)) { |
| 104 | $route = $route['class']::getControllerPrefix() ?: $route; |
| 105 | } |
| 106 | |
| 107 | if (is_string($route) && substr($controllerClass, 0, strlen($route)) === $route) { |
| 108 | return $ext->getId(); |
| 109 | } |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | throw new common_exception_Error('Unknown controller ' . $controllerClass); |
| 114 | } |
| 115 | } |
| 116 | } |