-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap.php
More file actions
55 lines (49 loc) · 1.53 KB
/
Copy pathbootstrap.php
File metadata and controls
55 lines (49 loc) · 1.53 KB
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
<?php
declare(strict_types=1);
use PenguLab\AddonManager;
use PenguLab\Auth;
use PenguLab\Database;
use PenguLab\IntegrationManager;
use PenguLab\Secrets;
if (session_status() !== PHP_SESSION_ACTIVE) {
ini_set('session.use_strict_mode', '1');
session_name('pengulab');
session_set_cookie_params([
'httponly' => true,
'samesite' => 'Lax',
'secure' => (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off'),
]);
session_start();
}
spl_autoload_register(static function (string $class): void {
$prefix = 'PenguLab\\';
if (!str_starts_with($class, $prefix)) {
return;
}
$relative = substr($class, strlen($prefix));
$file = __DIR__ . '/src/' . str_replace('\\', '/', $relative) . '.php';
if (is_file($file)) {
require_once $file;
}
});
if (!isset($_SESSION['pengulab_csrf'])) {
$_SESSION['pengulab_csrf'] = bin2hex(random_bytes(24));
}
$dataDir = getenv('PENGULAB_DATA_DIR') ?: (__DIR__ . '/data');
$db = new Database($dataDir, __DIR__);
$secrets = new Secrets($dataDir);
$addons = new AddonManager($db, __DIR__ . '/addons', $dataDir . '/addons');
$integrations = new IntegrationManager($db, $addons, $secrets);
$auth = new Auth($db);
$version = trim((string)@file_get_contents(__DIR__ . '/VERSION')) ?: 'dev';
return [
'version' => $version,
'db' => $db,
'secrets' => $secrets,
'addons' => $addons,
'integrations' => $integrations,
'auth' => $auth,
'csrf' => $_SESSION['pengulab_csrf'],
'root' => __DIR__,
'dataDir' => $dataDir,
];