(
string $url,
array $headers = [],
bool $verifyTls = true,
int $connectTimeout = 10,
int $stallTimeout = 0,
?callable $errorHandler = null
)
| 32 | } |
| 33 | |
| 34 | public static function open( |
| 35 | string $url, |
| 36 | array $headers = [], |
| 37 | bool $verifyTls = true, |
| 38 | int $connectTimeout = 10, |
| 39 | int $stallTimeout = 0, |
| 40 | ?callable $errorHandler = null |
| 41 | ): self|false { |
| 42 | $stream = new self(); |
| 43 | $stream->errorHandler = $errorHandler; |
| 44 | $stream->buffer = @fopen(self::TEMP_STREAM, 'w+b'); |
| 45 | if ($stream->buffer === false) { |
| 46 | $stream->buffer = null; |
| 47 | $stream->fail('Unable to allocate WebDAV read buffer.'); |
| 48 | return false; |
| 49 | } |
| 50 | |
| 51 | $easy = curl_init(); |
| 52 | $multi = curl_multi_init(); |
| 53 | if ($easy === false || $multi === false) { |
| 54 | if (is_resource($stream->buffer)) { |
| 55 | @fclose($stream->buffer); |
| 56 | } |
| 57 | if ($easy !== false) { |
| 58 | curl_close($easy); |
| 59 | } |
| 60 | if ($multi !== false) { |
| 61 | curl_multi_close($multi); |
| 62 | } |
| 63 | $stream->buffer = null; |
| 64 | $stream->fail('Unable to initialize WebDAV read request.'); |
| 65 | return false; |
| 66 | } |
| 67 | |
| 68 | $stream->easyHandle = $easy; |
| 69 | $stream->multiHandle = $multi; |
| 70 | |
| 71 | $curlHeaders = []; |
| 72 | foreach ($headers as $key => $value) { |
| 73 | if (is_int($key)) { |
| 74 | $curlHeaders[] = (string)$value; |
| 75 | } else { |
| 76 | $curlHeaders[] = $key . ': ' . $value; |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | $options = [ |
| 81 | CURLOPT_URL => $url, |
| 82 | CURLOPT_RETURNTRANSFER => false, |
| 83 | CURLOPT_FOLLOWLOCATION => false, |
| 84 | CURLOPT_HTTPGET => true, |
| 85 | CURLOPT_WRITEFUNCTION => [$stream, 'handleWrite'], |
| 86 | CURLOPT_NOSIGNAL => true, |
| 87 | ]; |
| 88 | if ($curlHeaders !== []) { |
| 89 | $options[CURLOPT_HTTPHEADER] = $curlHeaders; |
| 90 | } |
| 91 | if ($connectTimeout > 0) { |
no test coverage detected