OAuthCommonAutoLoader

PSR-0 Autoloader.

Defined (1)

The class is defined in the following location(s).

/lib/PHPoAuthLib/src/OAuth/Common/AutoLoader.php  
  1. class AutoLoader 
  2. /** 
  3. * @var string The namespace prefix for this instance. 
  4. */ 
  5. protected $namespace = ''; 
  6.  
  7. /** 
  8. * @var string The filesystem prefix to use for this instance 
  9. */ 
  10. protected $path = ''; 
  11.  
  12. /** 
  13. * Build the instance of the autoloader 
  14. * @param string $namespace The prefixed namespace this instance will load 
  15. * @param string $path The filesystem path to the root of the namespace 
  16. */ 
  17. public function __construct($namespace, $path) 
  18. $this->namespace = ltrim($namespace, '\\'); 
  19. $this->path = rtrim($path, '/\\') . DIRECTORY_SEPARATOR; 
  20.  
  21. /** 
  22. * Try to load a class 
  23. * @param string $class The class name to load 
  24. * @return boolean If the loading was successful 
  25. */ 
  26. public function load($class) 
  27. $class = ltrim($class, '\\'); 
  28.  
  29. if (strpos($class, $this->namespace) === 0) { 
  30. $nsparts = explode('\\', $class); 
  31. $class = array_pop($nsparts); 
  32. $nsparts[] = ''; 
  33. $path = $this->path . implode(DIRECTORY_SEPARATOR, $nsparts); 
  34. $path .= str_replace('_', DIRECTORY_SEPARATOR, $class) . '.php'; 
  35.  
  36. if (file_exists($path)) { 
  37. require $path; 
  38.  
  39. return true; 
  40.  
  41. return false; 
  42.  
  43. /** 
  44. * Register the autoloader to PHP 
  45. * @return boolean The status of the registration 
  46. */ 
  47. public function register() 
  48. return spl_autoload_register(array($this, 'load')); 
  49.  
  50. /** 
  51. * Unregister the autoloader to PHP 
  52. * @return boolean The status of the unregistration 
  53. */ 
  54. public function unregister() 
  55. return spl_autoload_unregister(array($this, 'load'));