Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 14 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| FuncHelper | |
0.00% |
0 / 14 |
|
0.00% |
0 / 2 |
30 | |
0.00% |
0 / 1 |
| getClassName | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| getClassNameByUrl | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
20 | |||
| 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) 2014 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | namespace oat\tao\model\accessControl\func; |
| 23 | |
| 24 | use oat\tao\model\routing\Resolver; |
| 25 | use common_http_Request; |
| 26 | use common_exception_Error; |
| 27 | use oat\oatbox\service\ServiceManager; |
| 28 | |
| 29 | /** |
| 30 | */ |
| 31 | class FuncHelper |
| 32 | { |
| 33 | /** |
| 34 | * Get the controller className from extension and controller shortname |
| 35 | * @param string $extension |
| 36 | * @param string $shortname |
| 37 | * @return string the full class name (as defined in PHP) |
| 38 | * @throws \ResolverException:: |
| 39 | */ |
| 40 | public static function getClassName($extension, $shortName) |
| 41 | { |
| 42 | $url = _url('index', $shortName, $extension); |
| 43 | return self::getClassNameByUrl($url); |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Helps you to get the name of the class for a given URL. The controller class name is used in privileges |
| 48 | * definition. |
| 49 | * @param string $url |
| 50 | * @throws \ResolverException |
| 51 | * @return string the className |
| 52 | */ |
| 53 | public static function getClassNameByUrl($url) |
| 54 | { |
| 55 | $class = null; |
| 56 | if (!empty($url)) { |
| 57 | try { |
| 58 | $route = new Resolver(new common_http_Request($url)); |
| 59 | $route->setServiceLocator(ServiceManager::getServiceManager()); |
| 60 | $class = $route->getControllerClass(); |
| 61 | } catch (\ResolverException $re) { |
| 62 | throw new common_exception_Error( |
| 63 | 'The url "' . $url . '" could not be mapped to a controller : ' . $re->getMessage() |
| 64 | ); |
| 65 | } |
| 66 | } |
| 67 | if (is_null($class)) { |
| 68 | throw new common_exception_Error('The url "' . $url . '" could not be mapped to a controller'); |
| 69 | } |
| 70 | return $class; |
| 71 | } |
| 72 | } |