From f539b7e6f40205e71141e75514fc69612e7fe760 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Laurent=20L=C3=A9cluse?= <laurent.lecluse@unicaen.fr>
Date: Mon, 7 Oct 2024 15:22:01 +0200
Subject: [PATCH] =?UTF-8?q?Assouplissement=20config=20pour=20coh=C3=A9renc?=
 =?UTF-8?q?e=20Doctrine?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 doc/bdd.md                       |  2 +-
 src/Driver/Oracle/Driver.php     | 19 ++++++++++---------
 src/Driver/Postgresql/Driver.php |  2 +-
 3 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/doc/bdd.md b/doc/bdd.md
index a911d17..29df9a7 100644
--- a/doc/bdd.md
+++ b/doc/bdd.md
@@ -32,7 +32,7 @@ $config = [
         'host'     => '*********',  // IP ou nom DNS
         'port'     => 5432,         // port, à adapter
         'dbname'   => '*********',  // Nom de votre base de données
-        'username' => '*********',  // Utilisateur
+        'user'     => '*********',  // Utilisateur : "username" ou "user", les 2 clés fonctionnent
         'password' => '*********',  // Mot de passe
 ];
 
diff --git a/src/Driver/Oracle/Driver.php b/src/Driver/Oracle/Driver.php
index b2fcb0a..8e3f709 100644
--- a/src/Driver/Oracle/Driver.php
+++ b/src/Driver/Oracle/Driver.php
@@ -44,24 +44,25 @@ class Driver implements DriverInterface
     public function connect(): DriverInterface
     {
         $config       = $this->bdd->getConfig();
-        $host         = isset($config['host']) ? $config['host'] : null;
-        $port         = isset($config['port']) ? $config['port'] : null;
-        $dbname       = isset($config['dbname']) ? $config['dbname'] : null;
-        $username     = isset($config['username']) ? $config['username'] : null;
-        $password     = isset($config['password']) ? $config['password'] : null;
-        $characterset = isset($config['characterset']) ? $config['characterset'] : 'AL32UTF8';
+
+        $host = $config['host'] ?? null;
+        $port = $config['port'] ?? null;
+        $dbname = $config['dbname'] ?? null;
+        $username = $config['username'] ?? $config['user']?? null;
+        $password = $config['password'] ?? null;
+        $charset = $config['characterset'] ?? $config['charset'] ?? 'AL32UTF8';
 
         if (!$host) throw new BddException('host non fourni');
         if (!$port) throw new BddException('port non fourni');
         if (!$dbname) throw new BddException('dbname non fourni');
-        if (!$username) throw new BddException('username non fourni');
+        if (!$username) throw new BddException('username ou user non fourni');
         if (!$password) throw new BddException('password non fourni');
-        if (!$characterset) throw new BddException('characterset non fourni');
+        if (!$charset) throw new BddException('characterset ou charset non fourni');
 
         putenv("NLS_LANGUAGE=FRENCH");
 
         $cs              = $host . ':' . $port . '/' . $dbname;
-        $this->connexion = oci_pconnect($username, $password, $cs, $characterset);
+        $this->connexion = oci_pconnect($username, $password, $cs, $charset);
         if (!$this->connexion) {
             $error = oci_error();
             throw $this->sendException($error);
diff --git a/src/Driver/Postgresql/Driver.php b/src/Driver/Postgresql/Driver.php
index 0e84bdc..73497be 100644
--- a/src/Driver/Postgresql/Driver.php
+++ b/src/Driver/Postgresql/Driver.php
@@ -53,7 +53,7 @@ class Driver implements DriverInterface
         $host = $config['host'] ?? null;
         $port = $config['port'] ?? 5342;
         $dbname = $config['dbname'] ?? null;
-        $username = $config['username'] ?? null;
+        $username = $config['username'] ?? $config['user']?? null;
         $password = $config['password'] ?? null;
         $charset = $config['charset'] ?? 'UTF8';
 
-- 
GitLab