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