Passed
Pull Request — master (#222)
by
unknown
01:48
created

EnvLoader::loadEnvironmentVariables()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 18
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 18
rs 9.8333
cc 3
nc 3
nop 0
1
<?php
2
3
/*
4
 * BigBlueButton open source conferencing system - https://www.bigbluebutton.org/.
5
 *
6
 * Copyright (c) 2016-2024 BigBlueButton Inc. and by respective authors (see below).
7
 *
8
 * This program is free software; you can redistribute it and/or modify it under the
9
 * terms of the GNU Lesser General Public License as published by the Free Software
10
 * Foundation; either version 3.0 of the License, or (at your option) any later
11
 * version.
12
 *
13
 * BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
14
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
15
 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Lesser General Public License along
18
 * with BigBlueButton; if not, see <https://www.gnu.org/licenses/>.
19
 */
20
21
namespace BigBlueButton\Util;
22
23
use Dotenv\Dotenv;
24
25
/**
26
 * @see https://github.com/vlucas/phpdotenv
27
 */
28
class EnvLoader
29
{
30
    public static function loadEnvironmentVariables(): void
31
    {
32
        $envPath      = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR;
33
        $envFileMain  = '.env';
34
        $envFileLocal = '.env.local';
35
36
        if (file_exists($envPath . $envFileLocal)) {
37
            $envFile = $envFileLocal;
38
        } elseif (file_exists($envPath . $envFileMain)) {
39
            $envFile = $envFileMain;
40
        } else {
41
            $envPath = realpath($envPath);
42
            throw new \RuntimeException("Environment file ('{$envFileMain}' nor '{$envFileLocal}') not found in directory '{$envPath}'!");
43
        }
44
45
        $dotenv = Dotenv::createUnsafeImmutable($envPath, $envFile);
46
        $dotenv->load();
47
        $dotenv->required(['BBB_SECRET', 'BBB_SERVER_BASE_URL']);
48
    }
49
}
50