mirror of
https://github.com/YGGverse/gemini-php.git
synced 2025-01-12 16:18:09 +00:00
allow nullable response init
This commit is contained in:
parent
d7d6083634
commit
c38cdc841f
@ -10,40 +10,43 @@ class Response
|
||||
private ?string $_meta = null;
|
||||
private ?string $_body = null;
|
||||
|
||||
public function __construct(string $data)
|
||||
public function __construct(?string $data = null)
|
||||
{
|
||||
$match = [];
|
||||
|
||||
preg_match(
|
||||
'/(?<status>\d{2})\s(?<meta>.*)\r\n(?<body>.*)/su',
|
||||
$data,
|
||||
$match
|
||||
);
|
||||
|
||||
if (isset($match['code']))
|
||||
if ($data)
|
||||
{
|
||||
$code = (int) $match['code'];
|
||||
$match = [];
|
||||
|
||||
if ($code >= 10 && $code <= 69)
|
||||
preg_match(
|
||||
'/(?<status>\d{2})\s(?<meta>.*)\r\n(?<body>.*)/su',
|
||||
$data,
|
||||
$match
|
||||
);
|
||||
|
||||
if (isset($match['code']))
|
||||
{
|
||||
$this->setCode(
|
||||
$code
|
||||
$code = (int) $match['code'];
|
||||
|
||||
if ($code >= 10 && $code <= 69)
|
||||
{
|
||||
$this->setCode(
|
||||
$code
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($match['meta']) && mb_strlen($match['meta']) <= 1024)
|
||||
{
|
||||
$this->setMeta(
|
||||
(string) $match['meta']
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($match['meta']) && mb_strlen($match['meta']) <= 1024)
|
||||
{
|
||||
$this->setMeta(
|
||||
(string) $match['meta']
|
||||
);
|
||||
}
|
||||
|
||||
if (isset($match['body']))
|
||||
{
|
||||
$this->setBody(
|
||||
(string) (string) $match['body']
|
||||
);
|
||||
if (isset($match['body']))
|
||||
{
|
||||
$this->setBody(
|
||||
(string) (string) $match['body']
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user