mirror of
https://github.com/YGGverse/gemini-php.git
synced 2026-03-31 17:05:29 +00:00
implement TLS/socket client
This commit is contained in:
parent
0973828a82
commit
edf0234056
3 changed files with 287 additions and 1 deletions
58
src/Client/Response.php
Normal file
58
src/Client/Response.php
Normal 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;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue