Files
oficial/app/src/Controller/API/withJson.php

14 lines
395 B
PHP
Raw Normal View History

2023-10-13 10:45:21 -03:00
<?php
namespace Incoviba\Controller\API;
use Psr\Http\Message\ResponseInterface;
trait withJson
{
2025-01-17 00:04:11 -03:00
public function withJson(ResponseInterface $response, array|object $data = [], int $statusCode = 200): ResponseInterface
2023-10-13 10:45:21 -03:00
{
$response->getBody()->write(json_encode($data));
2025-01-17 00:04:11 -03:00
return $response->withStatus($statusCode)->withHeader('Content-Type', 'application/json');
2023-10-13 10:45:21 -03:00
}
}