Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
42.67% |
96 / 225 |
|
21.05% |
12 / 57 |
CRAP | |
0.00% |
0 / 1 |
| EnvUtils | |
42.67% |
96 / 225 |
|
21.05% |
12 / 57 |
1021.03 | |
0.00% |
0 / 1 |
| lazyInit | |
90.48% |
19 / 21 |
|
0.00% |
0 / 1 |
5.02 | |||
| setPrivatePath | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setDataPath | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setDataHref | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setCodePath | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setCodeHref | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| configure | |
100.00% |
39 / 39 |
|
100.00% |
1 / 1 |
1 | |||
| getPrivatePath | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getDataPath | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| getDataHref | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| getCodePath | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| getCodeHref | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| getSyslogPath | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| getBaseHref | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| getAppEnv | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| getMysqlHost | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| getMysqlPort | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| getMysqlServer | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| getMysqlUsername | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| getMysqlPassword | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| getMysqlSchema | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| hasUnlimitedCron | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| getDateUtilsClassName | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| getDateUtilsClassArgs | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| getDatabaseBackupKey | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| getEmailReactionKey | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| getIdEncryptionKey | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| getCronAuthenticityCode | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| getStravaClientId | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| getStravaClientSecret | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| getTelegramBotName | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| getTelegramBotToken | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| getTelegramAuthenticityCode | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| getImapHost | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| getImapPort | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| getImapFlags | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| getImapUsername | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| getImapPassword | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| getSmtpHost | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| getSmtpPort | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| getSmtpUsername | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| getSmtpPassword | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| getSmtpSecure | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| getSmtpDebug | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| getSmtpFrom | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| getEmailForwardingHost | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| getAppSearchEnginesUsername | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| getAppSearchEnginesPassword | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| getAppMonitoringUsername | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| getAppMonitoringPassword | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| getAppStatisticsUsername | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| getAppStatisticsPassword | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| checkNotNull | |
50.00% |
1 / 2 |
|
0.00% |
0 / 1 |
2.50 | |||
| computeDataPath | |
30.00% |
3 / 10 |
|
0.00% |
0 / 1 |
13.57 | |||
| computePrivatePath | |
75.00% |
6 / 8 |
|
0.00% |
0 / 1 |
4.25 | |||
| getConfigPath | |
75.00% |
6 / 8 |
|
0.00% |
0 / 1 |
3.14 | |||
| fromEnv | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Olz\Utils; |
| 4 | |
| 5 | class EnvUtils { |
| 6 | private ?string $private_path = null; |
| 7 | private ?string $data_path = null; |
| 8 | private ?string $data_href = null; |
| 9 | private ?string $code_path = null; |
| 10 | private ?string $code_href = null; |
| 11 | |
| 12 | private ?string $syslog_path = null; |
| 13 | private ?string $base_href = null; |
| 14 | private ?string $app_env = null; |
| 15 | |
| 16 | private ?string $mysql_host = null; |
| 17 | private ?string $mysql_port = null; |
| 18 | private ?string $mysql_username = null; |
| 19 | private ?string $mysql_password = null; |
| 20 | private ?string $mysql_schema = null; |
| 21 | |
| 22 | private bool $has_unlimited_cron = false; |
| 23 | |
| 24 | private string $date_utils_class_name = 'LiveDateUtils'; |
| 25 | /** @var array<string, mixed> */ |
| 26 | private array $date_utils_class_args = []; |
| 27 | |
| 28 | private ?string $database_backup_key = null; |
| 29 | private ?string $email_reaction_key = null; |
| 30 | private ?string $id_encryption_key = null; |
| 31 | |
| 32 | private ?string $cron_authenticity_code = null; |
| 33 | |
| 34 | private ?string $strava_client_id = null; |
| 35 | private ?string $strava_client_secret = null; |
| 36 | |
| 37 | private ?string $telegram_bot_name = null; |
| 38 | private ?string $telegram_bot_token = null; |
| 39 | private ?string $telegram_authenticity_code = null; |
| 40 | |
| 41 | private ?string $imap_host = null; |
| 42 | private ?string $imap_port = null; |
| 43 | private ?string $imap_flags = ''; |
| 44 | private ?string $imap_username = null; |
| 45 | private ?string $imap_password = null; |
| 46 | |
| 47 | private ?string $smtp_host = null; |
| 48 | private ?string $smtp_port = null; |
| 49 | private ?string $smtp_username = null; |
| 50 | private ?string $smtp_password = null; |
| 51 | private ?string $smtp_secure = ''; |
| 52 | private int $smtp_debug = 0; |
| 53 | private ?string $smtp_from = null; |
| 54 | |
| 55 | private ?string $email_forwarding_host = null; |
| 56 | |
| 57 | private ?string $app_search_engines_username = null; |
| 58 | private ?string $app_search_engines_password = null; |
| 59 | |
| 60 | private ?string $app_monitoring_username = null; |
| 61 | private ?string $app_monitoring_password = null; |
| 62 | |
| 63 | private ?string $app_statistics_username = null; |
| 64 | private ?string $app_statistics_password = null; |
| 65 | |
| 66 | private bool $lazyInitCompleted = false; |
| 67 | |
| 68 | public function lazyInit(): void { |
| 69 | if ($this->lazyInitCompleted) { |
| 70 | return; |
| 71 | } |
| 72 | global $_SERVER; |
| 73 | |
| 74 | // TODO: Also use the configuration file? |
| 75 | $private_path = self::computePrivatePath(); |
| 76 | $this->setPrivatePath($private_path); |
| 77 | |
| 78 | // TODO: Also use the configuration file? |
| 79 | $data_path = self::computeDataPath(); |
| 80 | $this->setDataPath($data_path); |
| 81 | $this->setDataHref('/'); |
| 82 | |
| 83 | $code_href = '/'; |
| 84 | if (isset($_SERVER['OLZ_SYMFONY_HREF']) && preg_match('/^\/.+\/$/', $_SERVER['OLZ_SYMFONY_HREF'])) { |
| 85 | $code_href = $_SERVER['OLZ_SYMFONY_HREF']; |
| 86 | } |
| 87 | $code_path = realpath(__DIR__.'/../../').'/'; |
| 88 | $this->setCodePath($code_path); |
| 89 | $this->setCodeHref($code_href); |
| 90 | |
| 91 | $config_path = self::getConfigPath(); |
| 92 | if (!is_file($config_path)) { |
| 93 | throw new \Exception("Konfigurationsdatei ({$config_path}) nicht gefunden!"); |
| 94 | } |
| 95 | |
| 96 | $configuration = require $config_path; |
| 97 | $configure_env_utils_function = $configuration['configure_env_utils']; |
| 98 | $configure_env_utils_function($this); |
| 99 | |
| 100 | $this->lazyInitCompleted = true; |
| 101 | } |
| 102 | |
| 103 | public function setPrivatePath(?string $private_path): void { |
| 104 | $this->private_path = $private_path; |
| 105 | } |
| 106 | |
| 107 | public function setDataPath(string $data_path): void { |
| 108 | $this->data_path = $data_path; |
| 109 | } |
| 110 | |
| 111 | public function setDataHref(string $data_href): void { |
| 112 | $this->data_href = $data_href; |
| 113 | } |
| 114 | |
| 115 | public function setCodePath(string $code_path): void { |
| 116 | $this->code_path = $code_path; |
| 117 | } |
| 118 | |
| 119 | public function setCodeHref(string $code_href): void { |
| 120 | $this->code_href = $code_href; |
| 121 | } |
| 122 | |
| 123 | /** @param array<string, mixed> $config_dict */ |
| 124 | public function configure(array $config_dict): void { |
| 125 | $this->syslog_path = $config_dict['syslog_path'] ?? $this->syslog_path; |
| 126 | $this->base_href = $config_dict['base_href'] ?? $this->base_href; |
| 127 | $this->app_env = $config_dict['app_env'] ?? $this->app_env; |
| 128 | |
| 129 | $this->mysql_host = $config_dict['mysql_host'] ?? $this->mysql_host; |
| 130 | $this->mysql_port = $config_dict['mysql_port'] ?? $this->mysql_port; |
| 131 | $this->mysql_username = $config_dict['mysql_username'] ?? $this->mysql_username; |
| 132 | $this->mysql_password = $config_dict['mysql_password'] ?? $this->mysql_password; |
| 133 | $this->mysql_schema = $config_dict['mysql_schema'] ?? $this->mysql_schema; |
| 134 | |
| 135 | $this->has_unlimited_cron = $config_dict['has_unlimited_cron'] ?? $this->has_unlimited_cron; |
| 136 | |
| 137 | $this->date_utils_class_name = $config_dict['date_utils_class_name'] ?? $this->date_utils_class_name; |
| 138 | $this->date_utils_class_args = $config_dict['date_utils_class_args'] ?? $this->date_utils_class_args; |
| 139 | |
| 140 | $this->database_backup_key = $config_dict['database_backup_key'] ?? $this->database_backup_key; |
| 141 | $this->email_reaction_key = $config_dict['email_reaction_key'] ?? $this->email_reaction_key; |
| 142 | $this->id_encryption_key = $config_dict['id_encryption_key'] ?? $this->id_encryption_key; |
| 143 | |
| 144 | $this->cron_authenticity_code = $config_dict['cron_authenticity_code'] ?? $this->cron_authenticity_code; |
| 145 | |
| 146 | $this->strava_client_id = $config_dict['strava_client_id'] ?? $this->strava_client_id; |
| 147 | $this->strava_client_secret = $config_dict['strava_client_secret'] ?? $this->strava_client_secret; |
| 148 | |
| 149 | $this->telegram_bot_name = $config_dict['telegram_bot_name'] ?? $this->telegram_bot_name; |
| 150 | $this->telegram_bot_token = $config_dict['telegram_bot_token'] ?? $this->telegram_bot_token; |
| 151 | $this->telegram_authenticity_code = $config_dict['telegram_authenticity_code'] ?? $this->telegram_authenticity_code; |
| 152 | |
| 153 | $this->imap_host = $config_dict['imap_host'] ?? $this->imap_host; |
| 154 | $this->imap_port = $config_dict['imap_port'] ?? $this->imap_port; |
| 155 | $this->imap_flags = $config_dict['imap_flags'] ?? $this->imap_flags; |
| 156 | $this->imap_username = $config_dict['imap_username'] ?? $this->imap_username; |
| 157 | $this->imap_password = $config_dict['imap_password'] ?? $this->imap_password; |
| 158 | |
| 159 | $this->smtp_host = $config_dict['smtp_host'] ?? $this->smtp_host; |
| 160 | $this->smtp_port = $config_dict['smtp_port'] ?? $this->smtp_port; |
| 161 | $this->smtp_username = $config_dict['smtp_username'] ?? $this->smtp_username; |
| 162 | $this->smtp_password = $config_dict['smtp_password'] ?? $this->smtp_password; |
| 163 | $this->smtp_secure = $config_dict['smtp_secure'] ?? $this->smtp_secure; |
| 164 | $this->smtp_debug = $config_dict['smtp_debug'] ?? $this->smtp_debug; |
| 165 | $this->smtp_from = $config_dict['smtp_from'] ?? $this->smtp_from; |
| 166 | |
| 167 | $this->email_forwarding_host = $config_dict['email_forwarding_host'] ?? $this->email_forwarding_host; |
| 168 | |
| 169 | $this->app_search_engines_username = $config_dict['app_search_engines_username'] ?? $this->app_search_engines_username; |
| 170 | $this->app_search_engines_password = $config_dict['app_search_engines_password'] ?? $this->app_search_engines_password; |
| 171 | |
| 172 | $this->app_monitoring_username = $config_dict['app_monitoring_username'] ?? $this->app_monitoring_username; |
| 173 | $this->app_monitoring_password = $config_dict['app_monitoring_password'] ?? $this->app_monitoring_password; |
| 174 | |
| 175 | $this->app_statistics_username = $config_dict['app_statistics_username'] ?? $this->app_statistics_username; |
| 176 | $this->app_statistics_password = $config_dict['app_statistics_password'] ?? $this->app_statistics_password; |
| 177 | } |
| 178 | |
| 179 | public function getPrivatePath(): ?string { |
| 180 | $this->lazyInit(); |
| 181 | return $this->private_path; |
| 182 | } |
| 183 | |
| 184 | public function getDataPath(): string { |
| 185 | $this->lazyInit(); |
| 186 | $this->checkNotNull($this->data_path, "data_path not set"); |
| 187 | return $this->data_path; |
| 188 | } |
| 189 | |
| 190 | public function getDataHref(): string { |
| 191 | $this->lazyInit(); |
| 192 | $this->checkNotNull($this->data_href, "data_href not set"); |
| 193 | return $this->data_href; |
| 194 | } |
| 195 | |
| 196 | public function getCodePath(): string { |
| 197 | $this->lazyInit(); |
| 198 | $this->checkNotNull($this->code_path, "code_path not set"); |
| 199 | return $this->code_path; |
| 200 | } |
| 201 | |
| 202 | public function getCodeHref(): string { |
| 203 | $this->lazyInit(); |
| 204 | $this->checkNotNull($this->code_href, "code_href not set"); |
| 205 | return $this->code_href; |
| 206 | } |
| 207 | |
| 208 | public function getSyslogPath(): string { |
| 209 | $this->lazyInit(); |
| 210 | $this->checkNotNull($this->syslog_path, "syslog_path not set"); |
| 211 | return $this->syslog_path; |
| 212 | } |
| 213 | |
| 214 | public function getBaseHref(): string { |
| 215 | $this->lazyInit(); |
| 216 | $this->checkNotNull($this->base_href, "base_href not set"); |
| 217 | return $this->base_href; |
| 218 | } |
| 219 | |
| 220 | public function getAppEnv(): string { |
| 221 | $this->lazyInit(); |
| 222 | $this->checkNotNull($this->app_env, "app_env not set"); |
| 223 | return $this->app_env; |
| 224 | } |
| 225 | |
| 226 | public function getMysqlHost(): string { |
| 227 | $this->lazyInit(); |
| 228 | $this->checkNotNull($this->mysql_host, "mysql_host not set"); |
| 229 | return $this->mysql_host; |
| 230 | } |
| 231 | |
| 232 | public function getMysqlPort(): string { |
| 233 | $this->lazyInit(); |
| 234 | $this->checkNotNull($this->mysql_port, "mysql_port not set"); |
| 235 | return $this->mysql_port; |
| 236 | } |
| 237 | |
| 238 | public function getMysqlServer(): string { |
| 239 | $this->lazyInit(); |
| 240 | return "{$this->mysql_host}:{$this->mysql_port}"; |
| 241 | } |
| 242 | |
| 243 | public function getMysqlUsername(): string { |
| 244 | $this->lazyInit(); |
| 245 | $this->checkNotNull($this->mysql_username, "mysql_username not set"); |
| 246 | return $this->mysql_username; |
| 247 | } |
| 248 | |
| 249 | public function getMysqlPassword(): string { |
| 250 | $this->lazyInit(); |
| 251 | $this->checkNotNull($this->mysql_password, "mysql_password not set"); |
| 252 | return $this->mysql_password; |
| 253 | } |
| 254 | |
| 255 | public function getMysqlSchema(): string { |
| 256 | $this->lazyInit(); |
| 257 | $this->checkNotNull($this->mysql_schema, "mysql_schema not set"); |
| 258 | return $this->mysql_schema; |
| 259 | } |
| 260 | |
| 261 | public function hasUnlimitedCron(): bool { |
| 262 | $this->lazyInit(); |
| 263 | return $this->has_unlimited_cron; |
| 264 | } |
| 265 | |
| 266 | public function getDateUtilsClassName(): string { |
| 267 | $this->lazyInit(); |
| 268 | return $this->date_utils_class_name; |
| 269 | } |
| 270 | |
| 271 | /** @return array<mixed> */ |
| 272 | public function getDateUtilsClassArgs(): array { |
| 273 | $this->lazyInit(); |
| 274 | return $this->date_utils_class_args; |
| 275 | } |
| 276 | |
| 277 | public function getDatabaseBackupKey(): string { |
| 278 | $this->lazyInit(); |
| 279 | $this->checkNotNull($this->database_backup_key, "database_backup_key not set"); |
| 280 | return $this->database_backup_key; |
| 281 | } |
| 282 | |
| 283 | public function getEmailReactionKey(): string { |
| 284 | $this->lazyInit(); |
| 285 | $this->checkNotNull($this->email_reaction_key, "email_reaction_key not set"); |
| 286 | return $this->email_reaction_key; |
| 287 | } |
| 288 | |
| 289 | public function getIdEncryptionKey(): string { |
| 290 | $this->lazyInit(); |
| 291 | $this->checkNotNull($this->id_encryption_key, "id_encryption_key not set"); |
| 292 | return $this->id_encryption_key; |
| 293 | } |
| 294 | |
| 295 | public function getCronAuthenticityCode(): string { |
| 296 | $this->lazyInit(); |
| 297 | $this->checkNotNull($this->cron_authenticity_code, "cron_authenticity_code not set"); |
| 298 | return $this->cron_authenticity_code; |
| 299 | } |
| 300 | |
| 301 | public function getStravaClientId(): string { |
| 302 | $this->lazyInit(); |
| 303 | $this->checkNotNull($this->strava_client_id, "strava_client_id not set"); |
| 304 | return $this->strava_client_id; |
| 305 | } |
| 306 | |
| 307 | public function getStravaClientSecret(): string { |
| 308 | $this->lazyInit(); |
| 309 | $this->checkNotNull($this->strava_client_secret, "strava_client_secret not set"); |
| 310 | return $this->strava_client_secret; |
| 311 | } |
| 312 | |
| 313 | public function getTelegramBotName(): string { |
| 314 | $this->lazyInit(); |
| 315 | $this->checkNotNull($this->telegram_bot_name, "telegram_bot_name not set"); |
| 316 | return $this->telegram_bot_name; |
| 317 | } |
| 318 | |
| 319 | public function getTelegramBotToken(): string { |
| 320 | $this->lazyInit(); |
| 321 | $this->checkNotNull($this->telegram_bot_token, "telegram_bot_token not set"); |
| 322 | return $this->telegram_bot_token; |
| 323 | } |
| 324 | |
| 325 | public function getTelegramAuthenticityCode(): string { |
| 326 | $this->lazyInit(); |
| 327 | $this->checkNotNull($this->telegram_authenticity_code, "telegram_authenticity_code not set"); |
| 328 | return $this->telegram_authenticity_code; |
| 329 | } |
| 330 | |
| 331 | public function getImapHost(): string { |
| 332 | $this->lazyInit(); |
| 333 | $this->checkNotNull($this->imap_host, "imap_host not set"); |
| 334 | return $this->imap_host; |
| 335 | } |
| 336 | |
| 337 | public function getImapPort(): string { |
| 338 | $this->lazyInit(); |
| 339 | $this->checkNotNull($this->imap_port, "imap_port not set"); |
| 340 | return $this->imap_port; |
| 341 | } |
| 342 | |
| 343 | public function getImapFlags(): string { |
| 344 | $this->lazyInit(); |
| 345 | $this->checkNotNull($this->imap_flags, "imap_flags not set"); |
| 346 | return $this->imap_flags; |
| 347 | } |
| 348 | |
| 349 | public function getImapUsername(): string { |
| 350 | $this->lazyInit(); |
| 351 | $this->checkNotNull($this->imap_username, "imap_username not set"); |
| 352 | return $this->imap_username; |
| 353 | } |
| 354 | |
| 355 | public function getImapPassword(): string { |
| 356 | $this->lazyInit(); |
| 357 | $this->checkNotNull($this->imap_password, "imap_password not set"); |
| 358 | return $this->imap_password; |
| 359 | } |
| 360 | |
| 361 | public function getSmtpHost(): string { |
| 362 | $this->lazyInit(); |
| 363 | $this->checkNotNull($this->smtp_host, "smtp_host not set"); |
| 364 | return $this->smtp_host; |
| 365 | } |
| 366 | |
| 367 | public function getSmtpPort(): string { |
| 368 | $this->lazyInit(); |
| 369 | $this->checkNotNull($this->smtp_port, "smtp_port not set"); |
| 370 | return $this->smtp_port; |
| 371 | } |
| 372 | |
| 373 | public function getSmtpUsername(): string { |
| 374 | $this->lazyInit(); |
| 375 | $this->checkNotNull($this->smtp_username, "smtp_username not set"); |
| 376 | return $this->smtp_username; |
| 377 | } |
| 378 | |
| 379 | public function getSmtpPassword(): string { |
| 380 | $this->lazyInit(); |
| 381 | $this->checkNotNull($this->smtp_password, "smtp_password not set"); |
| 382 | return $this->smtp_password; |
| 383 | } |
| 384 | |
| 385 | public function getSmtpSecure(): string { |
| 386 | $this->lazyInit(); |
| 387 | $this->checkNotNull($this->smtp_secure, "smtp_secure not set"); |
| 388 | return $this->smtp_secure; |
| 389 | } |
| 390 | |
| 391 | public function getSmtpDebug(): int { |
| 392 | $this->lazyInit(); |
| 393 | return $this->smtp_debug; |
| 394 | } |
| 395 | |
| 396 | public function getSmtpFrom(): string { |
| 397 | $this->lazyInit(); |
| 398 | $this->checkNotNull($this->smtp_from, "smtp_from not set"); |
| 399 | return $this->smtp_from; |
| 400 | } |
| 401 | |
| 402 | public function getEmailForwardingHost(): string { |
| 403 | $this->lazyInit(); |
| 404 | $this->checkNotNull($this->email_forwarding_host, "email_forwarding_host not set"); |
| 405 | return $this->email_forwarding_host; |
| 406 | } |
| 407 | |
| 408 | public function getAppSearchEnginesUsername(): string { |
| 409 | $this->lazyInit(); |
| 410 | $this->checkNotNull($this->app_search_engines_username, "app_search_engines_username not set"); |
| 411 | return $this->app_search_engines_username; |
| 412 | } |
| 413 | |
| 414 | public function getAppSearchEnginesPassword(): string { |
| 415 | $this->lazyInit(); |
| 416 | $this->checkNotNull($this->app_search_engines_password, "app_search_engines_password not set"); |
| 417 | return $this->app_search_engines_password; |
| 418 | } |
| 419 | |
| 420 | public function getAppMonitoringUsername(): string { |
| 421 | $this->lazyInit(); |
| 422 | $this->checkNotNull($this->app_monitoring_username, "app_monitoring_username not set"); |
| 423 | return $this->app_monitoring_username; |
| 424 | } |
| 425 | |
| 426 | public function getAppMonitoringPassword(): string { |
| 427 | $this->lazyInit(); |
| 428 | $this->checkNotNull($this->app_monitoring_password, "app_monitoring_password not set"); |
| 429 | return $this->app_monitoring_password; |
| 430 | } |
| 431 | |
| 432 | public function getAppStatisticsUsername(): string { |
| 433 | $this->lazyInit(); |
| 434 | $this->checkNotNull($this->app_statistics_username, "app_statistics_username not set"); |
| 435 | return $this->app_statistics_username; |
| 436 | } |
| 437 | |
| 438 | public function getAppStatisticsPassword(): string { |
| 439 | $this->lazyInit(); |
| 440 | $this->checkNotNull($this->app_statistics_password, "app_statistics_password not set"); |
| 441 | return $this->app_statistics_password; |
| 442 | } |
| 443 | |
| 444 | /** @phpstan-assert !null $value */ |
| 445 | protected function checkNotNull(mixed $value, string $error_message): void { |
| 446 | if ($value === null) { |
| 447 | throw new \Exception($error_message); |
| 448 | } |
| 449 | } |
| 450 | |
| 451 | public static function computeDataPath(): string { |
| 452 | $document_root = $_SERVER['DOCUMENT_ROOT'] ?? ''; |
| 453 | if ($document_root) { |
| 454 | return "{$document_root}/"; |
| 455 | } |
| 456 | $injected_path = __DIR__.'/data/DATA_PATH'; |
| 457 | if (is_file($injected_path)) { |
| 458 | $injected_data_path = file_get_contents($injected_path); |
| 459 | if ($injected_data_path && is_dir($injected_data_path)) { |
| 460 | return "{$injected_data_path}/"; |
| 461 | } |
| 462 | } |
| 463 | $local_root = realpath(__DIR__.'/../../public'); |
| 464 | return "{$local_root}/"; |
| 465 | } |
| 466 | |
| 467 | public static function computePrivatePath(): ?string { |
| 468 | global $_SERVER; |
| 469 | |
| 470 | $server_name = $_SERVER['SERVER_NAME'] ?? 'localhost'; |
| 471 | if ($server_name === '127.0.0.1' || $server_name === 'localhost') { |
| 472 | $local_private = __DIR__.'/../../private'; |
| 473 | if (!is_dir($local_private)) { |
| 474 | mkdir($local_private, 0o777, true); |
| 475 | } |
| 476 | return realpath($local_private).'/'; |
| 477 | } |
| 478 | return realpath(__DIR__.'/../../../../').'/'; |
| 479 | } |
| 480 | |
| 481 | public static function getConfigPath(): string { |
| 482 | global $_ENV; |
| 483 | $env = $_ENV['APP_ENV'] ?? getenv('APP_ENV'); |
| 484 | if ($env) { |
| 485 | $injected_env_path = dirname(__DIR__, 2)."/config/olz.{$env}.php"; |
| 486 | if (is_file($injected_env_path)) { |
| 487 | return $injected_env_path; |
| 488 | } |
| 489 | } |
| 490 | $injected_path = dirname(__DIR__, 2).'/config/olz.php'; |
| 491 | return $injected_path; |
| 492 | } |
| 493 | |
| 494 | public static function fromEnv(): self { |
| 495 | $instance = new self(); |
| 496 | $instance->lazyInit(); |
| 497 | return $instance; |
| 498 | } |
| 499 | } |