Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 16 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
| ActionDescription | |
0.00% |
0 / 16 |
|
0.00% |
0 / 5 |
90 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getDocBlock | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
12 | |||
| getName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getDescription | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getRequiredRights | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
12 | |||
| 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-2022 (original work) Open Assessment Technologies SA; |
| 19 | */ |
| 20 | |
| 21 | namespace oat\tao\model\controllerMap; |
| 22 | |
| 23 | use phpDocumentor\Reflection\DocBlock; |
| 24 | use phpDocumentor\Reflection\DocBlockFactory; |
| 25 | use ReflectionMethod; |
| 26 | |
| 27 | /** |
| 28 | * Description of a Tao Controller |
| 29 | * |
| 30 | * @author Joel Bout <joel@taotesting.com> |
| 31 | * @deprecated use \oat\tao\model\routing\RouteAnnotationService instead |
| 32 | */ |
| 33 | class ActionDescription |
| 34 | { |
| 35 | /** @var DocBlock[] */ |
| 36 | private static $docBlocks = []; |
| 37 | |
| 38 | /** |
| 39 | * The method implementing the action |
| 40 | * |
| 41 | * @var ReflectionMethod |
| 42 | */ |
| 43 | private $method; |
| 44 | |
| 45 | /** |
| 46 | * Create a new lazy parsing action description |
| 47 | * |
| 48 | * @param ReflectionMethod $method |
| 49 | */ |
| 50 | public function __construct(ReflectionMethod $method) |
| 51 | { |
| 52 | $this->method = $method; |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * @return DocBlock |
| 57 | */ |
| 58 | protected function getDocBlock() |
| 59 | { |
| 60 | $cacheKey = "{$this->method->class}::{$this->method->name}"; |
| 61 | |
| 62 | if (!isset(self::$docBlocks[$cacheKey])) { |
| 63 | $factory = DocBlockFactory::createInstance(); |
| 64 | $factory->registerTagHandler('requiresRight', RequiresRightTag::class); |
| 65 | |
| 66 | self::$docBlocks[$cacheKey] = is_string($this->method->getDocComment()) |
| 67 | ? $factory->create($this->method) |
| 68 | : new DocBlock(); |
| 69 | } |
| 70 | |
| 71 | return self::$docBlocks[$cacheKey]; |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * Get the name of the action, which corresponds |
| 76 | * to the name of the called function |
| 77 | * |
| 78 | * @return string |
| 79 | */ |
| 80 | public function getName() |
| 81 | { |
| 82 | return $this->method->getName(); |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * Get a human readable description of what the action does |
| 87 | * |
| 88 | * @return string |
| 89 | */ |
| 90 | public function getDescription() |
| 91 | { |
| 92 | return $this->getDocBlock()->getSummary(); |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * Returns an array of all rights required to execute the action |
| 97 | * |
| 98 | * The array uses the name of the parameter as key and the value is |
| 99 | * a string identifying the right |
| 100 | * |
| 101 | * @return string[] |
| 102 | */ |
| 103 | public function getRequiredRights() |
| 104 | { |
| 105 | $privileges = []; |
| 106 | |
| 107 | foreach ($this->getDocBlock()->getTagsByName('requiresRight') as $tag) { |
| 108 | if ($tag instanceof RequiresRightTag) { |
| 109 | $privileges[$tag->getParameterName()] = $tag->getRightId(); |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | return $privileges; |
| 114 | } |
| 115 | } |