From 4da5c1242c0238d50b8d1244b0a488b6b6fd4b61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20L=C3=BCcke?= Date: Tue, 6 Apr 2021 16:26:43 +0200 Subject: [PATCH] Die Verbindung zur Datenbank ist eingebaut. --- api/.env | 5 +++++ api/Dockerfile | 4 ++++ api/composer.json | 1 + api/html/index.php | 12 ++++++++++++ 4 files changed, 22 insertions(+) create mode 100644 api/.env diff --git a/api/.env b/api/.env new file mode 100644 index 0000000..f904bd0 --- /dev/null +++ b/api/.env @@ -0,0 +1,5 @@ +## Datenbank-Einstellungen +DATABASES_HOST=psql.torsten-hettstedt.net +DATABASES_NAME=torsten +DATABASES_USER=web_user +DATABASES_PASS=V6ZGhtdXEbxH8oWD \ No newline at end of file diff --git a/api/Dockerfile b/api/Dockerfile index 8707838..d7ad578 100644 --- a/api/Dockerfile +++ b/api/Dockerfile @@ -1,5 +1,9 @@ FROM php:8.0-apache +#RUN apt update && apt install -y postgresql postgresql-client +RUN apt update && apt install -y libpq-dev +RUN docker-php-ext-install -j$(nproc) pdo pdo_pgsql + WORKDIR /var/www RUN a2enmod rewrite \ No newline at end of file diff --git a/api/composer.json b/api/composer.json index c38794f..ef94ac7 100644 --- a/api/composer.json +++ b/api/composer.json @@ -19,6 +19,7 @@ "slim/slim": "^4.7.1", "vlucas/phpdotenv": "^4.2", "slim/psr7": "^1.3", + "php-di/slim-bridge": "^3.1.0", "jetbrains/phpstorm-attributes": "^1.0.0", "myclabs/php-enum": "^1.8.0" }, diff --git a/api/html/index.php b/api/html/index.php index 15cac14..9400c20 100644 --- a/api/html/index.php +++ b/api/html/index.php @@ -1,8 +1,20 @@ load(); + +use DI\Container; use Slim\Factory\AppFactory; +$container = new Container(); + +$container->set('databases', function () { + $dsn = "pgsql:host=${_ENV['DATABASES_HOST']};port=5432;dbname=${_ENV['DATABASES_NAME']}"; + return new PDO($dsn, $_ENV['DATABASES_USER'], $_ENV['DATABASES_PASS']); +}); + +AppFactory::setContainer($container); $app = AppFactory::create(); $app->get('/', 'TorstenHettstedt\TimekeepingApi\Controller\HelloWorldController:read');