summaryrefslogtreecommitdiff
path: root/src/Config.php
diff options
context:
space:
mode:
authorpolo <ordipolo@gmx.fr>2023-03-06 12:54:43 +0100
committerpolo <ordipolo@gmx.fr>2023-03-06 12:54:43 +0100
commit1766952a8499919a1275b0214f6ebda8dfc812e2 (patch)
treead5bd20b8c5b29a26d1b63071d18af688a0b0df4 /src/Config.php
parentb9c74de6d12ef40ab4baf67303ab22a10fcd5b32 (diff)
downloadAppliGestionPHP-1766952a8499919a1275b0214f6ebda8dfc812e2.zip
Config.ini renseigner '' = valeur par défaut
Diffstat (limited to 'src/Config.php')
-rw-r--r--src/Config.php63
1 files changed, 35 insertions, 28 deletions
diff --git a/src/Config.php b/src/Config.php
index 1557705..3e2b204 100644
--- a/src/Config.php
+++ b/src/Config.php
@@ -36,6 +36,41 @@ class Config
36 self::$raw_data = parse_ini_file($file_path); 36 self::$raw_data = parse_ini_file($file_path);
37 } 37 }
38 38
39 static public function hydrate()
40 {
41 foreach(self::$raw_data as $field => $value)
42 {
43 if($value != '') // valeur par défaut
44 {
45 if(isset(self::$$field)) // vérification du nom du champ
46 {
47 // vérification du contenu
48 if(self::fieldIsPath($field)) // cas où le champ db_path, latex_path, pdf_path ou pub_path
49 {
50 if(self::checkPath($field, $value))
51 {
52 $value = self::slashAtEndOfPath($value);
53 self::$$field = $value;
54 }
55 }
56 else // tester le reste?
57 {
58 self::$$field = $value;
59 }
60 // else: la valeur par défaut est conservée
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
39 static private function fieldIsPath($field): bool 74 static private function fieldIsPath($field): bool
40 { 75 {
41 if($field === 'db_path' || $field === 'latex_path' || $field === 'pdf_path' || $field === 'pub_path') 76 if($field === 'db_path' || $field === 'latex_path' || $field === 'pdf_path' || $field === 'pub_path')
@@ -82,34 +117,6 @@ class Config
82 } 117 }
83 } 118 }
84 119
85 static public function hydrate()
86 {
87 foreach(self::$raw_data as $field => $value)
88 {
89 if(isset(self::$$field)) // vérification du nom du champ
90 {
91 // vérification du contenu
92 if(self::fieldIsPath($field)) // cas où le champ db_path, latex_path, pdf_path ou pub_path
93 {
94 if(self::checkPath($field, $value))
95 {
96 $value = self::slashAtEndOfPath($value);
97 self::$$field = $value;
98 }
99 }
100 else // tester le reste?
101 {
102 self::$$field = $value;
103 }
104 // else: la valeur par défaut est conservée
105 }
106 else
107 {
108 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";
109 }
110 }
111 }
112
113 // à faire plus tard 120 // à faire plus tard
114 // transformer les chemins pour qu'ils soient relatifs au dossier 'src' où s'exécute le programme 121 // transformer les chemins pour qu'ils soient relatifs au dossier 'src' où s'exécute le programme
115 static private function adjustRelativePath($input) 122 static private function adjustRelativePath($input)