Нема описа

autoload.php 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. if (!class_exists('SodiumException', false)) {
  40. require_once dirname(__FILE__) . '/src/SodiumException.php';
  41. }
  42. if (PHP_VERSION_ID >= 50300) {
  43. // Namespaces didn't exist before 5.3.0, so don't even try to use this
  44. // unless PHP >= 5.3.0
  45. require_once dirname(__FILE__) . '/lib/namespaced.php';
  46. require_once dirname(__FILE__) . '/lib/sodium_compat.php';
  47. } else {
  48. require_once dirname(__FILE__) . '/src/PHP52/SplFixedArray.php';
  49. }
  50. if (PHP_VERSION_ID < 70200 || !extension_loaded('sodium')) {
  51. if (PHP_VERSION_ID >= 50300 && !defined('SODIUM_CRYPTO_SCALARMULT_BYTES')) {
  52. require_once dirname(__FILE__) . '/lib/php72compat_const.php';
  53. }
  54. if (PHP_VERSION_ID >= 70000) {
  55. assert(class_exists('ParagonIE_Sodium_Compat'), 'Possible filesystem/autoloader bug?');
  56. } else {
  57. assert(class_exists('ParagonIE_Sodium_Compat'));
  58. }
  59. require_once (dirname(__FILE__) . '/lib/php72compat.php');
  60. }