| 1 |
<?php |
| 2 |
|
| 3 |
spl_autoload_register(function ($class) { |
| 4 |
// namespace prefix |
| 5 |
$prefix = 'Codelight\\GDPR\\'; |
| 6 |
|
| 7 |
// check if this is a class from our project |
| 8 |
$len = strlen($prefix); |
| 9 |
if (strncmp($prefix, $class, $len) !== 0) { |
| 10 |
return; // nope, it isn't |
| 11 |
} |
| 12 |
|
| 13 |
// get the relative class name |
| 14 |
// remove the namespace name |
| 15 |
$className = substr($class, $len); |
| 16 |
|
| 17 |
// base directory of classes |
| 18 |
$baseDir = __DIR__ . '/src/'; |
| 19 |
// relative including |
| 20 |
$file = $baseDir . str_replace('\\', DIRECTORY_SEPARATOR, $className) . '.php'; |
| 21 |
|
| 22 |
// if the file exists, require it |
| 23 |
|
| 24 |
if (file_exists($file)) { |
| 25 |
require_once($file); |
| 26 |
} |
| 27 |
}); |