-
Notifications
You must be signed in to change notification settings - Fork 60
/
Copy pathautoload.inc.php
64 lines (63 loc) · 2.25 KB
/
autoload.inc.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
<?php
spl_autoload_register(function ($className) {
// Autoload services
if (preg_match('/^YesWiki\\\\([^\\\\]+)(?:\\\\([^\\\\]+))?(?:\\\\([^\\\\]+))?$/', $className, $matches)) {
if (empty($matches[2])) {
// not currently managed
} elseif (empty($matches[3])) {
switch ($matches[1]) {
case 'Core':
if (file_exists('includes/' . $matches[2] . '.php')) {
require 'includes/' . $matches[2] . '.php';
}
break;
default:
// actions or handlers, directly managed by Performer
break;
}
} else {
// basePath
switch ($matches[1]) {
case 'Core':
$basePath = 'includes';
break;
case 'Custom':
$basePath = 'custom';
break;
default:
$extension = strtolower($matches[1]);
$basePath = "tools/$extension";
break;
}
// Autoload services
switch ($matches[2]) {
case 'Service':
require "$basePath/services/{$matches[3]}.php";
break;
case 'Controller':
require "$basePath/controllers/{$matches[3]}.php";
break;
case 'Field':
if ($matches[1] != 'Core') {
require "$basePath/fields/{$matches[3]}.php";
}
break;
case 'Commands':
require "$basePath/commands/{$matches[3]}.php";
break;
case 'Entity':
require "$basePath/entities/{$matches[3]}.php";
break;
case 'Exception':
require "$basePath/exceptions/{$matches[3]}.php";
break;
case 'Trait':
require "$basePath/traits/{$matches[3]}.php";
break;
default:
// do nothing
break;
}
}
}
});