| 1 |
<?php |
| 2 |
|
| 3 |
spl_autoload_register(function ($class) { |
| 4 |
|
| 5 |
// project-specific namespace prefix |
| 6 |
$prefix = 'ImportWP\\'; |
| 7 |
|
| 8 |
// base directory for the namespace prefix |
| 9 |
$base_dir = __DIR__ . '/'; |
| 10 |
|
| 11 |
// does the class use the namespace prefix? |
| 12 |
$len = strlen($prefix); |
| 13 |
if (strncmp($prefix, $class, $len) !== 0) { |
| 14 |
// no, move to the next registered autoloader |
| 15 |
return; |
| 16 |
} |
| 17 |
|
| 18 |
// get the relative class name |
| 19 |
$relative_class = substr($class, $len); |
| 20 |
|
| 21 |
// replace the namespace prefix with the base directory, replace namespace |
| 22 |
// separators with directory separators in the relative class name, append |
| 23 |
// with .php |
| 24 |
$file = $base_dir . str_replace('\\', '/', $relative_class) . '.php'; |
| 25 |
|
| 26 |
// if the file exists, require it |
| 27 |
if (file_exists($file)) { |
| 28 |
require $file; |
| 29 |
} |
| 30 |
}); |
| 31 |
|