-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathautoloader.php
More file actions
89 lines (76 loc) · 1.92 KB
/
autoloader.php
File metadata and controls
89 lines (76 loc) · 1.92 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
namespace KVSun\AutoLoader;
use \shgysk8zer0\PHPCrypt\{KeyPair};
use const \KVSun\Consts\{
ERROR_REPORTING,
INCLUDE_PATH,
ERROR_HANDLER,
EXCEPTION_HANDLER,
REQUIRED,
INCLUDED,
PUBLIC_KEY,
PRIVATE_KEY,
PASSWD
};
date_default_timezone_set('America/Los_Angeles');
use function \KVSun\Consts\{defined};
if (array_key_exists('MIN_PHP_VERSION', $_SERVER)) {
if (version_compare(\PHP_VERSION, $_SERVER['MIN_PHP_VERSION'], '<')) {
http_response_code(500);
exit("PHP {$_SERVER['MIN_PHP_VERSION']} or greater is required.");
}
}
require_once __DIR__ . DIRECTORY_SEPARATOR . 'consts.php';
require_once __DIR__ . DIRECTORY_SEPARATOR . 'functions.php';
// ob_start();
error_reporting(defined('ERROR_REPORTING') ? ERROR_REPORTING : 0);
spl_autoload_register('spl_autoload');
if (defined('INCLUDE_PATH')) {
set_path(INCLUDE_PATH);
}
if (defined('ERROR_HANDLER')) {
set_error_handler(ERROR_HANDLER);
}
if (defined('EXCEPTION_HANDLER')) {
set_exception_handler(EXCEPTION_HANDLER);
}
if (defined('REQUIRED') and is_array(REQUIRED)) {
array_map(
function($file)
{
require_once __DIR__ . DIRECTORY_SEPARATOR .$file;
},
REQUIRED
);
}
if (defined('INCLUDE') and is_array(INCLUDED)) {
array_map(
function($file)
{
include_once __DIR__ . DIRECTORY_SEPARATOR .$file;
},
INCLUDED
);
}
if (!@file_exists(PUBLIC_KEY) or !@file_exists(PRIVATE_KEY)) {
$keys = KeyPair::generateKeyPair(PASSWD);
$keys->public->exportToFile(PUBLIC_KEY);
$keys->private->exportToFile(PRIVATE_KEY, PASSWD);
unset($keys);
}
if (session_status() !== PHP_SESSION_ACTIVE) {
session_start([
'name' => $_SERVER['SERVER_NAME'],
'cookie_secure' => true,
'cookie_httponly' => true,
]);
}
function set_path(Array $path, Bool $use_existing = true): String
{
$path = array_map('realpath', $path);
$path = join(\PATH_SEPARATOR, $path);
if ($use_existing === true) {
$path .= \PATH_SEPARATOR . get_include_path();
}
return set_include_path($path);
}