Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 10 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 1 |
| ActionResolver | |
0.00% |
0 / 10 |
|
0.00% |
0 / 6 |
42 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getByControllerName | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| loadFromUrl | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| getAction | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getController | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getServiceLocator | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 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; |
| 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 | use Zend\ServiceManager\ServiceLocatorInterface; |
| 29 | |
| 30 | /** |
| 31 | * Wrap the {@link Resolver} for the needs of access controls in order to get controller and action from a url. |
| 32 | * @author Betrrand Chevrier <bertrand@taotesting.com> |
| 33 | */ |
| 34 | class ActionResolver |
| 35 | { |
| 36 | private $action; |
| 37 | |
| 38 | private $controller; |
| 39 | |
| 40 | public function __construct($url) |
| 41 | { |
| 42 | $this->loadFromUrl($url); |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Build the helper from the controller className |
| 47 | * @param string $extension |
| 48 | * @param string $shortname |
| 49 | * @return ActionResolver |
| 50 | * @throws \ResolverException |
| 51 | */ |
| 52 | public static function getByControllerName($shortName, $extension) |
| 53 | { |
| 54 | $url = _url('index', $shortName, $extension); |
| 55 | return new static($url); |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * @throws \ResolverException |
| 60 | */ |
| 61 | private function loadFromUrl($url) |
| 62 | { |
| 63 | $route = new Resolver(new common_http_Request($url)); |
| 64 | $route->setServiceLocator($this->getServiceLocator()); |
| 65 | $this->controller = $route->getControllerClass(); |
| 66 | $this->action = $route->getMethodName(); |
| 67 | } |
| 68 | |
| 69 | public function getAction() |
| 70 | { |
| 71 | return $this->action; |
| 72 | } |
| 73 | |
| 74 | public function getController() |
| 75 | { |
| 76 | return $this->controller; |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * @return ServiceLocatorInterface |
| 81 | */ |
| 82 | public function getServiceLocator() |
| 83 | { |
| 84 | return ServiceManager::getServiceManager(); |
| 85 | } |
| 86 | } |