示例#1
0
 public function testResponse()
 {
     $response = new Response();
     $this->assertNull($response->getStatusCode());
     $this->assertNull($response->getReasonPhrase());
     $response->withStatus('200', 'OK');
     $this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
     $this->assertEquals('OK', $response->getReasonPhrase());
 }
示例#2
0
 /**
  * {@inheritDoc}
  */
 public function execute(RequestInterface $request)
 {
     if (null === self::$ch) {
         self::$ch = curl_init();
     }
     $uri = $request->getUri();
     curl_setopt(self::$ch, CURLOPT_URL, sprintf('%s://%s@%s', $uri->getScheme(), $uri->getUserInfo(), $uri->getHost()));
     curl_setopt(self::$ch, CURLOPT_PORT, $uri->getPort());
     $headers = array();
     foreach ($request->getHeaders() as $header => $values) {
         $headers[] = $header . ': ' . implode(', ', $values);
     }
     curl_setopt(self::$ch, CURLOPT_HTTPHEADER, $headers);
     curl_setopt_array(self::$ch, array_merge($this->getDefaultCurlOptions(), $this->curlOptions));
     curl_setopt(self::$ch, CURLOPT_POSTFIELDS, $request->getBody()->getContents());
     $result = curl_exec(self::$ch);
     $info = curl_getinfo(self::$ch);
     $error = curl_error(self::$ch);
     $response = new Response();
     $response->withStatus($info['http_code']);
     $response->getBody()->write($result);
     return $response;
 }