torneos/app/Core/Response.php

19 lines
502 B
PHP

<?php
namespace App\Core;
final class Response
{
public static function json(mixed $data, int $status = 200): void
{
http_response_code($status);
header('Content-Type: application/json; charset=utf-8');
echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
}
public static function error(string $message, int $status = 400, array $errors = []): void
{
self::json(['message' => $message, 'errors' => $errors], $status);
}
}