aboutsummaryrefslogtreecommitdiff
path: root/src/service/Config.php
diff options
context:
space:
mode:
authorpolo <ordipolo@gmx.fr>2026-10-23 00:47:32 +0200
committerpolo <ordipolo@gmx.fr>2026-10-23 00:47:32 +0200
commitf27cca08ff786ceff1870147f6d6bad14d71117f (patch)
treed36597a72025313d6faf4ed228755fa267ebe2f6 /src/service/Config.php
parentc7309f900ef05bd5cb313110ec159b761af394ec (diff)
downloadcms-f27cca08ff786ceff1870147f6d6bad14d71117f.tar.gz
cms-f27cca08ff786ceff1870147f6d6bad14d71117f.tar.bz2
cms-f27cca08ff786ceff1870147f6d6bad14d71117f.zip
dossiers avec majuscule, namespace pour toutes les classes, autoload psr-4, UserDataService::createZip déplacé dans Backup
Diffstat (limited to 'src/service/Config.php')
-rw-r--r--src/service/Config.php88
1 files changed, 0 insertions, 88 deletions
diff --git a/src/service/Config.php b/src/service/Config.php
deleted file mode 100644
index 7077e01..0000000
--- a/src/service/Config.php
+++ /dev/null
@@ -1,88 +0,0 @@
1<?php
2// src/service/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 // envoi 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
27 // destination e-mails
28 static public string $email_from = ''; // correspondant affiché dans la boite de réception
29 static public string $email_from_name = 'site web';
30 static public string $email_dest = ''; // destinataire affiché dans la boite de réception
31 static public string $email_dest_name = 'moi';
32
33 // copier dans ce tableau les variables contenant des chemins
34 static private array $path_vars = [];
35
36 static public function load(string $file_path): void
37 {
38 if(file_exists($file_path))
39 {
40 // ce serait bien de gérer aussi les fichiers corrompus?
41 $raw_data = parse_ini_file($file_path);
42 self::hydrate($raw_data);
43 }
44 else
45 {
46 echo "<p>Le fichier config/config.ini n'existe pas ou n'est pas lisible.</p>";
47 }
48 define('TABLE_PREFIX', self::$table_prefix);
49 }
50
51 // renseigner les variables internes de Config
52 static private function hydrate(array $raw_data): void
53 {
54 foreach($raw_data as $field => $value)
55 {
56 if($value != '') // valeur par défaut
57 {
58 if(isset(self::$$field)) // le champ existe dans Config
59 {
60 // problème du slash à la fin du nom d'un dossier
61 $value = self::slashAtEndOfPath($field, $value);
62 self::$$field = $value;
63 }
64 else
65 {
66 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";
67 }
68 }
69 /*else
70 {
71 echo "debug: le champ " . $field . " est vide, la valeur par défaut " . self::$$field . " sera utilisée.\n";
72 }*/
73 }
74 }
75
76
77 // pour que les chemins finissent toujours par un /
78 static private function slashAtEndOfPath(string $field, string $value): string
79 {
80 foreach(self::$path_vars as $item)
81 {
82 if($field === $item){
83 return !str_ends_with($value, '/') ? $value . '/' : $value;
84 }
85 }
86 return $value;
87 }
88}