Exemplo n.º 1
0
 /**
  * Forge a new object based on a request.
  * @param  RequestInterface $request
  * @return Response
  */
 public static function forge(RequestInterface $request)
 {
     $headerSize = $request->getInfo(CURLINFO_HEADER_SIZE);
     $response = $request->getRawResponse();
     $content = strlen($response) === $headerSize ? '' : substr($response, $headerSize);
     $rawHeaders = rtrim(substr($response, 0, $headerSize));
     $headers = array();
     foreach (preg_split('/(\\r?\\n)/', $rawHeaders) as $header) {
         if ($header) {
             $headers[] = $header;
         } else {
             $headers = array();
         }
     }
     $headerBag = array();
     $info = $request->getInfo();
     $status = explode(' ', $headers[0]);
     $status = explode('/', $status[0]);
     unset($headers[0]);
     foreach ($headers as $header) {
         list($key, $value) = explode(': ', $header);
         $headerBag[trim($key)] = trim($value);
     }
     $response = new static($content, $info['http_code'], $headerBag);
     $response->setProtocolVersion($status[1]);
     $response->setCharset(substr(strstr($response->headers->get('Content-Type'), '='), 1));
     return $response;
 }
Exemplo n.º 2
0
 /**
  * Add a REquest.
  *
  * @param  RequestInterface $request
  * @return int
  */
 public function add(RequestInterface $request)
 {
     // Tell the $request to use this handle.
     $request->addMultiHandle($this->handle);
     // Store the request.
     $this->requests[] = $request;
     // Return the request's key.
     return count($this->requests) - 1;
 }
Exemplo n.º 3
0
 /**
  * Update the associated request with the values of this container.
  * @return void
  */
 protected function updateRequest()
 {
     $headers = array();
     foreach ($this->all() as $key => $values) {
         foreach ($values as $value) {
             $headers[] = $key . ': ' . $value;
         }
     }
     $this->request->setOption(CURLOPT_HTTPHEADER, $headers);
 }
Exemplo n.º 4
0
Arquivo: Curl.php Projeto: evlsqd/curl
 /**
  * Sets a request's HTTP verb to PUT.
  *
  * @param RequestInterface $request
  */
 protected function preparePutRequest(RequestInterface $request, $data)
 {
     $request->setOption(CURLOPT_CUSTOMREQUEST, 'PUT');
     if ($data !== null) {
         $request->setOption(CURLOPT_POSTFIELDS, $data);
     }
 }
Exemplo n.º 5
0
 protected function preparePutRequest(RequestInterface $request, $data)
 {
     if ($data !== null) {
         // Write the PUT data to memory.
         $file = fopen('php://temp', 'rw+');
         fwrite($file, $data);
         rewind($file);
         // Add the PUT data to the request.
         $request->setOption(CURLOPT_INFILE, $file);
         $request->setOption(CURLOPT_INFILESIZE, strlen($data));
         $request->setOption(CURLOPT_PUT, true);
     } else {
         $request->setOption(CURLOPT_CUSTOMREQUEST, 'PUT');
     }
 }