Bicycle/System/Classes/HTTP/Client/Response.php
Egor Isaev b516ca07dc Initial commit: Bicycle PHP MVC micro-framework
Core MVC, HTTP client, Session, Cookie, Config, HTTPException — 111 PHPUnit tests.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-04 10:04:19 +03:00

46 lines
837 B
PHP

<?php
/**
* @package Bicycle
* @author Egor Isaev
* @description HTTP/Client/Response.php
* @copyright (c) 04/06/2026
*/
namespace System\Classes\HTTP\Client;
use JsonException;
class Response
{
public function __construct(
private readonly int $status,
private readonly string $body
) {}
public function status(): int
{
return $this->status;
}
public function body(): string
{
return $this->body;
}
public function isSuccess(): bool
{
return $this->status >= 200 && $this->status < 300;
}
/**
* @throws JsonException
*/
public function json(): array
{
if ($this->body === '') {
return [];
}
return json_decode($this->body, true, 512, JSON_THROW_ON_ERROR);
}
}