예제 #1
0
 /**
  * {@inheritDoc}
  */
 public function preSend(RequestInterface $request)
 {
     $content = $request->getContent();
     if (is_array($content) || $content instanceof \JsonSerializable) {
         $request->setContent(Json::encode($content));
         $request->addHeader('Content-Type: application/json');
     }
 }
예제 #2
0
 /**
  * Converts a request into an array for stream_context_create().
  *
  * @param RequestInterface $request A request object
  *
  * @return array An array for stream_context_create()
  */
 public function getStreamContextArray(RequestInterface $request)
 {
     $options = array('http' => array('method' => $request->getMethod(), 'header' => implode("\r\n", $request->getHeaders()), 'content' => $request->getContent(), 'protocol_version' => $request->getProtocolVersion(), 'ignore_errors' => $this->getIgnoreErrors(), 'max_redirects' => $this->getMaxRedirects(), 'timeout' => $this->getTimeout()), 'ssl' => array('verify_peer' => $this->getVerifyPeer()));
     if ($this->proxy) {
         $options['http']['proxy'] = $this->proxy;
         $options['http']['request_fulluri'] = true;
     }
     return $options;
 }
예제 #3
0
 /**
  * Populates uri, method and entityBody used to generate the Authentication header using the specified request object.
  * Appends the Authentication header if it is present and has been able to be calculated.
  *
  * @param RequestInterface $request  A request object
  */
 public function preSend(RequestInterface $request)
 {
     $this->setUri($request->getResource());
     $this->setMethod($request->getMethod());
     $this->setEntityBody($request->getContent());
     $header = $this->getHeader();
     if ($header) {
         $request->addHeader($header);
     }
 }
 public function preSend(RequestInterface $request)
 {
     $raw = $request->getContent();
     $url = new Url($this->apiBaseUrl . $request->getResource() . '.json');
     $request->setContent(json_encode($raw));
     $request->setHost($url->getHost());
     $request->setResource($url->getResource());
     $request->addHeader('Authorization: Bearer ' . $this->token);
     $request->addHeader('Accept: application/json');
     $request->addHeader('Content-Type: application/json');
 }
 /**
  * {@inheritDoc}
  *
  * @throws InvalidArgumentException
  */
 public function preSend(RequestInterface $request)
 {
     $parameters = array('login' => $this->login, 'password' => $this->password);
     $content_out = "";
     foreach ($parameters as $key => $param) {
         $content_out .= $key . ":" . $param;
         $content_out .= "\n";
     }
     $content = $request->getContent();
     parse_str($content, $content);
     $content = $content['SimpleRequest'];
     $content = iconv('KOI8-R', 'UTF-8', $content);
     $content = $content_out . $content;
     $content = iconv('UTF-8', 'KOI8-R', $content);
     $content = array('SimpleRequest' => $content);
     // var_dump($content);die;
     $request->setContent(http_build_query($content));
 }
 /**
  * {@inheritDoc}
  *
  * @throws InvalidArgumentException
  */
 public function preSend(RequestInterface $request)
 {
     $requestId = date('YmdHis.') . getmypid() . '@' . $this->partnerWebSite;
     $parameters = array('request-id' => $requestId);
     $content_out = "";
     foreach ($parameters as $key => $param) {
         $content_out .= $key . ":" . $param;
         $content_out .= "\n";
     }
     $content = $request->getContent();
     parse_str($content, $content);
     $content = $content['SimpleRequest'];
     $content = iconv('KOI8-R', 'UTF-8', $content);
     $content = $content_out . $content;
     $content = iconv('UTF-8', 'KOI8-R', $content);
     $content = array('SimpleRequest' => $content);
     // var_dump($content);die;
     $request->setContent(http_build_query($content));
 }
