-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap.php
More file actions
41 lines (37 loc) · 1.65 KB
/
Copy pathbootstrap.php
File metadata and controls
41 lines (37 loc) · 1.65 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
<?php
declare(strict_types=1);
define('AGENT_ROOT', __DIR__);
spl_autoload_register(static function (string $class): void {
$prefix = 'TinyAgent\\';
if (!str_starts_with($class, $prefix)) {
return;
}
$path = AGENT_ROOT . '/src/' . str_replace('\\', '/', substr($class, strlen($prefix))) . '.php';
if (is_file($path)) {
require $path;
}
});
TinyAgent\Config::loadEnv(AGENT_ROOT . '/.env');
date_default_timezone_set('UTC');
if (PHP_SAPI !== 'cli' && session_status() === PHP_SESSION_NONE) {
$sessionDirectory = AGENT_ROOT . '/storage/sessions';
if (!is_dir($sessionDirectory) && !mkdir($sessionDirectory, 0770, true) && !is_dir($sessionDirectory)) {
throw new RuntimeException('Session storage is unavailable.');
}
ini_set('session.save_path', $sessionDirectory);
ini_set('session.use_strict_mode', '1');
ini_set('session.gc_maxlifetime', (string) TinyAgent\Config::int('SESSION_LIFETIME', 3600));
$secureCookie = TinyAgent\Config::bool('SESSION_COOKIE_SECURE', TinyAgent\Config::env('APP_ENV', 'production') === 'production');
$cookiePath = (string) TinyAgent\Config::env('SESSION_COOKIE_PATH', '/');
if (!str_starts_with($cookiePath, '/') || preg_match('/[\x00-\x20\x7f]/', $cookiePath)) { $cookiePath = '/'; }
// Increment this namespace when credentials are rotated to invalidate all prior browser sessions.
session_name('tiny_agent_admin_v3');
session_set_cookie_params([
'lifetime' => 0,
'path' => $cookiePath,
'httponly' => true,
'secure' => $secureCookie || TinyAgent\Http::isHttps(),
'samesite' => 'Strict',
]);
session_start();
}