ringfinger/backend/classes/api/ApiJsonResponse.php

27 lines
497 B
PHP
Raw Normal View History

2020-08-17 23:46:58 +02:00
<?php
declare(strict_types=1);
final class ApiJsonResponse extends ApiResponse
{
2020-08-23 12:37:39 +02:00
protected string $mimeType = MimeType::JSON;
2020-08-17 23:46:58 +02:00
2020-08-23 12:37:39 +02:00
public function __construct(int $status = ServerStatus::OK)
{
parent::__construct($status);
2020-08-17 23:46:58 +02:00
2020-08-23 12:37:39 +02:00
$this->setParameter('success', true);
}
2020-08-17 23:46:58 +02:00
2020-08-23 12:37:39 +02:00
public function setResult(JsonSerializable $result): void
{
$this->setParameter('result', $result->jsonSerialize());
}
2020-08-17 23:46:58 +02:00
2020-08-23 12:37:39 +02:00
public function respond(): void
{
parent::respond();
2020-08-17 23:46:58 +02:00
2020-08-23 12:37:39 +02:00
echo json_encode($this->parameters);
}
2020-08-17 23:46:58 +02:00
}