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