-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
73 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,73 @@ | ||
<?php | ||
namespace phpgt\fetch; | ||
|
||
/** | ||
* @property-read bool $bodyUsed Indicates whether the body has been read yet | ||
* @property-read Headers $headers Contains the Headers object associated | ||
* with the response | ||
* @property-read bool $ok Whether the response was successful (status in | ||
* the range 200-299) or not | ||
* @property-read int $status The status code of the response | ||
* @property-read string $statusText The status message corresponding to the | ||
* status code | ||
* @property-read string $type Type of the response (basic, cors, error | ||
* or opaque) | ||
* @property-read string $url The URL of the response | ||
* | ||
*/ | ||
class Response { | ||
|
||
private $curlInfo; | ||
private $headers = []; | ||
private $body; | ||
|
||
public function __construct(string $rawResponse, array $curlInfo) { | ||
$headerSize = $curlInfo["header_size"]; | ||
$headerString = substr($rawResponse, 0, $headerSize); | ||
foreach(explode("\n", $headerString) as $line) { | ||
$kvp = explode(":", $line); | ||
if(!isset($kvp[1])) { | ||
continue; | ||
} | ||
|
||
$this->headers[trim($kvp[0])] = trim($kvp[1]); | ||
} | ||
|
||
$this->body = substr($rawResponse, $headerSize); | ||
$this->curlInfo = $curlInfo; | ||
} | ||
|
||
// TODO: Move these functions to the `Body` trait. (Issue #8). | ||
|
||
public function arrayBuffer() { | ||
|
||
} | ||
|
||
public function blob() { | ||
|
||
} | ||
|
||
public function clone() { | ||
|
||
} | ||
|
||
public function error() { | ||
|
||
} | ||
|
||
public function formData() { | ||
|
||
} | ||
|
||
public function json() { | ||
|
||
} | ||
|
||
public function redirect() { | ||
|
||
} | ||
|
||
public function text() { | ||
|
||
} | ||
}# |