Skip to content

Commit e183e12

Browse files
committed
fix: add compatibility for multiple phpseclib versions
Ensure compatibility with both phpseclib 2.x and 3.x by dynamically aliasing the appropriate BigInteger class. Throw an exception if phpseclib is not installed.
1 parent ff307c3 commit e183e12

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

src/BCMath.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,18 @@
1212

1313
namespace bcmath_compat;
1414

15-
use phpseclib3\Math\BigInteger;
15+
// Check phpseclib version and use appropriate namespace
16+
if (class_exists('\phpseclib3\Math\BigInteger')) {
17+
// phpseclib 3.x
18+
class_alias('\phpseclib3\Math\BigInteger', '\bcmath_compat\BigInteger');
19+
} elseif (class_exists('\phpseclib\Math\BigInteger')) {
20+
// phpseclib 2.x
21+
class_alias('\phpseclib\Math\BigInteger', '\bcmath_compat\BigInteger');
22+
} else {
23+
throw new \RuntimeException('phpseclib is not installed');
24+
}
25+
26+
use bcmath_compat\BigInteger;
1627

1728
/**
1829
* BCMath Emulation Class

0 commit comments

Comments
 (0)