예제 #7
0
 /**
  * Returns a value for the CURLOPT_POSTFIELDS option.
  *
  * @return string|array A post fields value
  */
 private static function getPostFields(RequestInterface $request)
 {
     if (!$request instanceof FormRequestInterface) {
         return $request->getContent();
     }
     $fields = $request->getFields();
     $multipart = false;
     foreach ($fields as $name => $value) {
         if ($value instanceof FormUploadInterface) {
             $multipart = true;
             if ($file = $value->getFile()) {
                 // replace value with upload string
                 $fields[$name] = '@' . $file;
                 if ($contentType = $value->getContentType()) {
                     $fields[$name] .= ';type=' . $contentType;
                 }
             } else {
                 return $request->getContent();
             }
         }
     }
     return $multipart ? $fields : http_build_query($fields);
 }
예제 #8
0
 /**
  * Returns a value for the CURLOPT_POSTFIELDS option.
  *
  * @return string|array A post fields value
  */
 private static function getPostFields(RequestInterface $request)
 {
     if (!$request instanceof FormRequestInterface) {
         return $request->getContent();
     }
     $fields = $request->getFields();
     $multipart = false;
     foreach ($fields as $name => $value) {
         if (!$value instanceof FormUploadInterface) {
             continue;
         }
         if (!($file = $value->getFile())) {
             return $request->getContent();
         }
         $multipart = true;
         if (version_compare(PHP_VERSION, '5.5', '>=')) {
             $curlFile = new \CURLFile($file);
             if ($contentType = $value->getContentType()) {
                 $curlFile->setMimeType($contentType);
             }
             if (basename($file) != $value->getFilename()) {
                 $curlFile->setPostFilename($value->getFilename());
             }
             $fields[$name] = $curlFile;
         } else {
             // replace value with upload string
             $fields[$name] = '@' . $file;
             if ($contentType = $value->getContentType()) {
                 $fields[$name] .= ';type=' . $contentType;
             }
             if (basename($file) != $value->getFilename()) {
                 $fields[$name] .= ';filename=' . $value->getFilename();
             }
         }
     }
     return $multipart ? $fields : http_build_query($fields, '', '&');
 }
 /**
  * {@inheritDoc}
  */
 public function preSend(RequestInterface $request)
 {
     $request->setContent(preg_replace('/%5B(?:[0-9]|[1-9][0-9]+)%5D=/', '=', $request->getContent()));
     $request->setResource(preg_replace('/%5B(?:[0-9]|[1-9][0-9]+)%5D=/', '=', $request->getResource()));
 }
 /**
  * Transform request content to associative array
  *
  * @access protected
  * @param  RequestInterface $request
  * @return array
  */
 protected function getContentAsParameters(RequestInterface $request)
 {
     parse_str($request->getContent(), $parts);
     return $parts;
 }
예제 #11
0
 /**
  * @param RequestInterface $request
  * @param Response         $response
  */
 private function logResponse(RequestInterface $request, Response $response)
 {
     $this->logger->debug(sprintf('Request to %s%s with content "%s" was send and response with content "%s" and status %d received', $request->getHost(), $request->getResource(), $request->getContent(), $response->getContent(), $response->getStatusCode()));
 }
예제 #12
0
 /**
  * Converts a request into an array for stream_context_create().
  *
  * @param RequestInterface $request A request object
  *
  * @return array An array for stream_context_create()
  */
 public function getStreamContextArray(RequestInterface $request)
 {
     return array('http' => array('method' => $request->getMethod(), 'header' => implode("\r\n", $request->getHeaders()), 'content' => $request->getContent(), 'protocol_version' => $request->getProtocolVersion(), 'ignore_errors' => $this->getIgnoreErrors(), 'max_redirects' => $this->getMaxRedirects(), 'timeout' => $this->getTimeout()), 'ssl' => array('verify_peer' => $this->getVerifyPeer()));
 }
 public function postSend(RequestInterface $request, MessageInterface $response)
 {
     $this->data[] = array('request' => array('method' => $request->getMethod(), 'url' => sprintf('%s%s', $request->getHost(), $request->getResource()), 'headers' => $request->getHeaders(), 'content' => $request->getContent()), 'response' => array('statusCode' => $response->getStatusCode(), 'reasonPhrase' => $response->getReasonPhrase(), 'headers' => $response->getHeaders(), 'content' => $response->getContent()));
 }