Json controller trait
This commit is contained in:
13
common/Define/Controller/Json.php
Normal file
13
common/Define/Controller/Json.php
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
namespace ProVM\Common\Define\Controller;
|
||||||
|
|
||||||
|
use Psr\Http\Message\ResponseInterface as Response;
|
||||||
|
|
||||||
|
trait Json {
|
||||||
|
public function withJson(Response $response, $output, $status = 200) {
|
||||||
|
$response->getBody()->write(json_encode($output));
|
||||||
|
return $response
|
||||||
|
->withHeader('Content-Type', 'application/json')
|
||||||
|
->withStatus($status);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user