Files
iblogs/src/Api/Response/MultiResponse.php
Sam Kintop bf3870ccca
Some checks failed
Publish Docker Image / build-and-push (push) Failing after 2m13s
all
2026-04-30 09:44:02 -05:00

39 lines
899 B
PHP

<?php
namespace Aternos\Mclogs\Api\Response;
class MultiResponse extends ApiResponse
{
protected int $httpCode = 207;
/**
* @var ApiResponse[]
*/
protected array $responses = [];
/**
* @param string $id
* @param ApiResponse $response
* @return $this
*/
public function addResponse(string $id, ApiResponse $response): static
{
$this->responses[$id] = $response;
return $this;
}
public function jsonSerialize(): array
{
$response = parent::jsonSerialize();
$results = [];
foreach ($this->responses as $id => $apiResponse) {
$result = $apiResponse->jsonSerialize();
$result["id"] = $id;
$result["status"] = $apiResponse->getHttpCode();
$results[] = $result;
}
$response["results"] = $results;
return $response;
}
}