1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
<?php
final class Papi_Core_Autoload {
public function __construct() {
spl_autoload_register( [$this, 'autoload'] );
}
public function autoload( $class ) {
$class = strtolower( $class );
$file = 'class-' . str_replace( '_', '-', strtolower( $class ) ) . '.php';
$path = PAPI_PLUGIN_DIR;
if ( strpos( $class, 'papi_admin' ) === 0 ) {
$path .= 'admin/';
} else if ( strpos( $class, 'papi_conditional_' ) === 0 ) {
$path .= 'conditional/';
} else if ( strpos( $class, 'papi_core_' ) === 0 ) {
$path .= 'core/';
} else if ( strpos( $class, 'papi_cli_' ) === 0 ) {
$path .= 'cli/';
} else if ( preg_match( '/^papi\_\w+\_store$/', $class ) ) {
$path .= 'stores/';
} else if ( strpos( $class, 'papi_porter' ) === 0 ) {
$path .= 'porter/';
} else if ( strpos( $class, 'papi_property' ) === 0 ) {
$path .= 'properties/';
} else if ( preg_match( '/^papi\_\w+\_type/', $class ) ) {
$path .= 'types/';
}
if ( is_readable( $path . $file ) ) {
require_once $path . $file;
}
}
}
new Papi_Core_Autoload();