Skip to content

Instantly share code, notes, and snippets.

@starise
Last active August 29, 2015 14:14
Show Gist options
  • Save starise/6a166e9c696eabd7f536 to your computer and use it in GitHub Desktop.
Save starise/6a166e9c696eabd7f536 to your computer and use it in GitHub Desktop.
Wordpress Plugin Autloader
<?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