summaryrefslogtreecommitdiff
path: root/src/Config.php
blob: 5de966f31e8415100cfa071658a641976c33d4ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php
// src/Config.php

class Config
{
    // valeurs par défaut au cas où
    static public string $business_name = 'ORDIPOLO';
    static public string $business_guy = 'Paul Jusot';
    static public string $business_address = "2A rue de l'île de Man";
    static public string $business_postcode = '29000';
    static public string $business_city = 'Quimper';
    static public string $db_name = "ordipolo";
    static public string $db_path = 'data/';
    static public string $latex_path = 'data/latex/';
    static public string $pdf_path = 'data/pdf/';
    static public string $pub_path = "pub/";
    static public string $flyer = "flyer.xcf";
    static public string $business_card = "carte.sla";
    static public string $image_editor = 'gimp';
    static public string $publishing = 'scribus';
    static public string $sgbd = 'sqlite';
    static public string $sqlite_gui = 'sqlitebrowser'; // ne pas utiliser si le sgbd n'est pas sqlite
    static public string $date_format = 'euro';
    
    // ça pourrait être bien de founir sqlite avec l'application pour supprimer une dépendance
    //~ static public $sqliteBin = 'lib/sqlite_linux';
    //~ static public $sqliteBin = 'lib/sqlite_win.exe';
    
    static private $raw_data;
    
    static public function readFile($file_path)
    {
        self::$raw_data = parse_ini_file($file_path);
    }
    
    static public function hydrate()
    {
        foreach(self::$raw_data as $field => $value)
        {
            if($value != '') // valeur par défaut
            {
                if(isset(self::$$field)) // vérification du nom du champ
                {
                    // problème du slash à la fin du nom d'un dossier
                    if(self::fieldIsPath($field)) // pour db_path, latex_path, pdf_path et pub_path
                    {
                        self::$$field = self::slashAtEndOfPath($value);
                    }
                    else // tester le reste?
                    {
                        self::$$field = $value;
                    }
                    // else: la valeur par défaut est conservée
                }
                else
                {
                    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";
                }
            }
            else
            {
                echo "debug: le champ " . $field . " est vide, la valeur par défaut " . self::$$field . " sera utilisée.\n";
            }
        }
    }
    
    static private function fieldIsPath($field): bool
    {
        if($field === 'db_path' || $field === 'latex_path' || $field === 'pdf_path' || $field === 'pub_path')
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    
    static public function slashAtEndOfPath($path): string
    {
        if(!str_ends_with($path, '/'))
        {
            return($path . '/');
        }
        else
        {
            return $path;
        }
    }
    
    
    // à faire plus tard
    // transformer les chemins pour qu'ils soient relatifs au dossier 'src' où s'exécute le programme
    static private function adjustRelativePath($input)
    {
        // chemin windows?
        
        // chemin relatif ou absolu (par le 1er caractère)
        
        // obtenir l'emplacement du dossier de l'utilisateur '~'
        $userHomePlace = exec('');
        
        // obtenir l'emplacement du dossier 'src'
        $appExecPlace = getcwd();
    }
    
    //~ static public function makeDsn()
    //~ {
        //~ if($this->sgbd === 'sqlite')
        //~ {
            //~ $this->dsn = 'sqlite:' . $this->db_name . '.sqlite';
        //~ }
    //~ }
}