handleOutput() public static method

The response body can be written to a file, returned, echoed or passed to a custom function. The response header might be passed to a custom function.
public static handleOutput ( Response $response, array $curlOptions, resource $ch ) : null | string
$response VCR\Response Response which contains the response body.
$curlOptions array cURL options which are not stored within the Response.
$ch resource cURL handle to add headers if needed.
return null | string
Example #1
0
 /**
  * Perform a cURL session.
  *
  * @link http://www.php.net/manual/en/function.curl-exec.php
  * @param resource $curlHandle A cURL handle returned by curl_init().
  *
  * @return mixed Returns TRUE on success or FALSE on failure.
  * However, if the CURLOPT_RETURNTRANSFER option is set, it will return the
  * result on success, FALSE on failure.
  */
 public static function curlExec($curlHandle)
 {
     $requestCallback = self::$requestCallback;
     self::$responses[(int) $curlHandle] = $requestCallback(self::$requests[(int) $curlHandle]);
     return CurlHelper::handleOutput(self::$responses[(int) $curlHandle], self::$curlOptions[(int) $curlHandle], $curlHandle);
 }
Example #2
0
 /**
  * Perform a cURL session.
  *
  * @link http://www.php.net/manual/en/function.curl-exec.php
  * @param resource $curlHandle A cURL handle returned by curl_init().
  *
  * @return mixed Returns TRUE on success or FALSE on failure.
  * However, if the CURLOPT_RETURNTRANSFER option is set, it will return the
  * result on success, FALSE on failure.
  */
 public static function curlExec($curlHandle)
 {
     $request = self::$requests[(int) $curlHandle];
     CurlHelper::validateCurlPOSTBody($request, $curlHandle);
     $requestCallback = self::$requestCallback;
     self::$responses[(int) $curlHandle] = $requestCallback($request);
     return CurlHelper::handleOutput(self::$responses[(int) $curlHandle], self::$curlOptions[(int) $curlHandle], $curlHandle);
 }
Example #3
0
 public function testHandleResponseWritesFile()
 {
     vfsStream::setup('test');
     $expectedBody = 'example response';
     $testFile = vfsStream::url('test/write_file');
     $curlOptions = array(CURLOPT_FILE => fopen($testFile, 'w+'));
     $response = new Response(200, null, $expectedBody);
     CurlHelper::handleOutput($response, $curlOptions, curl_init());
     $this->assertEquals($expectedBody, file_get_contents($testFile));
 }