autoload.php 767 B

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. /**
  3. * Autoload function
  4. *
  5. * @author Jegstudio
  6. * @package zeever
  7. * @since 1.0.0
  8. */
  9. spl_autoload_register(
  10. function( $class ) {
  11. $prefix = 'Zeever';
  12. $base_dir = ZEEVER_DIR . 'inc/class/';
  13. $len = strlen( $prefix );
  14. if ( strncmp( $prefix, $class, $len ) !== 0 ) {
  15. return;
  16. }
  17. $array_path = explode( '\\', substr( $class, $len ) );
  18. $relative_class = array_pop( $array_path );
  19. $class_path = strtolower( implode( '/', $array_path ) );
  20. $class_name = str_replace( '_', '-', 'class-' . $relative_class . '.php' );
  21. $file = rtrim( $base_dir, '/' ) . '/' . $class_path . '/' . strtolower( $class_name );
  22. if ( is_link( $file ) ) {
  23. $file = readlink( $file );
  24. }
  25. if ( is_file( $file ) ) {
  26. require $file;
  27. }
  28. }
  29. );