API
This commit is contained in:
16
api/common/Implement/Controller/Json.php
Normal file
16
api/common/Implement/Controller/Json.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?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');
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user