Authy.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. /**
  3. * Autoloader
  4. *
  5. * PHP version 5
  6. *
  7. * @category Services
  8. * @package Authy
  9. * @author David Cuadrado <[email protected]>
  10. * @license http://creativecommons.org/licenses/MIT/ MIT
  11. * @link http://authy.github.com/pear
  12. */
  13. /**
  14. * Autoloads Authy API files
  15. * Based on https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md
  16. *
  17. * @param string $className class to load
  18. *
  19. * @return boolean true when the file was loaded
  20. */
  21. function Authy_autoloader($className)
  22. {
  23. $className = ltrim($className, '\\');
  24. $baseDir = __DIR__.'/lib/';
  25. $fileName = '';
  26. $namespace = '';
  27. if ($lastNsPos = strripos($className, '\\')) {
  28. $namespace = substr($className, 0, $lastNsPos);
  29. $className = substr($className, $lastNsPos + 1);
  30. $fileName = str_replace('\\', '/', $namespace) . '/';
  31. }
  32. $fileName .= str_replace('_', '/', $className) . '.php';
  33. if (file_exists($baseDir.'/'.$fileName)) {
  34. include $baseDir.'/'.$fileName;
  35. return true;
  36. } else if (file_exists($baseDir.'/vendor/'.$fileName)) {
  37. include $baseDir.'/vendor/'.$fileName;
  38. return true;
  39. } else {
  40. print("File not found for ". $className .": ".$fileName);
  41. }
  42. return false;
  43. }
  44. spl_autoload_register('Authy_autoloader');