Files
grocy/controllers/BaseApiController.php

43 lines
956 B
PHP
Raw Normal View History

2018-04-11 19:49:35 +02:00
<?php
namespace Grocy\Controllers;
class BaseApiController extends BaseController
{
2020-08-31 20:40:31 +02:00
protected $OpenApiSpec = null;
public function __construct(\DI\Container $container)
{
parent::__construct($container);
}
protected function ApiResponse(\Psr\Http\Message\ResponseInterface $response, $data)
{
$response->getBody()->write(json_encode($data));
return $response;
}
protected function EmptyApiResponse(\Psr\Http\Message\ResponseInterface $response, $status = 204)
{
return $response->withStatus($status);
}
protected function GenericErrorResponse(\Psr\Http\Message\ResponseInterface $response, $errorMessage, $status = 400)
2018-04-11 19:49:35 +02:00
{
2020-08-31 20:40:31 +02:00
return $response->withStatus($status)->withJson([
'error_message' => $errorMessage
2020-08-31 20:40:31 +02:00
]);
2018-04-11 19:49:35 +02:00
}
2020-08-31 20:40:31 +02:00
protected function getOpenApispec()
{
if ($this->OpenApiSpec == null)
{
$this->OpenApiSpec = json_decode(file_get_contents(__DIR__ . '/../grocy.openapi.json'));
}
return $this->OpenApiSpec;
}
2018-04-11 19:49:35 +02:00
}