9
|
1 |
<?php |
|
2 |
|
|
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 |
|
|
21 |
// Get the relative class name |
|
22 |
$relative_class = substr($class, $len); |
|
23 |
|
|
24 |
// Replace the namespace prefix with the base directory, replace namespace |
|
25 |
// separators with directory separators in the relative class name, append |
|
26 |
// with .php |
|
27 |
$file = dirname(__FILE__) . '/src/' . str_replace('_', '/', $relative_class) . '.php'; |
|
28 |
// if the file exists, require it |
|
29 |
if (file_exists($file)) { |
|
30 |
require_once $file; |
|
31 |
return true; |
|
32 |
} |
|
33 |
return false; |
|
34 |
} |
|
35 |
|
|
36 |
// Now that we have an autoloader, let's register it! |
|
37 |
spl_autoload_register('sodiumCompatAutoloader'); |
|
38 |
} |
|
39 |
|
|
40 |
require_once dirname(__FILE__) . '/src/SodiumException.php'; |
|
41 |
if (PHP_VERSION_ID >= 50300) { |
|
42 |
// Namespaces didn't exist before 5.3.0, so don't even try to use this |
|
43 |
// unless PHP >= 5.3.0 |
|
44 |
require_once dirname(__FILE__) . '/lib/namespaced.php'; |
|
45 |
require_once dirname(__FILE__) . '/lib/sodium_compat.php'; |
|
46 |
} |
|
47 |
if (PHP_VERSION_ID < 70200 || !extension_loaded('sodium')) { |
|
48 |
require_once dirname(__FILE__) . '/lib/php72compat.php'; |
|
49 |
} |