Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Autoloader
- {
- public function __construct()
- {
- spl_autoload_register( array( $this, 'autoload' ) );
- }
- public function autoload( $class )
- {
- $iterator = new RecursiveDirectoryIterator( LIBRARY_PATH );
- foreach( new RecursiveIteratorIterator( $iterator ) as $file=>$meta ) {
- if( ( $class . '.php' ) === $meta->getFileName() ) {
- if( file_exists( $file ) ) {
- require_once $file;
- }
- break;
- }
- }
- unset( $iterator, $file );
- }
- }
- class SimpleClassLoader
- {
- /**
- * Installs this class loader on the SPL autoload stack.
- */
- public function register()
- {
- spl_autoload_register(array($this, 'loadClass'));
- }
- /**
- * Uninstalls this class loader from the SPL autoloader stack.
- */
- public function unregister()
- {
- spl_autoload_unregister(array($this, 'loadClass'));
- }
- /**
- * Loads the given class or interface.
- *
- * @param string $className The name of the class to load.
- * @return void
- */
- public function loadClass($className)
- {
- require str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';
- }
- }
- $loader = new SimpleClassLoader();
- $loader->register();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement