container = $container; } /** * @param Request $request * @param Response $response * @param mixed[] $args * * @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()); } /** * @param Request $request * @param Response $response * @param mixed[] $args * * @return Response * * @noinspection PhpUnusedParameterInspection * @throws Exception */ 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()); } /** * @param Request $request * @param Response $response * @param mixed[] $args * * @return Response * * @noinspection PhpUnusedParameterInspection * @throws Exception */ 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()); } /** * @param Response $response * @param WorkingHoursView[] $data * * @return Response */ protected function printResponse( Response $response, array $data): Response { $payload = json_encode($data); $response->getBody()->write($payload); return $response ->withHeader('Content-Type', 'application/json') ->withStatus(200); } }