[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

/wp-includes/sodium_compat/lib/ -> namespaced.php (source)

   1  <?php
   2  
   3  require_once dirname(dirname(__FILE__)) . '/autoload.php';
   4  
   5  if (PHP_VERSION_ID < 50300) {
   6      return;
   7  }
   8  
   9  /*
  10   * This file is just for convenience, to allow developers to reduce verbosity when
  11   * they add this project to their libraries.
  12   *
  13   * Replace this:
  14   *
  15   * $x = ParagonIE_Sodium_Compat::crypto_aead_xchacha20poly1305_encrypt(...$args);
  16   *
  17   * with this:
  18   *
  19   * use ParagonIE\Sodium\Compat;
  20   *
  21   * $x = Compat::crypto_aead_xchacha20poly1305_encrypt(...$args);
  22   */
  23  spl_autoload_register(function ($class) {
  24      if ($class[0] === '\\') {
  25          $class = substr($class, 1);
  26      }
  27      $namespace = 'ParagonIE\\Sodium';
  28      // Does the class use the namespace prefix?
  29      $len = strlen($namespace);
  30      if (strncmp($namespace, $class, $len) !== 0) {
  31          // no, move to the next registered autoloader
  32          return false;
  33      }
  34  
  35      // Get the relative class name
  36      $relative_class = substr($class, $len);
  37  
  38      // Replace the namespace prefix with the base directory, replace namespace
  39      // separators with directory separators in the relative class name, append
  40      // with .php
  41      $file = dirname(dirname(__FILE__)) . '/namespaced/' . str_replace('\\', '/', $relative_class) . '.php';
  42      // if the file exists, require it
  43      if (file_exists($file)) {
  44          require_once $file;
  45          return true;
  46      }
  47      return false;
  48  });


Generated: Tue Oct 27 01:00:08 2020 Cross-referenced by PHPXref 0.7.1