php-censor/src/B8Framework/Http/Response/JsonResponse.php

30 lines
562 B
PHP
Raw Normal View History

2016-04-12 19:31:39 +02:00
<?php
namespace b8\Http\Response;
use b8\Http\Response;
class JsonResponse extends Response
{
2016-04-20 17:39:48 +02:00
public function __construct(Response $createFrom = null)
{
parent::__construct($createFrom);
2016-04-12 19:31:39 +02:00
2016-04-20 17:39:48 +02:00
$this->setContent([]);
$this->setHeader('Content-Type', 'application/json');
}
2016-04-12 19:31:39 +02:00
2016-04-20 17:39:48 +02:00
public function hasLayout()
{
return false;
}
2016-04-12 19:31:39 +02:00
2016-04-20 17:39:48 +02:00
protected function flushBody()
{
if (isset($this->data['body'])) {
return json_encode($this->data['body']);
}
2016-04-12 19:31:39 +02:00
2016-04-20 17:39:48 +02:00
return json_encode(null);
}
2016-04-12 19:31:39 +02:00
}