forked from Shadowss/TravianZ
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathautoloader.php
More file actions
23 lines (20 loc) · 763 Bytes
/
Copy pathautoloader.php
File metadata and controls
23 lines (20 loc) · 763 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?php
function autoloadClass($class) {
// strip the App classname's namespace
$clazz = str_replace(['App\\', '\\'], ['', '/'], $class);
// search for class
$class_found = false;
// go max 5 levels up - we don't have folders that go deeper than that
for ($i = 0; $i < 5; $i++) {
$autoprefix = str_repeat('../', $i);
if (file_exists($autoprefix.'src/' . $clazz . '.php')) {
$class_found = true;
include_once $autoprefix.'src/' . $clazz . '.php';
break;
}
}
if (!$class_found) {
throw new Exception('Unable to find class ' . $clazz . '.');
}
}
spl_autoload_register('autoloadClass');