Created
January 31, 2014 18:47
-
-
Save tareq1988/8739970 to your computer and use it in GitHub Desktop.
Autoloader
This file contains hidden or 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 | |
/** | |
* Autoload class files on demand | |
* | |
* `Dokan_Installer` becomes => installer.php | |
* `Dokan_Template_Report` becomes => template-report.php | |
* | |
* @param string $class requested class name | |
*/ | |
function dokan_autoload( $class ) { | |
if ( stripos( $class, 'Dokan_' ) !== false ) { | |
$class_name = str_replace( array('Dokan_', '_'), array('', '-'), $class); | |
$file_path = __DIR__ . '/classes/' . strtolower( $class_name ) . '.php'; | |
if ( file_exists( $file_path ) ) { | |
require_once $file_path; | |
} | |
} | |
} | |
spl_autoload_register( 'dokan_autoload' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment