public function testPass() { $_POST['mykey1'] = 'hello'; $_GET['mykey2'] = 'asdasd'; $_POST['mykey3'] = 'asd'; $processor = new ParamsProcessor([new InputParam(InputParam::TYPE_POST, 'mykey1', InputParam::REQUIRED), new InputParam(InputParam::TYPE_GET, 'mykey2', InputParam::REQUIRED), new InputParam(InputParam::TYPE_POST, 'mykey3', InputParam::OPTIONAL)]); $this->assertFalse($processor->isError()); $this->assertEquals($processor->getValues(), ['mykey1' => 'hello', 'mykey2' => 'asdasd', 'mykey3' => 'asd']); }
/** * Process input parameters * * @param ApiHandlerInterface $handler * * @return array|bool */ private function processParams(ApiHandlerInterface $handler) { $paramsProcessor = new ParamsProcessor($handler->params()); if ($paramsProcessor->isError()) { $this->getHttpResponse()->setCode(Response::S500_INTERNAL_SERVER_ERROR); $this->sendResponse(new JsonResponse(['status' => 'error', 'message' => 'wrong input'])); return false; } return $paramsProcessor->getValues(); }