chore: Аннотации к типам
This commit is contained in:
parent
530a3b931d
commit
730a608f9b
27 changed files with 491 additions and 134 deletions
|
|
@ -3,27 +3,31 @@
|
|||
namespace ctiso\Connection;
|
||||
use ctiso\File;
|
||||
|
||||
class HttpRequest
|
||||
class HttpRequest
|
||||
{
|
||||
const POST = "POST";
|
||||
const GET = "GET";
|
||||
|
||||
private $param = array(); // Параметры запроса
|
||||
private $param = []; // Параметры запроса
|
||||
public $data = null; // Содержание
|
||||
public $url; // Адресс
|
||||
public $method; // Метод
|
||||
/** @var int */
|
||||
public $port = 80;
|
||||
/** @var string */
|
||||
public $host = "";
|
||||
public $proxy_host = null;
|
||||
public $proxy_port = null;
|
||||
/** @var string */
|
||||
public $http_version = 'HTTP/1.1';
|
||||
|
||||
function __construct() {
|
||||
$this->method = self::GET;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Возвращает заголовок соединения
|
||||
* @return string
|
||||
*/
|
||||
public function getHeader()
|
||||
{
|
||||
|
|
@ -36,11 +40,11 @@ class HttpRequest
|
|||
$result .= $this->data;
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Установка параметров запроса
|
||||
* @parma string $name
|
||||
* @parma string $value
|
||||
* @param string $name
|
||||
* @param string $value
|
||||
*/
|
||||
public function setParameter($name, $value)
|
||||
{
|
||||
|
|
@ -49,29 +53,35 @@ class HttpRequest
|
|||
|
||||
/**
|
||||
* Метод запроса GET или POST
|
||||
* @param string $method
|
||||
*/
|
||||
public function setMethod($method)
|
||||
public function setMethod($method): void
|
||||
{
|
||||
$this->method = $method;
|
||||
}
|
||||
|
||||
public function setUrl($url)
|
||||
/**
|
||||
* Установка URL
|
||||
* @param string $url
|
||||
*/
|
||||
public function setUrl($url): void
|
||||
{
|
||||
$this->url = $url;
|
||||
$this->host = parse_url($this->url, PHP_URL_HOST);
|
||||
}
|
||||
|
||||
public function getUrl()
|
||||
public function getUrl(): string
|
||||
{
|
||||
return $this->url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Содержание запроса
|
||||
* @param string $data
|
||||
*/
|
||||
public function setContent($data)
|
||||
public function setContent($data): void
|
||||
{
|
||||
$this->setParameter ("Content-length", strlen($data));
|
||||
$this->setParameter("Content-length", (string)strlen($data));
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
|
|
@ -99,6 +109,12 @@ class HttpRequest
|
|||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Получение JSON
|
||||
* @param string $url
|
||||
* @param array $data
|
||||
* @return array
|
||||
*/
|
||||
static function getJSON($url, $data) {
|
||||
$query = http_build_query($data);
|
||||
$q = $url . '?' . $query;
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ namespace ctiso\Connection;
|
|||
class HttpResponse
|
||||
{
|
||||
private $offset;
|
||||
private $param = array ();
|
||||
private $param = [];
|
||||
private $code;
|
||||
public $response;
|
||||
public $version;
|
||||
|
|
@ -19,7 +19,7 @@ class HttpResponse
|
|||
$this->offset = 0;
|
||||
$this->response = $response;
|
||||
$this->parseMessage();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Обработка HTTP ответа
|
||||
|
|
@ -30,7 +30,7 @@ class HttpResponse
|
|||
$this->version = $http[0];
|
||||
$this->code = $http[1];
|
||||
|
||||
$line = $this->getLine();
|
||||
$line = $this->getLine();
|
||||
while ($offset = strpos($line, ":")) {
|
||||
$this->param[substr($line, 0, $offset)] = trim(substr($line, $offset + 1));
|
||||
$line = $this->getLine();
|
||||
|
|
@ -59,7 +59,7 @@ class HttpResponse
|
|||
{
|
||||
$begin = $this->offset;
|
||||
$offset = strpos($this->response, "\r\n", $this->offset);
|
||||
$result = substr($this->response, $begin, $offset - $begin);
|
||||
$result = substr($this->response, $begin, $offset - $begin);
|
||||
$this->offset = $offset + 2;
|
||||
return $result;
|
||||
}
|
||||
|
|
@ -67,20 +67,20 @@ class HttpResponse
|
|||
/**
|
||||
* Значение параметра HTTP ответа
|
||||
*/
|
||||
public function getParameter($name)
|
||||
public function getParameter($name)
|
||||
{
|
||||
return $this->param[$name];
|
||||
}
|
||||
|
||||
public function getData()
|
||||
public function getData()
|
||||
{
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Состояние
|
||||
* Состояние
|
||||
*/
|
||||
public function getCode()
|
||||
public function getCode()
|
||||
{
|
||||
return $this->code;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue