Last active
August 29, 2015 14:14
-
-
Save starise/6a166e9c696eabd7f536 to your computer and use it in GitHub Desktop.
Wordpress Plugin Autloader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class vendorAutoloader | |
{ | |
const BASENAME = 'vendor'; | |
const BASESRC = 'src'; | |
/** | |
* Static loader method | |
* @param string $class | |
*/ | |
public static function load( $class ) { | |
if ( self::BASENAME == substr( $class, 0, 6 ) ) { | |
$classPath = str_replace( '\\', DIRECTORY_SEPARATOR, $class ); | |
require_once PT_PATH . self::BASESRC . DIRECTORY_SEPARATOR . $classPath . '.php'; | |
} | |
} | |
} | |
/** | |
* The autoload-stack could be inactive so the function will return false | |
*/ | |
if ( in_array( '__autoload', (array) spl_autoload_functions() ) ) { | |
spl_autoload_register( '__autoload' ); | |
} | |
spl_autoload_register( [ 'vendorAutoloader', 'load' ] ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment