-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathautoload.php
106 lines (86 loc) · 2.81 KB
/
autoload.php
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?php
spl_autoload_register(function ($class) {
$prefix = 'Config\\'; // Namespace prefix for Config classes
$base_dir = __DIR__ . '/config/';
$len = strlen($prefix);
if (strncmp($prefix, $class, $len) !== 0) {
return;
}
$relative_class = substr($class, $len);
$file = $base_dir . str_replace('\\', '/', $relative_class) . '.php';
if (file_exists($file)) {
require $file;
}
});
spl_autoload_register(function ($class) {
$prefix = 'App\\Models\\'; // Namespace prefix for Model classes
$base_dir = __DIR__ . '/app/Models/';
$len = strlen($prefix);
if (strncmp($prefix, $class, $len) !== 0) {
return;
}
$relative_class = substr($class, $len);
$file = $base_dir . str_replace('\\', '/', $relative_class) . '.php';
if (file_exists($file)) {
require $file;
}
});
spl_autoload_register(function ($class) {
$prefix = 'App\\Controllers\\'; // Namespace prefix for Controller classes
$base_dir = __DIR__ . '/app/Controllers/';
$len = strlen($prefix);
if (strncmp($prefix, $class, $len) !== 0) {
return;
}
$relative_class = substr($class, $len);
$file = $base_dir . str_replace('\\', '/', $relative_class) . '.php';
if (file_exists($file)) {
require $file;
}
});
spl_autoload_register(function ($class) {
$prefix = 'Support\\'; // Namespace prefix for Support classes
$base_dir = __DIR__ . '/bin/support/';
$len = strlen($prefix);
if (strncmp($prefix, $class, $len) !== 0) {
return;
}
$relative_class = substr($class, $len);
$file = $base_dir . str_replace('\\', '/', $relative_class) . '.php';
if (file_exists($file)) {
require $file;
}
});
spl_autoload_register(function ($class) {
$prefix = 'Core\\'; // Namespace prefix for Support classes
$base_dir = __DIR__ . '/core/';
$len = strlen($prefix);
if (strncmp($prefix, $class, $len) !== 0) {
return;
}
$relative_class = substr($class, $len);
$file = $base_dir . str_replace('\\', '/', $relative_class) . '.php';
if (file_exists($file)) {
require $file;
}
});
require_once __DIR__ . '/bin/support/helper.php';
require_once __DIR__ . '/bin/support/Prefix.php';
require_once __DIR__ . '/bin/support/Rc.php';
Use Support\Route;
Use Support\Api;
if (php_sapi_name() === 'cli') {
// Script berjalan di CLI, handle CLI commands di sini
echo "Starting cli......";
} else {
// Script berjalan di server web, aman untuk menggunakan $_SERVER['REQUEST_URI']
$uri = isset($_SERVER['REQUEST_URI']) ? trim($_SERVER['REQUEST_URI']) : '/';
$apiPrefix = '/' . basename(__DIR__) . '/api';
// Cek apakah URI mengarah ke API
if (strpos($uri, $apiPrefix) === 0) {
Api::init($prefix . '/api');
} else {
Route::init($prefix);
}
}
?>