[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/lib/lessphp/ -> Autoloader.php (source)

   1  <?php
   2  
   3  /**
   4   * Autoloader
   5   *
   6   * @package Less
   7   * @subpackage autoload
   8   */
   9  class Less_Autoloader {
  10  
  11      /**
  12       * Registered flag
  13       *
  14       * @var boolean
  15       */
  16      protected static $registered = false;
  17  
  18      /**
  19       * Library directory
  20       *
  21       * @var string
  22       */
  23      protected static $libDir;
  24  
  25      /**
  26       * Register the autoloader in the spl autoloader
  27       *
  28       * @return void
  29       * @throws Exception If there was an error in registration
  30       */
  31  	public static function register(){
  32          if( self::$registered ){
  33              return;
  34          }
  35  
  36          self::$libDir = dirname(__FILE__);
  37  
  38          if(false === spl_autoload_register(array('Less_Autoloader', 'loadClass'))){
  39              throw new Exception('Unable to register Less_Autoloader::loadClass as an autoloading method.');
  40          }
  41  
  42          self::$registered = true;
  43      }
  44  
  45      /**
  46       * Unregisters the autoloader
  47       *
  48       * @return void
  49       */
  50  	public static function unregister(){
  51          spl_autoload_unregister(array('Less_Autoloader', 'loadClass'));
  52          self::$registered = false;
  53      }
  54  
  55      /**
  56       * Loads the class
  57       *
  58       * @param string $className The class to load
  59       */
  60  	public static function loadClass($className){
  61  
  62  
  63          // handle only package classes
  64          if(strpos($className, 'Less_') !== 0){
  65              return;
  66          }
  67  
  68          $className = substr($className,5);
  69          $fileName = self::$libDir . DIRECTORY_SEPARATOR . str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';
  70  
  71          if(file_exists($fileName)){
  72              require $fileName;
  73              return true;
  74          }else{
  75              throw new Exception('file not loadable '.$fileName);
  76          }
  77      }
  78  
  79  }


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1