16 lines
413 B
PHP
16 lines
413 B
PHP
|
<?php
|
||
|
namespace ProVM\Common\Implement\Controller;
|
||
|
|
||
|
use Psr\Http\Message\ResponseInterface;
|
||
|
|
||
|
trait Json
|
||
|
{
|
||
|
public function withJson(ResponseInterface $response, mixed $data, int $status = 200): ResponseInterface
|
||
|
{
|
||
|
$response->getBody()->write(\Safe\json_encode($data));
|
||
|
return $response
|
||
|
->withStatus($status)
|
||
|
->withHeader('Content-Type', 'application/json');
|
||
|
|
||
|
}
|
||
|
}
|