autoload.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. if (!is_callable('sodiumCompatAutoloader')) {
  3. /**
  4. * Sodium_Compat autoloader.
  5. *
  6. * @param string $class Class name to be autoloaded.
  7. *
  8. * @return bool Stop autoloading?
  9. */
  10. function sodiumCompatAutoloader($class)
  11. {
  12. $namespace = 'ParagonIE_Sodium_';
  13. // Does the class use the namespace prefix?
  14. $len = strlen($namespace);
  15. if (strncmp($namespace, $class, $len) !== 0) {
  16. // no, move to the next registered autoloader
  17. return false;
  18. }
  19. // Get the relative class name
  20. $relative_class = substr($class, $len);
  21. // Replace the namespace prefix with the base directory, replace namespace
  22. // separators with directory separators in the relative class name, append
  23. // with .php
  24. $file = dirname(__FILE__) . '/src/' . str_replace('_', '/', $relative_class) . '.php';
  25. // if the file exists, require it
  26. if (file_exists($file)) {
  27. require_once $file;
  28. return true;
  29. }
  30. return false;
  31. }
  32. // Now that we have an autoloader, let's register it!
  33. spl_autoload_register('sodiumCompatAutoloader');
  34. }
  35. require_once dirname(__FILE__) . '/src/SodiumException.php';
  36. if (PHP_VERSION_ID >= 50300) {
  37. // Namespaces didn't exist before 5.3.0, so don't even try to use this
  38. // unless PHP >= 5.3.0
  39. require_once dirname(__FILE__) . '/lib/namespaced.php';
  40. require_once dirname(__FILE__) . '/lib/sodium_compat.php';
  41. }
  42. if (PHP_VERSION_ID < 70200 || !extension_loaded('sodium')) {
  43. require_once dirname(__FILE__) . '/lib/php72compat.php';
  44. }