mirror of
https://github.com/linuxserver/Heimdall.git
synced 2026-08-07 07:16:13 +00:00
39191885e5
- laravel/framework ^11.45 -> ^12.0 (installed 12.63.0) - phpunit/phpunit ^10.5 -> ^11.0; migrate phpunit.xml to the 11.5 schema - graham-campbell/github ^12.5 -> ^13.0 (v12 caps illuminate/support at ^11) - Carbon 3 pulled in by L12; no application code changes required - gitignore /.phpunit.cache Full suite green: 59 tests, 128 assertions (1 skipped).
75 lines
1.8 KiB
PHP
75 lines
1.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Brick\Math\Internal;
|
|
|
|
use function extension_loaded;
|
|
|
|
/**
|
|
* Stores the current Calculator instance used by BigNumber classes.
|
|
*
|
|
* @internal
|
|
*/
|
|
final class CalculatorRegistry
|
|
{
|
|
/**
|
|
* The Calculator instance in use.
|
|
*/
|
|
private static ?Calculator $instance = null;
|
|
|
|
/**
|
|
* Sets the Calculator instance to use.
|
|
*
|
|
* An instance is typically set only in unit tests: autodetect is usually the best option.
|
|
*
|
|
* @param Calculator|null $calculator The calculator instance, or null to revert to autodetect.
|
|
*/
|
|
final public static function set(?Calculator $calculator): void
|
|
{
|
|
self::$instance = $calculator;
|
|
}
|
|
|
|
/**
|
|
* Returns the Calculator instance to use.
|
|
*
|
|
* If none has been explicitly set, the fastest available implementation will be returned.
|
|
*
|
|
* Note: even though this method is not technically pure, it is considered pure when used in a normal context, when
|
|
* only relying on autodetect.
|
|
*
|
|
* @pure
|
|
*/
|
|
final public static function get(): Calculator
|
|
{
|
|
/** @phpstan-ignore impure.staticPropertyAccess */
|
|
if (self::$instance === null) {
|
|
/** @phpstan-ignore impure.propertyAssign */
|
|
self::$instance = self::detect();
|
|
}
|
|
|
|
/** @phpstan-ignore impure.staticPropertyAccess */
|
|
return self::$instance;
|
|
}
|
|
|
|
/**
|
|
* Returns the fastest available Calculator implementation.
|
|
*
|
|
* @pure
|
|
*
|
|
* @codeCoverageIgnore
|
|
*/
|
|
private static function detect(): Calculator
|
|
{
|
|
if (extension_loaded('gmp')) {
|
|
return new Calculator\GmpCalculator();
|
|
}
|
|
|
|
if (extension_loaded('bcmath')) {
|
|
return new Calculator\BcMathCalculator();
|
|
}
|
|
|
|
return new Calculator\NativeCalculator();
|
|
}
|
|
}
|