| 1 |
<?php |
| 2 |
/** |
| 3 |
* Loader for namespace. |
| 4 |
* |
| 5 |
* @since 1.0.0 |
| 6 |
* @package SureTrigger |
| 7 |
*/ |
| 8 |
|
| 9 |
spl_autoload_register( |
| 10 |
function ( $class ) { |
| 11 |
// The namespace prefix. |
| 12 |
$prefix = 'SureTriggers\\'; |
| 13 |
|
| 14 |
// Does the class use the namespace prefix? |
| 15 |
$len = strlen( $prefix ); |
| 16 |
if ( strncmp( $prefix, $class, $len ) !== 0 ) { |
| 17 |
// No, move to the next registered autoloader. |
| 18 |
return; |
| 19 |
} |
| 20 |
|
| 21 |
// Get the relative class name. |
| 22 |
$relative_class = substr( $class, $len ); |
| 23 |
|
| 24 |
// Replace the namespace prefix with the base directory, replace namespace. |
| 25 |
// separators with directory separators in the relative class name, append. |
| 26 |
// with .php. |
| 27 |
$file = __DIR__ . '/src/' . str_replace( '\\', '/', $relative_class ) . '.php'; |
| 28 |
|
| 29 |
// If the file exists, require it. |
| 30 |
if ( file_exists( $file ) ) { |
| 31 |
require $file; |
| 32 |
} |
| 33 |
} |
| 34 |
); |
| 35 |
|
| 36 |
|