9 class Less_Autoloader
{
16 protected static $registered = false;
23 protected static $libDir;
26 * Register the autoloader in the spl autoloader
29 * @throws Exception If there was an error in registration
31 public static function register(){
32 if( self
::$registered ){
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;
46 * Unregisters the autoloader
50 public static function unregister(){
51 spl_autoload_unregister(array('Less_Autoloader', 'loadClass'));
52 self
::$registered = false;
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){
68 $className = substr($className,5);
69 $fileName = self
::$libDir . DIRECTORY_SEPARATOR
. str_replace('_', DIRECTORY_SEPARATOR
, $className) . '.php';
71 if(file_exists($fileName)){
75 throw new Exception('file not loadable '.$fileName);