From faec659fd254f6ca9f9b1b3c3ebd7b2da4c366be Mon Sep 17 00:00:00 2001 From: Evann Regnault Date: Wed, 12 Jun 2024 09:47:22 +0200 Subject: [PATCH] dotenv --- .env.example | 6 ++++++ .gitignore | 2 +- composer.json | 3 ++- docker-compose.yml | 24 ------------------------ docker/Dockerfile | 15 --------------- docker/conf/default.conf | 22 ---------------------- docker/php/xdebug.ini | 6 ------ index.php | 7 ++++++- src/Keycloak/KeycloakAuth.php | 6 +++--- 9 files changed, 18 insertions(+), 73 deletions(-) create mode 100644 .env.example delete mode 100755 docker-compose.yml delete mode 100755 docker/Dockerfile delete mode 100755 docker/conf/default.conf delete mode 100755 docker/php/xdebug.ini diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..df2d928 --- /dev/null +++ b/.env.example @@ -0,0 +1,6 @@ +client_id=client +client_secret=secret +keycloak_token_url=https://keycloak.example.com/auth/realms/master/protocol/openid-connect/token +realm=master +users_path=/srv/dav/public +base_uri=/ diff --git a/.gitignore b/.gitignore index 7c94014..f1740f4 100755 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,4 @@ .env vendor public -composer.lock \ No newline at end of file +composer.lock diff --git a/composer.json b/composer.json index 5b63333..e32305a 100755 --- a/composer.json +++ b/composer.json @@ -19,7 +19,8 @@ ], "require": { "sabre/dav": "^4.6", - "ext-curl": "*" + "ext-curl": "*", + "vlucas/phpdotenv": "^5.6" }, "autoload": { "psr-0": { diff --git a/docker-compose.yml b/docker-compose.yml deleted file mode 100755 index 112064f..0000000 --- a/docker-compose.yml +++ /dev/null @@ -1,24 +0,0 @@ -version: '3.7' -services: - web: - image: nginx:alpine - ports: - - "80:80" - volumes: - - ./:/var/www/html - - ./docker/conf/default.conf:/etc/nginx/conf.d/default.conf - php: - build: - context: ./docker - volumes: - - ./:/var/www/html - - ./docker/php/xdebug.ini:/usr/local/etc/php/conf.d/xdebug.ini - mysql: - image: mysql:latest - ports: - - "3306:3306" - environment: - MYSQL_ROOT_PASSWORD: root - MYSQL_DATABASE: webapp - MYSQL_USER: webapp - MYSQL_PASSWORD: root diff --git a/docker/Dockerfile b/docker/Dockerfile deleted file mode 100755 index cbc0ff5..0000000 --- a/docker/Dockerfile +++ /dev/null @@ -1,15 +0,0 @@ -FROM php:8.3-fpm - -ARG WITH_XDEBUG=true - -RUN apt-get update && apt-get install -y \ - libfreetype6-dev \ - libjpeg62-turbo-dev \ - libpng-dev \ - && docker-php-ext-configure gd --with-freetype --with-jpeg \ - && docker-php-ext-install -j$(nproc) gd \ - && docker-php-ext-install mysqli \ - && docker-php-ext-install pdo pdo_mysql; \ - if [ $WITH_XDEBUG = "true" ] ; then \ - pecl install xdebug; \ - fi ; diff --git a/docker/conf/default.conf b/docker/conf/default.conf deleted file mode 100755 index 0735cc6..0000000 --- a/docker/conf/default.conf +++ /dev/null @@ -1,22 +0,0 @@ -server { - listen 80; - index index.php index.html; - server_name localhost; - error_log /var/log/nginx/error.log; - access_log /var/log/nginx/access.log; - root /var/www/html/src; - - location / { - try_files $uri $uri.js /index.php$is_args$args; - } - - location ~ \.php$ { - try_files $uri =404; - fastcgi_split_path_info ^(.+\.php)(/.+)$; - fastcgi_pass php:9000; - fastcgi_index index.php; - include fastcgi_params; - fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; - fastcgi_param PATH_INFO $fastcgi_path_info; - } -} diff --git a/docker/php/xdebug.ini b/docker/php/xdebug.ini deleted file mode 100755 index 8872bb2..0000000 --- a/docker/php/xdebug.ini +++ /dev/null @@ -1,6 +0,0 @@ -[Xdebug] -zend_extension=xdebug.so -xdebug.mode=debug -xdebug.client_port = 9000 -xdebug.client_host = host.docker.internal -xdebug.idekey=PHPSTORM diff --git a/index.php b/index.php index 62a4938..76fd586 100755 --- a/index.php +++ b/index.php @@ -2,10 +2,15 @@ use Collections\HomeCollection; use Sabre\DAV; +use Dotenv\Dotenv; // The autoloader require 'vendor/autoload.php'; +$dotenv = Dotenv::createImmutable(__DIR__); +$dotenv->load(); + + $aclPlugin = new \Sabre\DAVACL\Plugin(); @@ -37,4 +42,4 @@ $server->addPlugin($authPlugin); $server->addPlugin($aclPlugin); // All we need to do now, is to fire up the server -$server->start(); \ No newline at end of file +$server->start(); diff --git a/src/Keycloak/KeycloakAuth.php b/src/Keycloak/KeycloakAuth.php index 34e2870..fbb378a 100644 --- a/src/Keycloak/KeycloakAuth.php +++ b/src/Keycloak/KeycloakAuth.php @@ -12,7 +12,7 @@ class KeycloakAuth extends AbstractBasic private $client_secret; private $keycloakTokenUrl; - public function __construct(AclPlugin $plugin, $client_id, $client_secret, $keycloakTokenUrl) + public function __construct(AclPlugin $plugin, string $client_id, string $client_secret, string $keycloakTokenUrl) { $this->aclPlugin = $plugin; $this->client_id = $client_id; @@ -20,7 +20,7 @@ class KeycloakAuth extends AbstractBasic $this->keycloakTokenUrl = $keycloakTokenUrl; } - protected function validateUserPass($username, $password) + protected function validateUserPass($username, $password) : bool { $curl = curl_init(); @@ -53,4 +53,4 @@ class KeycloakAuth extends AbstractBasic } } -} \ No newline at end of file +}