Files
oficial/app/src/Controller/API/withJson.php
2025-01-17 00:04:11 -03:00

14 lines
395 B
PHP

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