aboutsummaryrefslogtreecommitdiff
path: root/src/Config.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/Config.php')
-rw-r--r--src/Config.php86
1 files changed, 0 insertions, 86 deletions
diff --git a/src/Config.php b/src/Config.php
deleted file mode 100644
index 76b34e2..0000000
--- a/src/Config.php
+++ /dev/null
@@ -1,86 +0,0 @@
1<?php
2// src/Config.php
3
4declare(strict_types=1);
5
6class Config
7{
8 // BDD
9 static public string $db_host = 'localhost';
10 static public string $database = '';
11 static public string $db_driver = 'pdo_mysql';
12 static public string $user = '';
13 static public string $password = '';
14 static public string $table_prefix = '';
15
16 // classe URL
17 static public string $protocol = 'http';
18 static public string $index_path = '';
19 static public string $port = '80';
20
21 // e-mails
22 static public string $smtp_host = '';
23 static public string $smtp_username = '';
24 static public string $smtp_password = '';
25 static public string $smtp_secure = ''; // tls (smarttls) ou ssl (smtps) ou plain_text/chaine vide
26 static public string $email_from = 'mon_adresse@email.fr';
27 static public string $email_from_name = 'site web';
28 static public string $email_dest = '';
29 static public string $email_dest_name = 'destinataire formulaire';
30
31 // copier dans ce tableau les variables contenant des chemins
32 static private array $path_vars = [];
33
34 static public function load(string $file_path): void
35 {
36 if(file_exists($file_path))
37 {
38 // ce serait bien de gérer aussi les fichiers corrompus?
39 $raw_data = parse_ini_file($file_path);
40 self::hydrate($raw_data);
41 }
42 else
43 {
44 echo "<p>Le fichier config/config.ini n'existe pas ou n'est pas lisible.</p>";
45 }
46 define('TABLE_PREFIX', self::$table_prefix);
47 }
48
49 // renseigner les variables internes de Config
50 static private function hydrate(array $raw_data): void
51 {
52 foreach($raw_data as $field => $value)
53 {
54 if($value != '') // valeur par défaut
55 {
56 if(isset(self::$$field)) // le champ existe dans Config
57 {
58 // problème du slash à la fin du nom d'un dossier
59 $value = self::slashAtEndOfPath($field, $value);
60 self::$$field = $value;
61 }
62 else
63 {
64 echo "debug: le fichier config.ini comporte une erreur, le champ: " . $field . " est incorrect,\nl'information contenue sur cette ligne ne sera pas utilisée\n";
65 }
66 }
67 /*else
68 {
69 echo "debug: le champ " . $field . " est vide, la valeur par défaut " . self::$$field . " sera utilisée.\n";
70 }*/
71 }
72 }
73
74
75 // pour que les chemins finissent toujours par un /
76 static private function slashAtEndOfPath(string $field, string $value): string
77 {
78 foreach(self::$path_vars as $item)
79 {
80 if($field === $item){
81 return !str_ends_with($value, '/') ? $value . '/' : $value;
82 }
83 }
84 return $value;
85 }
86}