52 lines
1.4 KiB
PHP
52 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace TorstenHettstedt\TimekeepingApi\Controller;
|
|
|
|
use JsonSerializable;
|
|
use PDO;
|
|
use Psr\Container\ContainerExceptionInterface;
|
|
use Psr\Container\ContainerInterface;
|
|
use Psr\Container\NotFoundExceptionInterface;
|
|
use Slim\Psr7\Response;
|
|
|
|
abstract class AbstractController
|
|
{
|
|
|
|
protected PDO $databases;
|
|
|
|
/**
|
|
* WorkingHoursController constructor.
|
|
*
|
|
* @param ContainerInterface $container
|
|
*
|
|
* @throws NotDatabasesException
|
|
* @throws ContainerExceptionInterface
|
|
* @throws NotFoundExceptionInterface
|
|
*/
|
|
public function __construct(ContainerInterface $container)
|
|
{
|
|
if ($container->has('databases') === false) {
|
|
throw new NotDatabasesException('Datenbank ist nicht Vorhanden');
|
|
}
|
|
$this->databases = $container->get('databases');
|
|
}
|
|
|
|
/**
|
|
* @param Response $response
|
|
* @param JsonSerializable|JsonSerializable[] $data
|
|
* @param int $status_code
|
|
*
|
|
* @return Response
|
|
*/
|
|
protected function printResponse(Response $response, mixed $data, int $status_code): Response
|
|
{
|
|
$payload = json_encode($data);
|
|
|
|
$response->getBody()->write($payload);
|
|
|
|
return $response
|
|
->withHeader('Content-Type', 'application/json')
|
|
->withStatus($status_code);
|
|
}
|
|
|
|
} |