/**
  * @param string $name
  * @param mixed $default
  * @return mixed
  */
 public function request($name, $default = null)
 {
     //The RequestInterface expects this method to return values from a form submission or from
     //the decoded JSON body
     if ($this->data === null) {
         /* @var $contentType ContentType */
         $mediaType = $this->httpRequest->getHeaders('Content-type') ? $this->httpRequest->getHeaders('Content-type')->getFieldValue() : null;
         if ($mediaType == 'application/x-www-form-urlencoded' && ($this->httpRequest->isPut() || $this->httpRequest->isDelete())) {
             parse_str($this->httpRequest->getContent(), $this->data);
         } else {
             if ($mediaType == 'application/json' && ($this->httpRequest->isPost() || $this->httpRequest->isPut() || $this->httpRequest->isDelete())) {
                 $this->data = json_decode($this->httpRequest->getContent(), true);
             } else {
                 $this->data = $this->httpRequest->getPost()->toArray();
             }
         }
     }
     return isset($this->data[$name]) ? $this->data[$name] : $default;
 }
 public static function createFromRequest(BaseRequest $request)
 {
     $new = static::fromString($request->toString());
     $new->setQuery($request->getQuery());
     $new->setPost($request->getPost());
     $new->setCookies($request->getCookie());
     $new->setFiles($request->getFiles());
     $new->setServer($request->getServer());
     $new->setContent($request->getContent());
     $new->setEnv($request->getEnv());
     $headers = $request->getHeaders();
     $new->setHeaders($headers);
     return $new;
 }
Ejemplo n.º 3
0
 private function checkBody()
 {
     $content = parent::getContent();
     if (empty($content)) {
         return;
     }
     $json = json_decode($content, true);
     if (empty($json)) {
         throw new \Exception('Body Request is not a valid JSON' . "\n" . '(' . $content . ')');
     }
     foreach ($json as $name => $value) {
         if (!$this->checkParamName($name)) {
             throw new \Exception('Invalid param name (' . $name . ')');
         }
     }
     $this->bodyParameters = $json;
 }
Ejemplo n.º 4
0
 /**
  * Запись логов
  * @param Request $request
  * @param Response $response
  */
 public function write($request, $response)
 {
     $serverOptions = $request->getServer()->toArray();
     $requestUri = isset($serverOptions['REQUEST_URI']) ? $serverOptions['REQUEST_URI'] : null;
     // Проверка на запись от правильного запроса
     if (is_null($requestUri) || !preg_match($this->_patternRequestWriteLog, $requestUri)) {
         return;
     }
     $remoteAddr = isset($serverOptions['REMOTE_ADDR']) ? $serverOptions['REMOTE_ADDR'] : '';
     $requestTime = isset($serverOptions['REQUEST_TIME']) ? $serverOptions['REQUEST_TIME'] : 0;
     $requestTimeFloat = isset($serverOptions['REQUEST_TIME_FLOAT']) ? $serverOptions['REQUEST_TIME_FLOAT'] : 0;
     /** @var DocumentManager $dm */
     $dm = $this->getServiceLocator()->get('doctrine-document');
     $logsClient = new LogsClient();
     $logsClient->setDatetime((new \DateTime())->setTimestamp($requestTime))->setHeaders($request->getHeaders()->toString())->setRequest($request->getContent())->setResponse($response->getContent())->setIpAddress($remoteAddr)->setDuration(round(microtime(true), 4) - $requestTimeFloat);
     $dm->persist($logsClient);
     $dm->flush();
 }
Ejemplo n.º 5
0
 public function saveAction(Params $params, Request $request, Response $response, Form $form, Finder $finderService, Update $updateService, Form $form, View $view)
 {
     if ($request->getMethod() !== Request::METHOD_PUT) {
         return $view;
     }
     $id = $params('id');
     $entity = $finderService->find(['T4webTranslate' => ['Words' => ['Id' => (int) $id]]]);
     if (!$entity) {
         $response->setStatusCode(Response::STATUS_CODE_404);
         $view->setErrors(['message' => 'bad params']);
         return $view;
     }
     $data = Json::decode($request->getContent(), Json::TYPE_ARRAY);
     $form->setData($data);
     if (!$form->isValid()) {
         $response->setStatusCode(Response::STATUS_CODE_404);
         $view->setErrors($form->getMessages());
         return $view;
     }
     $entity->populate($data);
     $result = $updateService->update($id, $entity->extract());
     $view->setVariables($result->extract());
     return $view;
 }
Ejemplo n.º 6
0
 }
 $requestMethod = $request->getMethod();
 /*
  * Types (Whenever new types are defined update this comment too)
  * AE => Add event
  * DE => Delete event
  * GE => Get Events
  * UE => Update Events
  * LI => Logged in status
  */
 switch (strtoupper($requestMethod)) {
     case 'AE':
         //validation
         //Todo-Ambuj Perform validation like check for name
         //if(empty($_POST['EventName']) || empty($_POST['EventDesc']) || empty($_POST['EventDate']) || empty($_POST['EventTime']) || empty($_POST['EventLocation']) || empty($_POST['EventDressCode'])) {
         $body = $request->getContent();
         if (!$body) {
             $validate = false;
             $response = Response::createMessage("01");
             break;
         }
         $data = json_decode($body, true);
         if (!$data) {
             $validate = false;
             $response = Response::createMessage("04");
             break;
         }
         if (empty($data["EventName"]) && empty($data["EventDesc"]) && empty($data["EventDate"]) && empty($data["EventTime"]) && empty($data["EventLocation"]) && empty($data["EventDressCode"])) {
             $validate = false;
             $response = Response::createMessage("01");
             break;