Ejemplo n.º 1
0
 /**
  * Create array with params for specified handler
  *
  * @param ApiHandlerInterface $handler
  *
  * @return array
  */
 private function createParamsList(ApiHandlerInterface $handler)
 {
     return array_map(function (InputParam $param) {
         $parameter = ['type' => $param->getType(), 'key' => $param->getKey(), 'is_required' => $param->isRequired()];
         if ($param->getAvailableValues()) {
             $parameter['available_values'] = $param->getAvailableValues();
         }
         return $parameter;
     }, $handler->params());
 }
Ejemplo n.º 2
0
 /**
  * Process given values to POST and GET fields
  *
  * @param array $values
  *
  * @return array
  */
 private function processValues(array $values)
 {
     $params = $this->handler->params();
     $postFields = [];
     $rawPost = isset($values['post_raw']) ? $values['post_raw'] : false;
     $getFields = [];
     $putFields = [];
     $cookieFields = [];
     foreach ($values as $key => $value) {
         if (strstr($key, '___') !== false) {
             $parts = explode('___', $key);
             $key = $parts[0];
         }
         foreach ($params as $param) {
             $valueData = $this->processParam($param, $key, $value);
             if ($valueData === null) {
                 continue;
             }
             if ($param->isMulti()) {
                 if (in_array($param->getType(), [InputParam::TYPE_POST, InputParam::TYPE_FILE])) {
                     $postFields[$key][] = $valueData;
                 } elseif ($param->getType() == InputParam::TYPE_PUT) {
                     $putFields[$key][] = $valueData;
                 } elseif ($param->getType() == InputParam::TYPE_COOKIE) {
                     $cookieFields[$key][] = $valueData;
                 } else {
                     $getFields[$key][] = $valueData;
                 }
             } else {
                 if (in_array($param->getType(), [InputParam::TYPE_POST, InputParam::TYPE_FILE])) {
                     $postFields[$key] = $valueData;
                 } elseif ($param->getType() == InputParam::TYPE_PUT) {
                     $putFields[$key] = $valueData;
                 } elseif ($param->getType() == InputParam::TYPE_COOKIE) {
                     $cookieFields[$key] = $valueData;
                 } else {
                     $getFields[$key] = $valueData;
                 }
             }
         }
     }
     return [$postFields, $getFields, $cookieFields, $rawPost, $putFields];
 }
Ejemplo n.º 3
0
 /**
  * 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();
 }