-
Notifications
You must be signed in to change notification settings - Fork 0
/
FetchResult.php
41 lines (31 loc) · 873 Bytes
/
FetchResult.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php namespace rogoss\Curl;
class FetchResult {
/** @var string */
public $protokoll = "";
/** @var int */
public $status = 0;
/** @var string */
public $statusText = "";
/** @var string */
public $body = "";
/** @var array */
public $headers = [];
public function __construct($r)
{
$aParts = explode("\n\n", str_replace("\r", "", $r), 2);
$this->body = $aParts[1] ?? "";
$sHeaders = $aParts[0] ?? "";
unset($aParts);
$aHeaderLines = explode("\n", $sHeaders);
$aStatusLine = explode(" ", $aHeaderLines[0], 3);
$this->protokoll = $aStatusLine[0];
$this->status = (int)$aStatusLine[1];
$this->statusText = $aStatusLine[2];
unset($aStatusLine, $aHeaderLines[0]);
foreach($aHeaderLines as $sHeaderLine) {
$aParts = explode(": ", $sHeaderLine);
$this->headers[strtolower($aParts[0])] = $aParts[1];
unset($aParts);
}
}
}