Нема описа

autoload.php 2.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. if (PHP_VERSION_ID < 70000) {
  3. if (!is_callable('sodiumCompatAutoloader')) {
  4. /**
  5. * Sodium_Compat autoloader.
  6. *
  7. * @param string $class Class name to be autoloaded.
  8. *
  9. * @return bool Stop autoloading?
  10. */
  11. function sodiumCompatAutoloader($class)
  12. {
  13. $namespace = 'ParagonIE_Sodium_';
  14. // Does the class use the namespace prefix?
  15. $len = strlen($namespace);
  16. if (strncmp($namespace, $class, $len) !== 0) {
  17. // no, move to the next registered autoloader
  18. return false;
  19. }
  20. // Get the relative class name
  21. $relative_class = substr($class, $len);
  22. // Replace the namespace prefix with the base directory, replace namespace
  23. // separators with directory separators in the relative class name, append
  24. // with .php
  25. $file = dirname(__FILE__) . '/src/' . str_replace('_', '/', $relative_class) . '.php';
  26. // if the file exists, require it
  27. if (file_exists($file)) {
  28. require_once $file;
  29. return true;
  30. }
  31. return false;
  32. }
  33. // Now that we have an autoloader, let's register it!
  34. spl_autoload_register('sodiumCompatAutoloader');
  35. }
  36. } else {
  37. require_once dirname(__FILE__) . '/autoload-php7.php';
  38. }
  39. /* Explicitly, always load the Compat class: */
  40. require_once dirname(__FILE__) . '/src/Compat.php';
  41. if (!class_exists('SodiumException', false)) {
  42. require_once dirname(__FILE__) . '/src/SodiumException.php';
  43. }
  44. if (PHP_VERSION_ID >= 50300) {
  45. // Namespaces didn't exist before 5.3.0, so don't even try to use this
  46. // unless PHP >= 5.3.0
  47. require_once dirname(__FILE__) . '/lib/namespaced.php';
  48. require_once dirname(__FILE__) . '/lib/sodium_compat.php';
  49. } else {
  50. require_once dirname(__FILE__) . '/src/PHP52/SplFixedArray.php';
  51. }
  52. if (PHP_VERSION_ID < 70200 || !extension_loaded('sodium')) {
  53. if (PHP_VERSION_ID >= 50300 && !defined('SODIUM_CRYPTO_SCALARMULT_BYTES')) {
  54. require_once dirname(__FILE__) . '/lib/php72compat_const.php';
  55. }
  56. if (PHP_VERSION_ID >= 70000) {
  57. assert(class_exists('ParagonIE_Sodium_Compat'), 'Possible filesystem/autoloader bug?');
  58. } else {
  59. assert(class_exists('ParagonIE_Sodium_Compat'));
  60. }
  61. require_once(dirname(__FILE__) . '/lib/php72compat.php');
  62. } elseif (!function_exists('sodium_crypto_stream_xchacha20_xor')) {
  63. // Older versions of {PHP, ext/sodium} will not define these
  64. require_once(dirname(__FILE__) . '/lib/php72compat.php');
  65. }
  66. require_once(dirname(__FILE__) . '/lib/ristretto255.php');