-
Notifications
You must be signed in to change notification settings - Fork 1
/
_autoload.php
69 lines (55 loc) · 1.09 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
<?php
/*
Set folder for all includes
*/
define('WSL_ROOT', __DIR__ . '/' );
define('WSL_ASSETS','assets/');
define('WSL_DATA','data/');
/*
Load config definitions
*/
require_once WSL_ROOT . WSL_ASSETS . 'config.php';
/*
Usage example:
// notation: CamelCase
Assets folder:
./assets
/php
ClassName.php
/NameSpace
ClassName.php
/NextGroup
ClassNext.php
#
# 1 with namespaces
use NameSpace/ClassName;
/ inside ClassName.php
namespace NameSpace;
use NameSpace/NextGroup/ClassNext;
/ inside ClassNext.php
namespace NameSpace/NextGroup;
#
# 2 without
/ just call class
#
# then call class
$class = new ClassName();
or for class with no __construct
ClassName::FunctionCall();
*/
spl_autoload_register(function (string $className) {
$assets = WSL_ROOT . WSL_ASSETS . 'php/';
$fileName = [
// # 1 with namespaces
$assets . str_replace('\\', '/', $className . '.php'),
// # 2 without
$assets . $className . '.php'
];
foreach ($fileName as $file) {
if (file_exists($file)) {
require_once $file;
break;
}
}
});
?>