2018-01-28 17:17:19 +00:00
|
|
|
<?php
|
|
|
|
|
2021-09-13 18:51:12 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2018-01-28 17:17:19 +00:00
|
|
|
namespace Abraham\TwitterOAuth;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The result of the most recent API request.
|
|
|
|
*
|
|
|
|
* @author Abraham Williams <abraham@abrah.am>
|
|
|
|
*/
|
|
|
|
class Response
|
|
|
|
{
|
|
|
|
/** @var string|null API path from the most recent request */
|
|
|
|
private $apiPath;
|
|
|
|
/** @var int HTTP status code from the most recent request */
|
|
|
|
private $httpCode = 0;
|
|
|
|
/** @var array HTTP headers from the most recent request */
|
|
|
|
private $headers = [];
|
|
|
|
/** @var array|object Response body from the most recent request */
|
|
|
|
private $body = [];
|
|
|
|
/** @var array HTTP headers from the most recent request that start with X */
|
|
|
|
private $xHeaders = [];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $apiPath
|
|
|
|
*/
|
2021-09-13 18:51:12 +00:00
|
|
|
public function setApiPath(string $apiPath): void
|
2018-01-28 17:17:19 +00:00
|
|
|
{
|
|
|
|
$this->apiPath = $apiPath;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string|null
|
|
|
|
*/
|
2021-09-13 18:51:12 +00:00
|
|
|
public function getApiPath(): ?string
|
2018-01-28 17:17:19 +00:00
|
|
|
{
|
|
|
|
return $this->apiPath;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array|object $body
|
|
|
|
*/
|
|
|
|
public function setBody($body)
|
|
|
|
{
|
|
|
|
$this->body = $body;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array|object|string
|
|
|
|
*/
|
|
|
|
public function getBody()
|
|
|
|
{
|
|
|
|
return $this->body;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param int $httpCode
|
|
|
|
*/
|
2021-09-13 18:51:12 +00:00
|
|
|
public function setHttpCode(int $httpCode): void
|
2018-01-28 17:17:19 +00:00
|
|
|
{
|
|
|
|
$this->httpCode = $httpCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return int
|
|
|
|
*/
|
2021-09-13 18:51:12 +00:00
|
|
|
public function getHttpCode(): int
|
2018-01-28 17:17:19 +00:00
|
|
|
{
|
|
|
|
return $this->httpCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array $headers
|
|
|
|
*/
|
2021-09-13 18:51:12 +00:00
|
|
|
public function setHeaders(array $headers): void
|
2018-01-28 17:17:19 +00:00
|
|
|
{
|
|
|
|
foreach ($headers as $key => $value) {
|
|
|
|
if (substr($key, 0, 1) == 'x') {
|
|
|
|
$this->xHeaders[$key] = $value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$this->headers = $headers;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
2021-09-13 18:51:12 +00:00
|
|
|
public function getsHeaders(): array
|
2018-01-28 17:17:19 +00:00
|
|
|
{
|
|
|
|
return $this->headers;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array $xHeaders
|
|
|
|
*/
|
2021-09-13 18:51:12 +00:00
|
|
|
public function setXHeaders(array $xHeaders = []): void
|
2018-01-28 17:17:19 +00:00
|
|
|
{
|
|
|
|
$this->xHeaders = $xHeaders;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
2021-09-13 18:51:12 +00:00
|
|
|
public function getXHeaders(): array
|
2018-01-28 17:17:19 +00:00
|
|
|
{
|
|
|
|
return $this->xHeaders;
|
|
|
|
}
|
|
|
|
}
|