MDL-49746 course: sorting users by last access
[moodle.git] / lib / lessphp / Autoloader.php
blobb6300c02059873f6031001c33ae292f7ff20a6b2
1 <?php
3 /**
4 * Autoloader
6 * @package Less
7 * @subpackage autoload
8 */
9 class Less_Autoloader {
11 /**
12 * Registered flag
14 * @var boolean
16 protected static $registered = false;
18 /**
19 * Library directory
21 * @var string
23 protected static $libDir;
25 /**
26 * Register the autoloader in the spl autoloader
28 * @return void
29 * @throws Exception If there was an error in registration
31 public static function register(){
32 if( self::$registered ){
33 return;
36 self::$libDir = dirname(__FILE__);
38 if(false === spl_autoload_register(array('Less_Autoloader', 'loadClass'))){
39 throw new Exception('Unable to register Less_Autoloader::loadClass as an autoloading method.');
42 self::$registered = true;
45 /**
46 * Unregisters the autoloader
48 * @return void
50 public static function unregister(){
51 spl_autoload_unregister(array('Less_Autoloader', 'loadClass'));
52 self::$registered = false;
55 /**
56 * Loads the class
58 * @param string $className The class to load
60 public static function loadClass($className){
63 // handle only package classes
64 if(strpos($className, 'Less_') !== 0){
65 return;
68 $className = substr($className,5);
69 $fileName = self::$libDir . DIRECTORY_SEPARATOR . str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';
71 if(file_exists($fileName)){
72 require $fileName;
73 return true;
74 }else{
75 throw new Exception('file not loadable '.$fileName);