/** * Check if: * controller - is first parameter * method - is second parameter * rest of parameters - are sorted * * @author Jakub Olek <*****@*****.**> * * @throws WikiaException */ public final function init() { $webRequest = F::app()->wg->Request; $accessService = new ApiAccessService($this->getRequest()); $controller = $webRequest->getVal('controller'); $method = $webRequest->getVal('method'); $accessService->checkUse($controller . 'Controller', $method); //this is used for monitoring purposes, do not change unless you know what you are doing //should set api/v1 as the transaction name if (!$this->request->isInternal()) { Transaction::setEntryPoint(Transaction::ENTRY_POINT_API_V1); } if (!$this->request->isInternal()) { if ($this->hideNonCommercialContent()) { $this->blockIfNonCommercialOnly(); } $paramKeys = array_keys($webRequest->getQueryValues()); $count = count($paramKeys); if ($count >= 2 && $paramKeys[0] === 'controller' && $paramKeys[1] === 'method') { if ($count > 2) { $origParam = $paramKeys = array_flip(array_slice($paramKeys, 2)); ksort($paramKeys); ksort($origParam); if ($paramKeys !== $origParam) { throw new BadRequestApiException('The parameters\' order is incorrect'); } } } else { throw new BadRequestApiException('Controller and/or method missing'); } } }
protected function getApiMethods($api) { $apiDoc = $this->docsService->getDoc($api); $controller = $apiDoc['resourcePath'] . 'ApiController'; $result = []; foreach ($apiDoc['apis'] as $i => &$apiElem) { if ($this->accessService->canUse($controller, $apiElem['operations'][0]['nickname'])) { $result[] = $apiElem; } } return ['apis' => $result, 'models' => $apiDoc['models']]; }