You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Application-Web/src/Http/JsonHttpResponse.php

29 lines
592 B

<?php
namespace App\Http;
class JsonHttpResponse extends HttpResponse {
/**
* @var mixed Any JSON serializable value
*/
private $payload;
/**
* @param mixed $payload
*/
public function __construct($payload, int $code = HttpCodes::OK) {
parent::__construct($code, []);
$this->payload = $payload;
}
public function getJson(): string {
$result = json_encode($this->payload);
if (!$result) {
throw new \RuntimeException("Given payload is not json encodable");
}
return $result;
}
}