autoloader.php in YayExtra – WooCommerce Extra Product Options trunk, at autoloader.php
| 1 | <?php |
| 2 | /** |
| 3 | * Set up autoload |
| 4 | */ |
| 5 | |
| 6 | namespace YayExtra; |
| 7 | |
| 8 | spl_autoload_register( |
| 9 | function ( $class ) { |
| 10 | $prefix = __NAMESPACE__; |
| 11 | $base_dir = __DIR__ . '/includes'; |
| 12 | |
| 13 | $len = strlen( $prefix ); |
| 14 | if ( strncmp( $prefix, $class, $len ) !== 0 ) { |
| 15 | return; |
| 16 | } |
| 17 | |
| 18 | $relative_class_name = substr( $class, $len ); |
| 19 | |
| 20 | $file = $base_dir . str_replace( '\\', '/', $relative_class_name ) . '.php'; |
| 21 | |
| 22 | if ( file_exists( $file ) ) { |
| 23 | require $file; |
| 24 | } |
| 25 | } |
| 26 | ); |
| 27 |