Lines
100.00%
26 / 26
Methods
100.00%
4 / 4
Classes
100.00%
1 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| __invoke | 100.00% | 3 / 3 | 100.00% | 1 / 1 | 1 | ||
| buildQuery | 100.00% | 8 / 8 | 100.00% | 1 / 1 | 4 | ||
| buildHashFromParameterList | 100.00% | 10 / 10 | 100.00% | 1 / 1 | 4 | ||
| getWebcallDisplayUrl | 100.00% | 5 / 5 | 100.00% | 1 / 1 | 1 | ||
| 19 | abstract class BaseController extends \BO\Slim\Controller | |
| 20 | { | |
| 21 | protected static $hashParameter = ['webcalldisplay' => ['collections', 'queue']]; | |
| 22 | ||
| 23 | #[\Override] | |
| 24 | public function __invoke(RequestInterface $request, ResponseInterface $response, array $args) | |
| 25 | { | |
| 26 | $request = $this->initRequest($request); | |
| 27 | $noCacheResponse = \BO\Slim\Render::withLastModified($response, time(), '0'); | |
| 28 | return $this->readResponse($request, $noCacheResponse, $args); | |
| 29 | } | |
| 30 | ||
| 31 | protected function buildQuery(string $target, RequestInterface $request): string | |
| 32 | { | |
| 33 | $queryArr = []; | |
| 34 | $allParams = array_merge(static::$hashParameter[$target], ['template']); | |
| 35 | $currentQP = $request->getQueryParams(); | |
| 36 | foreach ($allParams as $parameter) { | |
| 37 | if (isset($currentQP[$parameter]) && $currentQP[$parameter]) { | |
| 38 | $queryArr[$parameter] = $currentQP[$parameter]; | |
| 39 | } | |
| 40 | } | |
| 41 | ||
| 42 | $queryArr['hmac'] = $this->buildHashFromParameterList($target, $request); | |
| 43 | ||
| 44 | return http_build_query($queryArr); | |
| 45 | } | |
| 46 | ||
| 47 | protected function buildHashFromParameterList(string $target, RequestInterface $request) | |
| 48 | { | |
| 49 | $paramsToHash = []; | |
| 50 | $currentQP = $request->getQueryParams(); | |
| 51 | foreach (static::$hashParameter[$target] as $parameter) { | |
| 52 | if (isset($currentQP[$parameter]) && $currentQP[$parameter]) { | |
| 53 | $paramsToHash[$parameter] = $currentQP[$parameter]; | |
| 54 | } | |
| 55 | } | |
| 56 | ||
| 57 | return SlimHelper::hashQueryParameters( | |
| 58 | $target, | |
| 59 | $paramsToHash, | |
| 60 | static::$hashParameter[$target] | |
| 61 | ); | |
| 62 | } | |
| 63 | ||
| 64 | /** | |
| 65 | * @SuppressWarnings(UnusedFormalParameter) | |
| 66 | * | |
| 67 | * @param RequestInterface $request | |
| 68 | * @param array $parameters | |
| 69 | * @return string | |
| 70 | */ | |
| 71 | protected function getWebcallDisplayUrl(RequestInterface $request, array $parameters) | |
| 72 | { | |
| 73 | $target = 'webcalldisplay'; | |
| 74 | $config = \App::$http->readGetResult('/config/')->getEntity(); | |
| 75 | ||
| 76 | $url = '' . $config->toProperty()->webcalldisplay->baseUrl->get(); | |
| 77 | $url .= '?' . $this->buildQuery($target, $request); | |
| 78 | ||
| 79 | return $url; | |
| 80 | } | |
| 81 | } |