1
0
Fork 0
mirror of https://github.com/Yetangitu/ampache synced 2025-10-05 10:49:37 +02:00
ampache/modules/Dropbox/CurlStreamRelay.php
Afterster 1711cd14ff Fix Soundcloud and Dropbox catalog modules since SSE
Update php-dropbox to latest version (fix SSLv3 issue)
2015-02-14 11:23:52 +01:00

45 lines
1 KiB
PHP

<?php
namespace Dropbox;
/**
* A CURLOPT_WRITEFUNCTION that will write HTTP response data to $outStream if
* it's an HTTP 200 response. For all other HTTP status codes, it'll save the
* output in a string, which you can retrieve it via {@link getErrorBody}.
*
* @internal
*/
class CurlStreamRelay
{
var $outStream;
var $errorData;
var $isError;
function __construct($ch, $outStream)
{
$this->outStream = $outStream;
$this->errorData = array();
$isError = null;
curl_setopt($ch, CURLOPT_WRITEFUNCTION, array($this, 'writeData'));
}
function writeData($ch, $data)
{
if ($this->isError === null) {
$statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$this->isError = ($statusCode !== 200);
}
if ($this->isError) {
$this->errorData[] = $data;
} else {
fwrite($this->outStream, $data);
}
return strlen($data);
}
function getErrorBody()
{
return implode($this->errorData);
}
}