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