Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 26 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| MiddlewareManager | |
0.00% |
0 / 26 |
|
0.00% |
0 / 3 |
90 | |
0.00% |
0 / 1 |
| append | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
2 | |||
| detach | |
0.00% |
0 / 15 |
|
0.00% |
0 / 1 |
42 | |||
| getMiddlewareHandler | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| 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) 2021 (original work) Open Assessment Technologies SA |
| 19 | */ |
| 20 | |
| 21 | declare(strict_types=1); |
| 22 | |
| 23 | namespace oat\tao\model\Middleware; |
| 24 | |
| 25 | use oat\oatbox\service\ConfigurableService; |
| 26 | use oat\tao\model\Context\ContextInterface; |
| 27 | use oat\tao\model\Middleware\Context\MiddlewareContext; |
| 28 | |
| 29 | /** |
| 30 | * @deprecated Refer to generis/core/Middleware/README.md |
| 31 | */ |
| 32 | class MiddlewareManager extends ConfigurableService |
| 33 | { |
| 34 | /** |
| 35 | * @deprecated Refer to generis/core/Middleware/README.md |
| 36 | */ |
| 37 | public function append(ContextInterface $context): self |
| 38 | { |
| 39 | $middlewareId = $context->getParameter(MiddlewareContext::PARAM_MIDDLEWARE_ID); |
| 40 | $route = $context->getParameter(MiddlewareContext::PARAM_ROUTE); |
| 41 | |
| 42 | $map = $this->getMiddlewareHandler()->getOption(MiddlewareRequestHandler::OPTION_MAP); |
| 43 | |
| 44 | $this->getMiddlewareHandler()->setOption( |
| 45 | MiddlewareRequestHandler::OPTION_MAP, |
| 46 | array_merge_recursive($map, [$route => [$middlewareId]]) |
| 47 | ); |
| 48 | |
| 49 | return $this; |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * @deprecated Refer to generis/Middleware/README.md |
| 54 | */ |
| 55 | public function detach(ContextInterface $context): self |
| 56 | { |
| 57 | $middlewareId = $context->getParameter(MiddlewareContext::PARAM_MIDDLEWARE_ID); |
| 58 | $route = $context->getParameter(MiddlewareContext::PARAM_ROUTE); |
| 59 | |
| 60 | $map = $this->getMiddlewareHandler()->getOption(MiddlewareRequestHandler::OPTION_MAP); |
| 61 | |
| 62 | if ($middlewareId && $route) { |
| 63 | $routed = $map[$route]; |
| 64 | if ( |
| 65 | ($key = array_search( |
| 66 | $middlewareId, |
| 67 | $routed |
| 68 | )) !== false |
| 69 | ) { |
| 70 | unset($routed[$key]); |
| 71 | $map[$route] = $routed; |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | if ($route && !$middlewareId) { |
| 76 | unset($map[$route]); |
| 77 | } |
| 78 | |
| 79 | $this->getMiddlewareHandler()->setOption(MiddlewareRequestHandler::OPTION_MAP, array_filter($map)); |
| 80 | return $this; |
| 81 | } |
| 82 | |
| 83 | public function getMiddlewareHandler(): MiddlewareRequestHandler |
| 84 | { |
| 85 | if ($this->getServiceManager()->has(MiddlewareRequestHandler::SERVICE_ID)) { |
| 86 | return $this->getServiceManager()->get(MiddlewareRequestHandler::SERVICE_ID); |
| 87 | } |
| 88 | return new MiddlewareRequestHandler(); |
| 89 | } |
| 90 | } |