first commit

This commit is contained in:
2025-11-28 10:08:12 +08:00
commit 09a14bf0a3
1088 changed files with 145132 additions and 0 deletions
@@ -0,0 +1,48 @@
<?php
namespace Mdanter\Ecc\Math;
class MathAdapterFactory
{
/**
* @var GmpMathInterface
*/
private static $forcedAdapter = null;
/**
* @param GmpMathInterface $adapter
*/
public static function forceAdapter(GmpMathInterface $adapter = null)
{
self::$forcedAdapter = $adapter;
}
/**
* @param bool $debug
* @return DebugDecorator|GmpMathInterface|null
*/
public static function getAdapter(bool $debug = false): GmpMathInterface
{
if (self::$forcedAdapter !== null) {
return self::$forcedAdapter;
}
$adapter = new GmpMath();
return self::wrapAdapter($adapter, $debug);
}
/**
* @param GmpMathInterface $adapter
* @param bool $debug
* @return DebugDecorator|GmpMathInterface
*/
private static function wrapAdapter(GmpMathInterface $adapter, bool $debug): GmpMathInterface
{
if ($debug === true) {
return new DebugDecorator($adapter);
}
return $adapter;
}
}