-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloader.php
More file actions
37 lines (36 loc) · 1.3 KB
/
loader.php
File metadata and controls
37 lines (36 loc) · 1.3 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
<?php
spl_autoload_register(function ($class) {
if (substr($class, 0, 9) !== 'Famework\\') {
/* If the class does not lie under the "Famework" namespace,
* then we can exit immediately.
*/
return;
}
/* All of the classes have names like "Famework\Foo", so we need
* to replace the backslashes with frontslashes if we want the
* name to map directly to a location in the filesystem.
*/
/* But before, we have to remove the "Famework\" part,
* because this autoloader is placed in the Famework folder.
*/
$class = str_replace('Famework\\', '', $class);
$class = str_replace('\\', '/', $class);
// Check under the current directory.
$path = dirname(__FILE__) . '/' . $class . '.php';
if (is_readable($path)) {
require $path;
return;
}
/* Now, we have to search the class in the Mod_* folders.
* For that, we need the folder and the class:
* {User}/{Folder}/{Class} --> part 2 and 3
*/
$parts = explode('/', $class);
if (count($parts) >= 2) {
$modpath = dirname(__FILE__) . '/Mods/' . $parts[0] . '_' . $parts[1] . str_replace($parts[0] . '/' . $parts [1], '', $class) . '.php';
if (is_readable($modpath)) {
require $modpath;
return;
}
}
});