-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap.php
More file actions
32 lines (24 loc) · 1.05 KB
/
bootstrap.php
File metadata and controls
32 lines (24 loc) · 1.05 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
<?php
require_once $_SERVER['DOCUMENT_ROOT'] . '/vendor/autoload.php';
const APP_DIR = __DIR__;
const VIEW_DIR = DIRECTORY_SEPARATOR . 'view' . DIRECTORY_SEPARATOR;
spl_autoload_register(function ($class) {
// префикс простанства имен
$prefix = 'App';
// базовый каталог для префикса пространства имен
$base_dir = __DIR__ . '/src/';
//использует ли класс префикс пространства имен
$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;
}
});