implement TLS/socket client

This commit is contained in:
yggverse 2024-04-03 02:11:07 +03:00
parent 0973828a82
commit edf0234056
3 changed files with 287 additions and 1 deletions

58
src/Client/Response.php Normal file
View file

@ -0,0 +1,58 @@
<?php
declare(strict_types=1);
namespace Yggverse\Gemini\Client;
class Response
{
private ?int $_code = null;
private ?string $_meta = null;
private ?string $_body = null;
public function __construct(string $data)
{
$match = [];
preg_match(
'/(?<status>\d{2})\s(?<meta>.*)\r\n(?<body>.*)/su',
$data,
$match
);
if (isset($match['code']))
{
$code = (int) $match['code'];
if ($code >= 10 && $code <= 69)
{
$this->_code = $match['code'];
}
}
if (isset($match['meta']) && mb_strlen($match['meta']) <= 1024)
{
$this->_meta = (string) $match['meta'];
}
if (isset($match['body']))
{
$this->_body = (string) $match['body'];
}
}
public function getCode(): ?int
{
return $this->_code;
}
public function getMeta(): ?string
{
return $this->_meta;
}
public function getBody(): ?string
{
return $this->_body;
}
}