Merge pull request #7389 from MrPetovan/bug/7387-local_user-int
[friendica.git/.git] / src / Util / Config / ConfigFileManager.php
1 <?php
2
3 namespace Friendica\Util\Config;
4
5 /**
6  * An abstract class in case of handling with config files
7  */
8 abstract class ConfigFileManager
9 {
10         /**
11          * The Sub directory of the config-files
12          * @var string
13          */
14         const SUBDIRECTORY = 'config';
15
16         /**
17          * The default name of the user defined config file
18          * @var string
19          */
20         const CONFIG_LOCAL    = 'local';
21
22         /**
23          * The default name of the user defined ini file
24          * @var string
25          */
26         const CONFIG_INI      = 'local';
27
28         /**
29          * The default name of the user defined legacy config file
30          * @var string
31          */
32         const CONFIG_HTCONFIG = 'htconfig';
33
34         protected $baseDir;
35         protected $configDir;
36
37         /**
38          * @param string $baseDir The base directory of Friendica
39          */
40         public function __construct($baseDir)
41         {
42                 $this->baseDir = $baseDir;
43                 $this->configDir = $baseDir . DIRECTORY_SEPARATOR . self::SUBDIRECTORY;
44         }
45
46         /**
47          * Gets the full name (including the path) for a *.config.php (default is local.config.php)
48          *
49          * @param string $name The config name (default is empty, which means local.config.php)
50          *
51          * @return string The full name or empty if not found
52          */
53         protected function getConfigFullName($name = '')
54         {
55                 $name = !empty($name) ? $name : self::CONFIG_LOCAL;
56
57                 $fullName = $this->configDir . DIRECTORY_SEPARATOR . $name . '.config.php';
58                 return file_exists($fullName) ? $fullName : '';
59         }
60
61         /**
62          * Gets the full name (including the path) for a *.ini.php (default is local.ini.php)
63          *
64          * @param string $name The config name (default is empty, which means local.ini.php)
65          *
66          * @return string The full name or empty if not found
67          */
68         protected function getIniFullName($name = '')
69         {
70                 $name = !empty($name) ? $name : self::CONFIG_INI;
71
72                 $fullName = $this->configDir . DIRECTORY_SEPARATOR . $name . '.ini.php';
73                 return file_exists($fullName) ? $fullName : '';
74         }
75
76         /**
77          * Gets the full name (including the path) for a .*.php (default is .htconfig.php)
78          *
79          * @param string $name The config name (default is empty, which means .htconfig.php)
80          *
81          * @return string The full name or empty if not found
82          */
83         protected function getHtConfigFullName($name = '')
84         {
85                 $name = !empty($name) ? $name : self::CONFIG_HTCONFIG;
86
87                 $fullName = $this->baseDir  . DIRECTORY_SEPARATOR . '.' . $name . '.php';
88                 return file_exists($fullName) ? $fullName : '';
89         }
90 }