Example #1
0
 /**
  * @param \Blar\Curl\Curl $curl Curl.
  * @param \Blar\Http\HttpResponse $response Response.
  * @return $this
  */
 protected function configureCurl(Curl $curl, HttpResponse $response)
 {
     $curl->setMethod($this->getMethod());
     $curl->setUrl($this->getUrl());
     if ($this->getHeaders()) {
         $headers = $this->createHeadersArray($this->getHeaders());
         $curl->setOption(CURLOPT_HTTPHEADER, $headers);
     }
     if ($this->getBody()) {
         $curl->setBody($this->getBody());
     }
     $curl->setHeaderCallback(function ($header) use($response) {
         $response->setHeaderLine($header);
     });
     $curl->setWriteCallback(function ($part) use($response) {
         $response->addBodyPart($part);
     });
     return $this;
 }
Example #2
0
 public function testWriteCallback()
 {
     $curl = new Curl();
     $curl->setUrl('http://httpbin.org/get?foo=23&bar=42');
     $curl->setWriteCallback(function ($part) use(&$response) {
         $response .= $part;
     });
     $curl->execute();
     $data = json_decode($response);
     $this->assertEquals(23, $data->args->foo);
     $this->assertEquals(42, $data->args->bar);
 }