-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathautoloader.php
More file actions
31 lines (25 loc) · 963 Bytes
/
Copy pathautoloader.php
File metadata and controls
31 lines (25 loc) · 963 Bytes
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
<?php
require_once('config.php');
function loadClass($className)
{
$fileName = '';
$namespace = '';
// Sets the include path as the "src" directory
$includePath = __DIR__ . DIRECTORY_SEPARATOR . 'src';
if(false !== strripos($className, '\\')){
$className = str_replace('\\API','',$className);
$lastNsPos = strripos($className, '\\');
$namespace = substr($className, 0, $lastNsPos);
$className = substr($className, $lastNsPos + 1);
$fileName = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR;
}
$fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';
$fullFileName = $includePath . DIRECTORY_SEPARATOR . $fileName;
if(file_exists($fullFileName)){
require $fullFileName;
}
else{
die('Class "' . $className . ':' . $fileName.'" does not exist.');
}
}
spl_autoload_register('loadClass'); // Registers the autoloader