balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

autoload.php (2731B)


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