diff --git a/api/src/Controller/WorkingHoursViewController.php b/api/src/Controller/WorkingHoursViewController.php index 1386464..89bd57e 100644 --- a/api/src/Controller/WorkingHoursViewController.php +++ b/api/src/Controller/WorkingHoursViewController.php @@ -4,6 +4,7 @@ namespace TorstenHettstedt\TimekeepingApi\Controller; use Exception; +use PDO; use Psr\Container\ContainerInterface; use Slim\Psr7\Request; use Slim\Psr7\Response; @@ -14,13 +15,26 @@ use TorstenHettstedt\TimekeepingApi\Repositories\WorkingHoursYearlyViewRepositor class WorkingHoursViewController { + protected PDO $databases; + /** * @var ContainerInterface */ protected ContainerInterface $container; + /** + * WorkingHoursViewController constructor. + * + * @param ContainerInterface $container + * + * @throws NotDatabasesException + */ public function __construct(ContainerInterface $container) { $this->container = $container; + if ($container->has('databases') === false) { + throw new NotDatabasesException('Datenbank ist nicht Vorhanden'); + } + $this->databases = $container->get('databases'); } /** @@ -31,14 +45,10 @@ class WorkingHoursViewController * @return Response * * @noinspection PhpUnusedParameterInspection - * @throws NotDatabasesException * @throws Exception */ public function browseWeekly(Request $request, Response $response, array $args): Response { - if ($this->container->has('databases') === false) { - throw new NotDatabasesException('Datenbank ist nicht Vorhanden'); - } $repository = new WorkingHoursWeeklyViewRepository($this->container->get('databases')); return $this->printResponse($response, $repository->findAll()); } @@ -55,9 +65,6 @@ class WorkingHoursViewController */ public function browseMonthly(Request $request, Response $response, array $args): Response { - if ($this->container->has('databases') === false) { - throw new NotDatabasesException('Datenbank ist nicht Vorhanden'); - } $repository = new WorkingHoursMonthlyViewRepository($this->container->get('databases')); return $this->printResponse($response, $repository->findAll()); } @@ -74,9 +81,6 @@ class WorkingHoursViewController */ public function browseYearly(Request $request, Response $response, array $args): Response { - if ($this->container->has('databases') === false) { - throw new NotDatabasesException('Datenbank ist nicht Vorhanden'); - } $repository = new WorkingHoursYearlyViewRepository($this->container->get('databases')); return $this->printResponse($response, $repository->findAll()); }