Autoloader

Doent Class Autoloader


Source

File: classes/Autoloader.php

class Autoloader {

	/**
	 * Autoload function for registration with spl_autoload_register
	 *
	 * Looks recursively through project directory and loads class files based on
	 * filename match.
	 *
	 * @param  string  $className
	 */
	public static function loader( $className ) {

		if ( ! class_exists( $className ) && strpos( $className, "Dozent" ) !== false ) {

			$className = str_replace( array( '\\', '/' ), DIRECTORY_SEPARATOR, $className );
			$className = str_replace( 'Dozent' . DIRECTORY_SEPARATOR, '', $className );
			$filename = $className . '.php';

			$classes_dir = __DIR__;

			if ( strpos( $className, "/" ) !== false ) {
				$classes_dir = dirname( __DIR__ );
			}

			$file_path = $classes_dir . DIRECTORY_SEPARATOR . $filename;

			if ( file_exists( $file_path ) ) {
				include_once $file_path;
			}

		}
	}

}

Methods

  • loader — Autoload function for registration with spl_autoload_register

Changelog

Changelog
Version Description
DozentLMS 1.0.0 Introduced.