| Total Complexity | 5 |
| Total Lines | 41 |
| Duplicated Lines | 0 % |
| Coverage | 39.13% |
| Changes | 0 | ||
| 1 | <?php |
||
| 11 | class BaseController extends Controller |
||
| 12 | { |
||
| 13 | /** @var Serializer */ |
||
| 14 | protected $serializer; |
||
| 15 | |||
| 16 | 14 | public function __construct(ServerRequestInterface $request) |
|
| 17 | { |
||
| 18 | 14 | parent::__construct($request); |
|
| 19 | 14 | $this->serializer = SerializerBuilder::create()->build(); |
|
| 20 | 14 | $this->disableView(); |
|
| 21 | 14 | $this->disableLayout(); |
|
| 22 | 14 | } |
|
| 23 | |||
| 24 | /** |
||
| 25 | * @param $object |
||
| 26 | * @param int $statusCode |
||
| 27 | */ |
||
| 28 | public function sendJsonObjectResponse($object, $statusCode = 200) |
||
| 29 | { |
||
| 30 | if (!is_object($object)) { |
||
| 31 | throw new InvalidArgumentException('You must pass an object.'); |
||
| 32 | } |
||
| 33 | $this->disableLayout(); |
||
| 34 | $this->disableView(); |
||
| 35 | $this->setHeader('Cache-Control', 'no-cache, must-revalidate'); |
||
| 36 | $this->setHeader('Expires','Mon, 26 Jul 1997 05:00:00 GMT'); |
||
| 37 | $this->setHeader('Content-Type','application/json'); |
||
| 38 | $json = $this->serializer->serialize($object, 'json'); |
||
| 39 | $this->setBody($json); |
||
| 40 | $this->setStatusCode($statusCode); |
||
| 41 | } |
||
| 42 | |||
| 43 | 5 | protected function httpMethodCheck($method) |
|
| 52 | } |
||
| 53 | } |